From 9e47037bb1acc43a2c9e035e518b791183260676 Mon Sep 17 00:00:00 2001 From: tobrun Date: Mon, 13 Aug 2018 11:40:54 +0200 Subject: [android] - add line-gradient example, integrate lineProgress expression --- .../mapboxsdk/style/expressions/Expression.java | 26 +++++ .../mapboxsdk/style/sources/GeoJsonOptions.java | 12 ++- .../src/main/AndroidManifest.xml | 11 ++ .../activity/style/GradientLineActivity.java | 117 +++++++++++++++++++++ .../src/main/res/layout/activity_gradient_line.xml | 11 ++ .../res/raw/test_line_gradient_feature.geojson | 38 +++++++ .../src/main/res/values/descriptions.xml | 1 + .../src/main/res/values/titles.xml | 1 + 8 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GradientLineActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_gradient_line.xml create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/raw/test_line_gradient_feature.geojson 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 1aa0ce9093..271ad64f65 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 @@ -1143,6 +1143,32 @@ public class Expression { return new Expression("heatmap-density"); } + /** + * Gets the progress along a gradient line. Can only be used in the line-gradient property. + *

+ * Example usage: + *

+ *
+   * {@code
+   * LineLayer layer = new LineLayer("layer-id", "source-id");
+   * layer.setProperties(
+   *     lineGradient(interpolate(
+   *         linear(), lineProgress(),
+   *         stop(0f, rgb(0, 0, 255)),
+   *         stop(0.5f, rgb(0, 255, 0)),
+   *         stop(1f, rgb(255, 0, 0)))
+   *     )
+   * )
+   * }
+   * 
+ * + * @return expression + * @see Style specification + */ + public static Expression lineProgress() { + return new Expression("line-progress"); + } + /** * Retrieves an item from an array. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java index 79cde7429c..bc58100e59 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java @@ -44,6 +44,17 @@ public class GeoJsonOptions extends HashMap { return this; } + /** + * Initialises whether to calculate line distance metrics. + * + * @param lineMetrics true to calculate line distance metrics. + * @return the current instance for chaining + */ + public GeoJsonOptions withLineMetrics(boolean lineMetrics) { + this.put("lineMetrics", lineMetrics); + return this; + } + /** * Douglas-Peucker simplification tolerance (higher means simpler geometries and faster performance). * @@ -88,5 +99,4 @@ public class GeoJsonOptions extends HashMap { this.put("clusterRadius", clusterRadius); return this; } - } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index c87e9d09bf..e23b1d64f3 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -432,6 +432,17 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity" /> + + + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/raw/test_line_gradient_feature.geojson b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/raw/test_line_gradient_feature.geojson new file mode 100644 index 0000000000..3525259cba --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/raw/test_line_gradient_feature.geojson @@ -0,0 +1,38 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 9.38507080078125, + 46.16936992120204 + ], + [ + 9.07196044921875, + 45.81540082150529 + ], + [ + 9.3878173828125, + 45.85271700071619 + ], + [ + 9.2010498046875, + 45.46783598133375 + ], + [ + 8.876953125, + 44.422011314236634 + ], + [ + 7.635498046875, + 45.07352060670971 + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml index bb4e0cfe6d..6c68edc4d2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml @@ -29,6 +29,7 @@ Learn how to create a dynamic custom InfoWindow Use SupportMapFragments in a ViewPager Adopt the map style on the fly + Show a gradient line layer from a geojson source Use functions to change the map appearance Manipulate symbols at runtime Use a custom sprite in a Symbol Layer diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml index 736c33fe34..ddf3518863 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml @@ -30,6 +30,7 @@ Min/Max Zoom ViewPager Runtime Style + Gradient line layer Data Driven Style Circle layer Local Style file -- cgit v1.2.1