Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Add bindings for circle-sort-key #322

Merged
merged 4 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace android {

// Property getters

jni::Local<jni::Object<>> CircleLayer::getCircleSortKey(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
return std::move(*convert<jni::Local<jni::Object<>>>(env, toCircleLayer(layer).getCircleSortKey()));
}

jni::Local<jni::Object<>> CircleLayer::getCircleRadius(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
return std::move(*convert<jni::Local<jni::Object<>>>(env, toCircleLayer(layer).getCircleRadius()));
Expand Down Expand Up @@ -237,6 +242,7 @@ namespace android {
jni::MakePeer<CircleLayer, jni::String&, jni::String&>,
"initialize",
"finalize",
METHOD(&CircleLayer::getCircleSortKey, "nativeGetCircleSortKey"),
METHOD(&CircleLayer::getCircleRadiusTransition, "nativeGetCircleRadiusTransition"),
METHOD(&CircleLayer::setCircleRadiusTransition, "nativeSetCircleRadiusTransition"),
METHOD(&CircleLayer::getCircleRadius, "nativeGetCircleRadius"),
Expand Down
2 changes: 2 additions & 0 deletions MapboxGLAndroidSDK/src/cpp/style/layers/circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class CircleLayer : public Layer {

// Properties

jni::Local<jni::Object<jni::ObjectTag>> getCircleSortKey(jni::JNIEnv&);

jni::Local<jni::Object<jni::ObjectTag>> getCircleRadius(jni::JNIEnv&);
void setCircleRadiusTransition(jni::JNIEnv&, jlong duration, jlong delay);
jni::Local<jni::Object<TransitionOptions>> getCircleRadiusTransition(jni::JNIEnv&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ public CircleLayer withProperties(@NonNull PropertyValue<?>... properties) {

// Property getters

/**
* Get the CircleSortKey property
*
* @return property wrapper value around Float
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleSortKey() {
checkThread();
return (PropertyValue<Float>) new PropertyValue("circle-sort-key", nativeGetCircleSortKey());
}

/**
* Get the CircleRadius property
*
Expand Down Expand Up @@ -477,6 +489,10 @@ public void setCircleStrokeOpacityTransition(@NonNull TransitionOptions options)
nativeSetCircleStrokeOpacityTransition(options.getDuration(), options.getDelay());
}

@NonNull
@Keep
private native Object nativeGetCircleSortKey();

@NonNull
@Keep
private native Object nativeGetCircleRadius();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ public static PropertyValue<Expression> symbolAvoidEdges(Expression 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 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
Expand All @@ -1836,7 +1836,7 @@ public static PropertyValue<Float> symbolSortKey(Float 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 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
Expand Down Expand Up @@ -2595,4 +2595,24 @@ public static PropertyValue<Expression> textOptional(Expression value) {
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<Float> 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<Expression> circleSortKey(Expression value) {
return new LayoutPropertyValue<>("circle-sort-key", value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ public void testFilter() {



@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() {
Expand Down
10 changes: 5 additions & 5 deletions scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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
Expand Down