Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Fix match stop conversion #12128

Merged
merged 1 commit into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1017,12 +1017,7 @@ public static Expression match(@NonNull @Size(min = 2) Expression... input) {
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-match">Style specification</a>
*/
public static Expression match(@NonNull Expression input, @NonNull Expression defaultOutput, @NonNull Stop... stops) {
Expression[] expressionStops = new Expression[stops.length * 2];
for (int i = 0; i < stops.length; i++) {
expressionStops[i * 2] = literal(stops[i].value);
expressionStops[i * 2 + 1] = literal(stops[i].output);
}
return match(join(join(new Expression[] {input}, expressionStops), new Expression[] {defaultOutput}));
return match(join(join(new Expression[] {input}, Stop.toExpressionArray(stops)), new Expression[] {defaultOutput}));
}

/**
Expand Down Expand Up @@ -3449,8 +3444,6 @@ private Object toValue(ExpressionLiteral expressionValue) {
throw new IllegalArgumentException("PropertyValue are not allowed as an expression literal, use value instead.");
} else if (value instanceof Expression.ExpressionLiteral) {
return toValue((ExpressionLiteral) value);
} else if (value instanceof Expression) {
return ((Expression) value).toArray();
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.graphics.Color;
import android.support.test.runner.AndroidJUnit4;

import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
Expand All @@ -11,14 +10,12 @@
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;

import org.junit.Test;
import org.junit.runner.RunWith;
import timber.log.Timber;

import java.io.IOException;

import timber.log.Timber;

import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
Expand Down Expand Up @@ -188,6 +185,25 @@ public void testLiteralProperty() {
});
}

@Test
public void testLiteralMatchExpression() {
validateTestSetup();
setupStyle();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expression expression = match(literal("something"), literal(0f),
stop("1", get("1")),
stop("2", get("2")),
stop("3", get("3")),
stop("4", get("4"))
);

layer.setProperties(
fillColor(expression)
);
expression.toArray();
});
}

private void setupStyle() {
invoke(mapboxMap, (uiController, mapboxMap) -> {
// Add a source
Expand Down