map = new HashMap<>();
+ map.put("json", literal(geoJson.toJson()));
+ return new Expression("distance", new ExpressionMap(map), literal(unit));
+ }
+
+ /**
+ * Retrieves the shortest distance between two geometries.
+ * The returned value can be consumed as an input into another expression for changing a paint or layout property
+ * or filtering features by distance.
+ *
+ * Currently supports `Point`, `MultiPoint`, `LineString`, `MultiLineString` geometry types.
+ *
+ * @param geoJson the target feature geoJson.
+ * Currently supports `Point`, `MultiPoint`, `LineString`, `MultiLineString` geometry types
+ * @return the distance in the unit "meters".
+ * @see Style specification
+ */
+ public static Expression distance(@NonNull GeoJson geoJson) {
+ Map map = new HashMap<>();
+ map.put("json", literal(geoJson.toJson()));
+ return new Expression("distance", new ExpressionMap(map));
+ }
+
public static Expression within(@NonNull Polygon polygon) {
Map map = new HashMap<>();
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 62f3a71f0..6ca50a510 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
@@ -37,6 +37,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.color;
import static com.mapbox.mapboxsdk.style.expressions.Expression.concat;
import static com.mapbox.mapboxsdk.style.expressions.Expression.cos;
import static com.mapbox.mapboxsdk.style.expressions.Expression.cubicBezier;
+import static com.mapbox.mapboxsdk.style.expressions.Expression.distance;
import static com.mapbox.mapboxsdk.style.expressions.Expression.division;
import static com.mapbox.mapboxsdk.style.expressions.Expression.downcase;
import static com.mapbox.mapboxsdk.style.expressions.Expression.e;
@@ -487,6 +488,22 @@ public class ExpressionTest {
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}
+
+ @Test
+ public void testDistance() throws Exception {
+ Point point = Point.fromLngLat(1, 2);
+ HashMap map = new HashMap<>();
+ map.put("json", point.toJson());
+ Object[] expected = new Object[] {"distance", map};
+ Object[] actual = distance(point).toArray();
+ assertTrue("expression should match", Arrays.deepEquals(expected, actual));
+
+ Object[] expectedWithUnit = new Object[] {"distance", map, "meters"};
+ Object[] actualWithUnit = distance(point, "meters").toArray();
+ assertTrue("expression should match", Arrays.deepEquals(expectedWithUnit, actualWithUnit));
+ }
+
+
@Test
public void testInArray() throws Exception {
Object[] expected = new Object[] {"in", "one", new Object[] {"literal", new Object[] {"one", "two"}}};
diff --git a/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index e89902d7e..ba26ee8d6 100644
--- a/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -515,6 +515,18 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
+
+
+
+
+ mapboxMap = map
+
+ // Setup camera position above Georgetown
+ mapboxMap.cameraPosition = CameraPosition.Builder()
+ .target(LatLng(lat, lon))
+ .zoom(16.0)
+ .build()
+ setupStyle()
+ }
+ }
+
+ private fun setupStyle() {
+ val center = Point.fromLngLat(lon, lat)
+ val circle = TurfTransformation.circle(center, 150.0, TurfConstants.UNIT_METRES)
+ // Setup style with additional layers,
+ // using Style.MAPBOX_STREETS as a base style
+ mapboxMap.setStyle(
+ Style.Builder()
+ .fromUri(Style.MAPBOX_STREETS)
+ .withSources(
+ GeoJsonSource(
+ POINT_ID, Point.fromLngLat(lon, lat)
+ ),
+ GeoJsonSource(CIRCLE_ID, circle)
+ )
+ .withLayerBelow(
+ FillLayer(CIRCLE_ID, CIRCLE_ID)
+ .withProperties(
+ fillOpacity(0.5f),
+ fillColor(Color.parseColor("#3bb2d0"))
+ ), "poi-label"
+ )
+ ) { style ->
+ // Show only POI labels inside circle radius using distance expression
+ val symbolLayer = style.getLayer("poi-label") as SymbolLayer
+ symbolLayer.setFilter(lt(
+ distance(
+ Point.fromLngLat(lon, lat), "meters"
+ ), 150)
+ )
+
+ // Hide other types of labels to highlight POI labels
+ (style.getLayer("road-label") as SymbolLayer).setProperties(visibility(NONE))
+ (style.getLayer("transit-label") as SymbolLayer).setProperties(visibility(NONE))
+ (style.getLayer("road-number-shield") as SymbolLayer).setProperties(visibility(NONE))
+ }
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView.onStop()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView.onLowMemory()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView.onDestroy()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?) {
+ super.onSaveInstanceState(outState, outPersistentState)
+ outState?.let {
+ mapView.onSaveInstanceState(it)
+ }
+ }
+
+ companion object {
+ const val POINT_ID = "point"
+ const val CIRCLE_ID = "circle"
+ }
+}
\ No newline at end of file
diff --git a/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index 6f61fb649..63c410cda 100644
--- a/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -34,6 +34,7 @@
Learn how to create a dynamic custom InfoWindow
Use SupportMapFragments in a ViewPager
Adopt the map style on the fly
+ Show POIs on a map with distance expression filter
Show a gradient line layer from a geojson source
Use functions to change the map appearance
Manipulate symbols at runtime
diff --git a/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
index 23c227f23..912af9ab9 100644
--- a/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -32,6 +32,7 @@
Min/Max Zoom
ViewPager
Runtime Style
+ Distance Expression
Gradient line layer
Data Driven Style
Circle layer
diff --git a/vendor/mapbox-gl-native b/vendor/mapbox-gl-native
index 71ce52d35..9f8c9c61e 160000
--- a/vendor/mapbox-gl-native
+++ b/vendor/mapbox-gl-native
@@ -1 +1 @@
-Subproject commit 71ce52d35f8421c89f6112b83061613937b2836c
+Subproject commit 9f8c9c61e87868510ee2951c93044c4995478641