From 77d0d5e5cf625679c7439c07deaed7e6d8bd5b3e Mon Sep 17 00:00:00 2001 From: Chloe Krawczyk Date: Wed, 15 Apr 2020 02:56:54 -0700 Subject: [PATCH] Add bindings for circle-sort-key (#322) * Update generate-style-code.js * add jni bindings for circle-sort-key * update mapbox-gl-native to latest * Revert "add jni bindings for circle-sort-key" This reverts commit cdd6049d Co-authored-by: kevin --- .../src/cpp/style/layers/circle_layer.cpp | 6 +++++ .../src/cpp/style/layers/circle_layer.hpp | 2 ++ .../mapboxsdk/style/layers/CircleLayer.java | 16 ++++++++++++ .../style/layers/PropertyFactory.java | 24 +++++++++++++++-- .../testapp/style/CircleLayerTest.java | 26 +++++++++++++++++++ scripts/generate-style-code.js | 10 +++---- vendor/mapbox-gl-native | 2 +- 7 files changed, 78 insertions(+), 8 deletions(-) diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp b/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp index a7fae5e23..2be603360 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp @@ -37,6 +37,11 @@ namespace android { // Property getters + jni::Local> CircleLayer::getCircleSortKey(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toCircleLayer(layer).getCircleSortKey())); + } + jni::Local> CircleLayer::getCircleRadius(jni::JNIEnv& env) { using namespace mbgl::android::conversion; return std::move(*convert>>(env, toCircleLayer(layer).getCircleRadius())); @@ -237,6 +242,7 @@ namespace android { jni::MakePeer, "initialize", "finalize", + METHOD(&CircleLayer::getCircleSortKey, "nativeGetCircleSortKey"), METHOD(&CircleLayer::getCircleRadiusTransition, "nativeGetCircleRadiusTransition"), METHOD(&CircleLayer::setCircleRadiusTransition, "nativeSetCircleRadiusTransition"), METHOD(&CircleLayer::getCircleRadius, "nativeGetCircleRadius"), diff --git a/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.hpp b/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.hpp index 40dca91e2..daa28571b 100644 --- a/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.hpp +++ b/MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.hpp @@ -26,6 +26,8 @@ public: // Properties + jni::Local> getCircleSortKey(jni::JNIEnv&); + jni::Local> getCircleRadius(jni::JNIEnv&); void setCircleRadiusTransition(jni::JNIEnv&, jlong duration, jlong delay); jni::Local> getCircleRadiusTransition(jni::JNIEnv&); diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java index 03f926ed5..d9845634c 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java @@ -143,6 +143,18 @@ public class CircleLayer extends Layer { // Property getters + /** + * Get the CircleSortKey property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getCircleSortKey() { + checkThread(); + return (PropertyValue) new PropertyValue("circle-sort-key", nativeGetCircleSortKey()); + } + /** * Get the CircleRadius property * @@ -477,6 +489,10 @@ public class CircleLayer extends Layer { nativeSetCircleStrokeOpacityTransition(options.getDuration(), options.getDelay()); } + @NonNull + @Keep + private native Object nativeGetCircleSortKey(); + @NonNull @Keep private native Object nativeGetCircleRadius(); diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index b7a90c656..b3ae7a325 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -1826,7 +1826,7 @@ public class PropertyFactory { } /** - * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key when they overlap. Features with a lower sort key will have priority over other features when doing placement. + * Sorts features in ascending order based on this value. Features with lower sort keys are drawn and placed first. When {@link PropertyFactory#iconAllowOverlap} or {@link PropertyFactory#textAllowOverlap} is `false`, features with a lower sort key will have priority during placement. When {@link PropertyFactory#iconAllowOverlap} or {@link PropertyFactory#textAllowOverlap} is set to `true`, features with a higher sort key will overlap over features with a lower sort key. * * @param value a Float value * @return property wrapper around Float @@ -1836,7 +1836,7 @@ public class PropertyFactory { } /** - * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key when they overlap. Features with a lower sort key will have priority over other features when doing placement. + * Sorts features in ascending order based on this value. Features with lower sort keys are drawn and placed first. When {@link PropertyFactory#iconAllowOverlap} or {@link PropertyFactory#textAllowOverlap} is `false`, features with a lower sort key will have priority during placement. When {@link PropertyFactory#iconAllowOverlap} or {@link PropertyFactory#textAllowOverlap} is set to `true`, features with a higher sort key will overlap over features with a lower sort key. * * @param value a Float value * @return property wrapper around Float @@ -2595,4 +2595,24 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-optional", value); } + /** + * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue circleSortKey(Float value) { + return new LayoutPropertyValue<>("circle-sort-key", value); + } + + /** + * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue circleSortKey(Expression value) { + return new LayoutPropertyValue<>("circle-sort-key", value); + } + } diff --git a/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java b/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java index fbe812c7d..1430f304c 100644 --- a/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java +++ b/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java @@ -99,6 +99,32 @@ public class CircleLayerTest extends BaseLayerTest { + @Test + @UiThreadTest + public void testCircleSortKeyAsConstant() { + Timber.i("circle-sort-key"); + assertNotNull(layer); + assertNull(layer.getCircleSortKey().getValue()); + + // Set and Get + Float propertyValue = 0.3f; + layer.setProperties(circleSortKey(propertyValue)); + assertEquals(layer.getCircleSortKey().getValue(), propertyValue); + } + + @Test + @UiThreadTest + public void testCircleSortKeyAsExpression() { + Timber.i("circle-sort-key-expression"); + assertNotNull(layer); + assertNull(layer.getCircleSortKey().getExpression()); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleSortKey(expression)); + assertEquals(layer.getCircleSortKey().getExpression(), expression); + } + @Test @UiThreadTest public void testCircleRadiusTransition() { diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index bc3f67c9a..3ed77405a 100755 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -7,7 +7,7 @@ const spec = require('../vendor/mapbox-gl-native/scripts/style-spec'); const _ = require('lodash'); // FIXME: https://github.com/mapbox/mapbox-gl-native/issues/15008 -delete spec.layout_circle["circle-sort-key"] +//delete spec.layout_circle["circle-sort-key"] //delete spec.layout_line["line-sort-key"] //delete spec.layout_fill["fill-sort-key"] @@ -384,14 +384,14 @@ for (const layer of layers) { } // Jni -const layerHpp = ejs.compile(fs.readFileSync('vendor/mapbox-gl-native/platform/android/src/style/layers/layer.hpp.ejs', 'utf8'), {strict: true}); -const layerCpp = ejs.compile(fs.readFileSync('vendor/mapbox-gl-native/platform/android/src/style/layers/layer.cpp.ejs', 'utf8'), {strict: true}); +const layerHpp = ejs.compile(fs.readFileSync('MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp.ejs', 'utf8'), {strict: true}); +const layerCpp = ejs.compile(fs.readFileSync('MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp.ejs', 'utf8'), {strict: true}); for (const layer of layers) { const layerFileName = layer.type.replace('-', '_'); - writeIfModified(`vendor/mapbox-gl-native/platform/android/src/style/layers/${layerFileName}_layer.hpp`, layerHpp(layer)); - writeIfModified(`vendor/mapbox-gl-native/platform/android/src/style/layers/${layerFileName}_layer.cpp`, layerCpp(layer)); + writeIfModified(`MapboxGLAndroidSDK/src/cpp/style/layers/${layerFileName}_layer.hpp`, layerHpp(layer)); + writeIfModified(`MapboxGLAndroidSDK/src/cpp/style/layers/${layerFileName}_layer.cpp`, layerCpp(layer)); } // Java PropertyFactory diff --git a/vendor/mapbox-gl-native b/vendor/mapbox-gl-native index be9ca95e9..66ac55445 160000 --- a/vendor/mapbox-gl-native +++ b/vendor/mapbox-gl-native @@ -1 +1 @@ -Subproject commit be9ca95e9ab3be296177bf6ec0f1b05f7ade8749 +Subproject commit 66ac55445998718b28a6fbd4a4094a10426627a9