diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2018-06-12 00:12:31 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-06-12 18:08:58 +0200 |
commit | aa16b90e2b374b27f4458aade536685189bdb1c8 (patch) | |
tree | ae9ccb78620b61136685cc5c9230fa987198d79b /platform | |
parent | 0ecdbebb092f17499718cb6ec8376edac46cad33 (diff) | |
download | qtlocation-mapboxgl-aa16b90e2b374b27f4458aade536685189bdb1c8.tar.gz |
[android] - move match stops conversion to Stop.toExpressionArray
Diffstat (limited to 'platform')
2 files changed, 21 insertions, 12 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java index eb9150ecbc..72e8187b96 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -1017,12 +1017,7 @@ public class Expression { * @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})); } /** @@ -3449,8 +3444,6 @@ public class Expression { 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; } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java index baa8262e71..f1f260c919 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java @@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.testapp.style; 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; @@ -11,14 +10,12 @@ import com.mapbox.mapboxsdk.testapp.R; 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; @@ -188,6 +185,25 @@ public class ExpressionTest extends BaseActivityTest { }); } + @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 |