diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-03-07 18:52:00 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-03-29 16:18:41 +0200 |
commit | 2b9a52f5e4cfd1a90c96b307ea218c720df10436 (patch) | |
tree | e38d567a8e6738673af617673a4465e59eba2c09 | |
parent | a6d8742e637a53eea90c2d0da049e684804928d3 (diff) | |
download | qtlocation-mapboxgl-2b9a52f5e4cfd1a90c96b307ea218c720df10436.tar.gz |
[core] Enable 'text-radial-offset' property
10 files changed, 98 insertions, 6 deletions
diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 46935ef535..35fe72e6bf 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -134,6 +134,10 @@ public: PropertyValue<TextJustifyType> getTextJustify() const; void setTextJustify(PropertyValue<TextJustifyType>); + static PropertyValue<float> getDefaultTextRadialOffset(); + PropertyValue<float> getTextRadialOffset() const; + void setTextRadialOffset(PropertyValue<float>); + static PropertyValue<std::vector<TextVariableAnchorType>> getDefaultTextVariableAnchor(); PropertyValue<std::vector<TextVariableAnchorType>> getTextVariableAnchor() const; void setTextVariableAnchor(PropertyValue<std::vector<TextVariableAnchorType>>); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index 88770b10af..01908b1b0b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -2276,7 +2276,27 @@ public class PropertyFactory { } /** - * To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the `text-radial-offset` instead of the two-dimensional {@link PropertyFactory#textOffset}. + * Radial offset of text, in the direction of the symbol's anchor. Useful in combination with {@link PropertyFactory#textVariableAnchor}, which doesn't support the two-dimensional {@link PropertyFactory#textOffset}. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Float> textRadialOffset(Float value) { + return new LayoutPropertyValue<>("text-radial-offset", value); + } + + /** + * Radial offset of text, in the direction of the symbol's anchor. Useful in combination with {@link PropertyFactory#textVariableAnchor}, which doesn't support the two-dimensional {@link PropertyFactory#textOffset}. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textRadialOffset(Expression value) { + return new LayoutPropertyValue<>("text-radial-offset", value); + } + + /** + * To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} instead of the two-dimensional {@link PropertyFactory#textOffset}. * * @param value a String[] value * @return property wrapper around String[] @@ -2286,7 +2306,7 @@ public class PropertyFactory { } /** - * To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the `text-radial-offset` instead of the two-dimensional {@link PropertyFactory#textOffset}. + * To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} instead of the two-dimensional {@link PropertyFactory#textOffset}. * * @param value a String[] value * @return property wrapper around String[] diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index 4b5e755f7d..75473f0f30 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java @@ -470,6 +470,18 @@ public class SymbolLayer extends Layer { } /** + * Get the TextRadialOffset property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue<Float> getTextRadialOffset() { + checkThread(); + return (PropertyValue<Float>) new PropertyValue("text-radial-offset", nativeGetTextRadialOffset()); + } + + /** * Get the TextVariableAnchor property * * @return property wrapper value around String[] @@ -1199,6 +1211,10 @@ public class SymbolLayer extends Layer { @NonNull @Keep + private native Object nativeGetTextRadialOffset(); + + @NonNull + @Keep private native Object nativeGetTextVariableAnchor(); @NonNull diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java index 67260f9b3c..9775a5184b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java @@ -579,6 +579,19 @@ public class SymbolLayerTest extends BaseLayerTest { @Test @UiThreadTest + public void testTextRadialOffsetAsConstant() { + Timber.i("text-radial-offset"); + assertNotNull(layer); + assertNull(layer.getTextRadialOffset().getValue()); + + // Set and Get + Float propertyValue = 0.3f; + layer.setProperties(textRadialOffset(propertyValue)); + assertEquals(layer.getTextRadialOffset().getValue(), propertyValue); + } + + @Test + @UiThreadTest public void testTextVariableAnchorAsConstant() { Timber.i("text-variable-anchor"); assertNotNull(layer); diff --git a/platform/android/src/style/layers/symbol_layer.cpp b/platform/android/src/style/layers/symbol_layer.cpp index e9b149eaf3..810848e9cb 100644 --- a/platform/android/src/style/layers/symbol_layer.cpp +++ b/platform/android/src/style/layers/symbol_layer.cpp @@ -176,6 +176,11 @@ namespace android { return std::move(*convert<jni::Local<jni::Object<>>>(env, toSymbolLayer(layer).getTextJustify())); } + jni::Local<jni::Object<>> SymbolLayer::getTextRadialOffset(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert<jni::Local<jni::Object<>>>(env, toSymbolLayer(layer).getTextRadialOffset())); + } + jni::Local<jni::Object<>> SymbolLayer::getTextVariableAnchor(jni::JNIEnv& env) { using namespace mbgl::android::conversion; return std::move(*convert<jni::Local<jni::Object<>>>(env, toSymbolLayer(layer).getTextVariableAnchor())); @@ -519,6 +524,7 @@ namespace android { METHOD(&SymbolLayer::getTextLineHeight, "nativeGetTextLineHeight"), METHOD(&SymbolLayer::getTextLetterSpacing, "nativeGetTextLetterSpacing"), METHOD(&SymbolLayer::getTextJustify, "nativeGetTextJustify"), + METHOD(&SymbolLayer::getTextRadialOffset, "nativeGetTextRadialOffset"), METHOD(&SymbolLayer::getTextVariableAnchor, "nativeGetTextVariableAnchor"), METHOD(&SymbolLayer::getTextAnchor, "nativeGetTextAnchor"), METHOD(&SymbolLayer::getTextMaxAngle, "nativeGetTextMaxAngle"), diff --git a/platform/android/src/style/layers/symbol_layer.hpp b/platform/android/src/style/layers/symbol_layer.hpp index c93961f70a..3b0f8ee5d1 100644 --- a/platform/android/src/style/layers/symbol_layer.hpp +++ b/platform/android/src/style/layers/symbol_layer.hpp @@ -80,6 +80,8 @@ public: jni::Local<jni::Object<jni::ObjectTag>> getTextJustify(jni::JNIEnv&); + jni::Local<jni::Object<jni::ObjectTag>> getTextRadialOffset(jni::JNIEnv&); + jni::Local<jni::Object<jni::ObjectTag>> getTextVariableAnchor(jni::JNIEnv&); jni::Local<jni::Object<jni::ObjectTag>> getTextAnchor(jni::JNIEnv&); diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index 2622ae5ef6..5145755cec 100755 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -153,7 +153,11 @@ global.defaultValue = function (property) { switch (property.type) { case 'number': + if (property.default === undefined) { + return 0; + } else { return property.default; + } case 'formatted': case 'string': return JSON.stringify(property.default || ""); diff --git a/scripts/style-spec.js b/scripts/style-spec.js index 695b5b7a59..bcfb7e5c17 100644 --- a/scripts/style-spec.js +++ b/scripts/style-spec.js @@ -5,6 +5,4 @@ delete spec.layout_symbol['symbol-sort-key']; delete spec.layout_symbol['symbol-z-order'].values['auto']; spec.layout_symbol['symbol-z-order'].default = 'viewport-y'; -delete spec.layout_symbol['text-radial-offset']; -delete spec.layout_symbol['text-justify'].values['auto']; -spec.layout_symbol['text-offset'].requires.splice(1, 1); // { "!": "text-radial-offset" } +delete spec.layout_symbol['text-justify'].values['auto'];
\ No newline at end of file diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 2195f703d7..1c56888f73 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -492,6 +492,22 @@ void SymbolLayer::setTextJustify(PropertyValue<TextJustifyType> value) { baseImpl = std::move(impl_); observer->onLayerChanged(*this); } +PropertyValue<float> SymbolLayer::getDefaultTextRadialOffset() { + return TextRadialOffset::defaultValue(); +} + +PropertyValue<float> SymbolLayer::getTextRadialOffset() const { + return impl().layout.get<TextRadialOffset>(); +} + +void SymbolLayer::setTextRadialOffset(PropertyValue<float> value) { + if (value == getTextRadialOffset()) + return; + auto impl_ = mutableImpl(); + impl_->layout.get<TextRadialOffset>() = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} PropertyValue<std::vector<TextVariableAnchorType>> SymbolLayer::getDefaultTextVariableAnchor() { return TextVariableAnchor::defaultValue(); } @@ -1341,6 +1357,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co TextLineHeight, TextLetterSpacing, TextJustify, + TextRadialOffset, TextVariableAnchor, TextAnchor, TextMaxAngle, @@ -1381,6 +1398,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co { "text-line-height", static_cast<uint8_t>(Property::TextLineHeight) }, { "text-letter-spacing", static_cast<uint8_t>(Property::TextLetterSpacing) }, { "text-justify", static_cast<uint8_t>(Property::TextJustify) }, + { "text-radial-offset", static_cast<uint8_t>(Property::TextRadialOffset) }, { "text-variable-anchor", static_cast<uint8_t>(Property::TextVariableAnchor) }, { "text-anchor", static_cast<uint8_t>(Property::TextAnchor) }, { "text-max-angle", static_cast<uint8_t>(Property::TextMaxAngle) }, @@ -1543,7 +1561,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co } - if (property == Property::IconSize || property == Property::IconRotate || property == Property::TextSize || property == Property::TextMaxWidth || property == Property::TextLetterSpacing || property == Property::TextRotate) { + if (property == Property::IconSize || property == Property::IconRotate || property == Property::TextSize || property == Property::TextMaxWidth || property == Property::TextLetterSpacing || property == Property::TextRadialOffset || property == Property::TextRotate) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { @@ -1575,6 +1593,11 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co return nullopt; } + if (property == Property::TextRadialOffset) { + setTextRadialOffset(*typedValue); + return nullopt; + } + if (property == Property::TextRotate) { setTextRotate(*typedValue); return nullopt; diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index 8ccad4efec..cf8a9ab0d0 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -147,6 +147,11 @@ struct TextJustify : DataDrivenLayoutProperty<TextJustifyType> { static TextJustifyType defaultValue() { return TextJustifyType::Center; } }; +struct TextRadialOffset : DataDrivenLayoutProperty<float> { + static constexpr const char *name() { return "text-radial-offset"; } + static float defaultValue() { return 0; } +}; + struct TextVariableAnchor : LayoutProperty<std::vector<TextVariableAnchorType>> { static constexpr const char *name() { return "text-variable-anchor"; } static std::vector<TextVariableAnchorType> defaultValue() { return { }; } @@ -289,6 +294,7 @@ class SymbolLayoutProperties : public Properties< TextLineHeight, TextLetterSpacing, TextJustify, + TextRadialOffset, TextVariableAnchor, TextAnchor, TextMaxAngle, |