diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java index c03bb05b4..71775486f 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -1536,6 +1536,42 @@ public class Expression { return at(literal(number), expression); } + /** + * Retrieves whether an item exists in an array or a substring exists in a string. + * + * @param needle the item expression + * @param haystack the array or string expression + * @return true if exists. + * @see Style specification + */ + public static Expression in(@NonNull Expression needle, @NonNull Expression haystack) { + return new Expression("in", needle, haystack); + } + + /** + * Retrieves whether an item exists in an array or a substring exists in a string. + * + * @param needle the item expression + * @param haystack the array or string expression + * @return true if exists. + * @see Style specification + */ + public static Expression in(@NonNull Number needle, @NonNull Expression haystack) { + return new Expression("in", literal(needle), haystack); + } + + /** + * Retrieves whether an item exists in an array or a substring exists in a string. + * + * @param needle the item expression + * @param haystack the array or string expression + * @return true if exists. + * @see Style specification + */ + public static Expression in(@NonNull String needle, @NonNull Expression haystack) { + return new Expression("in", literal(needle), haystack); + } + /** * Retrieves a property value from the current feature's properties, * or from another object if a second argument is provided. diff --git a/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java index fe91da8d5..ca35c648e 100644 --- a/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java +++ b/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java @@ -48,6 +48,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.gte; import static com.mapbox.mapboxsdk.style.expressions.Expression.has; import static com.mapbox.mapboxsdk.style.expressions.Expression.heatmapDensity; import static com.mapbox.mapboxsdk.style.expressions.Expression.id; +import static com.mapbox.mapboxsdk.style.expressions.Expression.in; import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; import static com.mapbox.mapboxsdk.style.expressions.Expression.isSupportedScript; import static com.mapbox.mapboxsdk.style.expressions.Expression.length; @@ -446,6 +447,27 @@ public class ExpressionTest { assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } + @Test + public void testInString() throws Exception { + Object[] expected = new Object[] {"in", "one", "onetwo"}; + Object[] actual = in(literal("one"), literal("onetwo")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testInNumber() throws Exception { + Object[] expected = new Object[] {"in", 1f, new Object[] {"literal", new Object[] {1f, 2f}}}; + Object[] actual = in(literal(1f), literal(new Object[] {1f, 2f})).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testInArray() throws Exception { + Object[] expected = new Object[] {"in", "one", new Object[] {"literal", new Object[] {"one", "two"}}}; + Object[] actual = in(literal("one"), literal(new Object[] {"one", "two"})).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + @Test public void testAtLiteral() throws Exception { Object[] expected = new Object[] {"at", 3f, new Object[] {"literal", new Object[] {"one", "two"}}}; diff --git a/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java b/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java index 1ae2499c6..b9c72288f 100644 --- a/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java +++ b/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java @@ -43,10 +43,12 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.eq; 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.gte; +import static com.mapbox.mapboxsdk.style.expressions.Expression.in; import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; import static com.mapbox.mapboxsdk.style.expressions.Expression.lt; import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; +import static com.mapbox.mapboxsdk.style.expressions.Expression.switchCase; import static com.mapbox.mapboxsdk.style.expressions.Expression.toNumber; import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; import static com.mapbox.mapboxsdk.style.layers.Property.FILL_TRANSLATE_ANCHOR_MAP; @@ -65,6 +67,7 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolPlacement; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; /** @@ -198,6 +201,9 @@ public class RuntimeStyleActivity extends AppCompatActivity { case R.id.action_fill_filter: styleFillFilterLayer(); return true; + case R.id.action_textsize_filter: + styleTextSizeFilterLayer(); + return true; case R.id.action_line_filter: styleLineFilterLayer(); return true; @@ -524,6 +530,34 @@ public class RuntimeStyleActivity extends AppCompatActivity { }, 2000); } + private void styleTextSizeFilterLayer() { + mapboxMap.setStyle(new Style.Builder().fromUri("asset://fill_filter_style.json")); + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(31, -100), 3)); + + Handler handler = new Handler(getMainLooper()); + handler.postDelayed(() -> { + if (mapboxMap == null) { + return; + } + + Timber.d("Styling text size fill layer"); + SymbolLayer states = (SymbolLayer) mapboxMap.getStyle().getLayer("state-label-lg"); + + if (states != null) { + states.setProperties( + textSize(switchCase( + in(get("name"), literal("Texas")), literal(25.0f), + in(get("name"), literal(new Object[] {"California","Illinois"})), literal(25.0f), + literal(6.0f) // default value + ) + ) + ); + } else { + Toast.makeText(RuntimeStyleActivity.this, "No states layer in this style", Toast.LENGTH_SHORT).show(); + } + }, 2000); + } + private void styleLineFilterLayer() { mapboxMap.setStyle(new Style.Builder().fromUri("asset://line_filter_style.json")); mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5)); diff --git a/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_runtime_style.xml b/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_runtime_style.xml index e3d7c8cfa..b302568fa 100644 --- a/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_runtime_style.xml +++ b/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_runtime_style.xml @@ -58,6 +58,10 @@ android:id="@+id/action_fill_filter" android:title="@string/apply_filtered_fill" mapbox:showAsAction="never" /> + Change the water color on zoom Custom tiles Apply filtered fill + Apply text size fill Apply filtered line Apply numeric fill filter Bring water to front