From 296038107799f8bddc2bc9533ac97211d1e7f6bb Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Thu, 7 Mar 2019 18:52:00 +0200 Subject: [core] Enable 'text-radial-offset' property --- include/mbgl/style/layers/symbol_layer.hpp | 4 ++++ .../mapboxsdk/style/layers/PropertyFactory.java | 24 +++++++++++++++++++-- .../mapbox/mapboxsdk/style/layers/SymbolLayer.java | 16 ++++++++++++++ .../mapboxsdk/testapp/style/SymbolLayerTest.java | 13 +++++++++++ platform/android/src/style/layers/symbol_layer.cpp | 6 ++++++ platform/android/src/style/layers/symbol_layer.hpp | 2 ++ scripts/generate-style-code.js | 4 ++++ scripts/style-spec.js | 4 +--- src/mbgl/style/layers/symbol_layer.cpp | 25 +++++++++++++++++++++- src/mbgl/style/layers/symbol_layer_properties.hpp | 6 ++++++ 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 getTextJustify() const; void setTextJustify(PropertyValue); + static PropertyValue getDefaultTextRadialOffset(); + PropertyValue getTextRadialOffset() const; + void setTextRadialOffset(PropertyValue); + static PropertyValue> getDefaultTextVariableAnchor(); PropertyValue> getTextVariableAnchor() const; void setTextVariableAnchor(PropertyValue>); 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 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 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 @@ -469,6 +469,18 @@ public class SymbolLayer extends Layer { return (PropertyValue) new PropertyValue("text-justify", nativeGetTextJustify()); } + /** + * Get the TextRadialOffset property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue getTextRadialOffset() { + checkThread(); + return (PropertyValue) new PropertyValue("text-radial-offset", nativeGetTextRadialOffset()); + } + /** * Get the TextVariableAnchor property * @@ -1197,6 +1209,10 @@ public class SymbolLayer extends Layer { @Keep private native Object nativeGetTextJustify(); + @NonNull + @Keep + private native Object nativeGetTextRadialOffset(); + @NonNull @Keep private native Object nativeGetTextVariableAnchor(); 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 @@ -577,6 +577,19 @@ public class SymbolLayerTest extends BaseLayerTest { assertEquals(layer.getTextJustify().getExpression(), expression); } + @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() { 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>>(env, toSymbolLayer(layer).getTextJustify())); } + jni::Local> SymbolLayer::getTextRadialOffset(jni::JNIEnv& env) { + using namespace mbgl::android::conversion; + return std::move(*convert>>(env, toSymbolLayer(layer).getTextRadialOffset())); + } + jni::Local> SymbolLayer::getTextVariableAnchor(jni::JNIEnv& env) { using namespace mbgl::android::conversion; return std::move(*convert>>(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> getTextJustify(jni::JNIEnv&); + jni::Local> getTextRadialOffset(jni::JNIEnv&); + jni::Local> getTextVariableAnchor(jni::JNIEnv&); jni::Local> 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 value) { baseImpl = std::move(impl_); observer->onLayerChanged(*this); } +PropertyValue SymbolLayer::getDefaultTextRadialOffset() { + return TextRadialOffset::defaultValue(); +} + +PropertyValue SymbolLayer::getTextRadialOffset() const { + return impl().layout.get(); +} + +void SymbolLayer::setTextRadialOffset(PropertyValue value) { + if (value == getTextRadialOffset()) + return; + auto impl_ = mutableImpl(); + impl_->layout.get() = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} PropertyValue> SymbolLayer::getDefaultTextVariableAnchor() { return TextVariableAnchor::defaultValue(); } @@ -1341,6 +1357,7 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co TextLineHeight, TextLetterSpacing, TextJustify, + TextRadialOffset, TextVariableAnchor, TextAnchor, TextMaxAngle, @@ -1381,6 +1398,7 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co { "text-line-height", static_cast(Property::TextLineHeight) }, { "text-letter-spacing", static_cast(Property::TextLetterSpacing) }, { "text-justify", static_cast(Property::TextJustify) }, + { "text-radial-offset", static_cast(Property::TextRadialOffset) }, { "text-variable-anchor", static_cast(Property::TextVariableAnchor) }, { "text-anchor", static_cast(Property::TextAnchor) }, { "text-max-angle", static_cast(Property::TextMaxAngle) }, @@ -1543,7 +1561,7 @@ optional 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> typedValue = convert>(value, error, true, false); if (!typedValue) { @@ -1575,6 +1593,11 @@ optional 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 { static TextJustifyType defaultValue() { return TextJustifyType::Center; } }; +struct TextRadialOffset : DataDrivenLayoutProperty { + static constexpr const char *name() { return "text-radial-offset"; } + static float defaultValue() { return 0; } +}; + struct TextVariableAnchor : LayoutProperty> { static constexpr const char *name() { return "text-variable-anchor"; } static std::vector defaultValue() { return { }; } @@ -289,6 +294,7 @@ class SymbolLayoutProperties : public Properties< TextLineHeight, TextLetterSpacing, TextJustify, + TextRadialOffset, TextVariableAnchor, TextAnchor, TextMaxAngle, -- cgit v1.2.1