diff options
author | Molly Lloyd <molly@mapbox.com> | 2018-12-13 17:05:43 -0800 |
---|---|---|
committer | Molly Lloyd <molly@mapbox.com> | 2018-12-13 17:05:43 -0800 |
commit | 7db9ce37e648e8145816f11dcdb3251f0ce81d74 (patch) | |
tree | 8f6b8c96e9571355b72f6e2d633a5d8036eb59a8 | |
parent | 98984ef2926dbd1cc6876880ac99cfa737f74a1c (diff) | |
download | qtlocation-mapboxgl-7db9ce37e648e8145816f11dcdb3251f0ce81d74.tar.gz |
[core] add dynamic-text-anchor property
-rw-r--r-- | include/mbgl/style/conversion/constant.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/style/layers/symbol_layer.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/style/types.hpp | 13 | ||||
-rwxr-xr-x | scripts/generate-style-code.js | 2 | ||||
-rw-r--r-- | src/mbgl/style/conversion/constant.cpp | 22 | ||||
-rw-r--r-- | src/mbgl/style/conversion/function.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/conversion/property_value.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/style/expression/value.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/style/layers/symbol_layer.cpp | 65 | ||||
-rw-r--r-- | src/mbgl/style/layers/symbol_layer_properties.hpp | 12 | ||||
-rw-r--r-- | src/mbgl/style/types.cpp | 13 |
11 files changed, 147 insertions, 2 deletions
diff --git a/include/mbgl/style/conversion/constant.hpp b/include/mbgl/style/conversion/constant.hpp index 40657528c4..83785eed4e 100644 --- a/include/mbgl/style/conversion/constant.hpp +++ b/include/mbgl/style/conversion/constant.hpp @@ -54,6 +54,11 @@ struct Converter<std::vector<std::string>> { optional<std::vector<std::string>> operator()(const Convertible& value, Error& error) const; }; +template <> +struct Converter<std::vector<DynamicTextAnchorType>> { + optional<std::vector<DynamicTextAnchorType>> operator()(const Convertible& value, Error& error) const; +}; + } // namespace conversion } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 764f1585f6..eaba375ade 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -134,6 +134,14 @@ public: PropertyValue<TextJustifyType> getTextJustify() const; void setTextJustify(PropertyValue<TextJustifyType>); + static PropertyValue<float> getDefaultDynamicTextOffset(); + PropertyValue<float> getDynamicTextOffset() const; + void setDynamicTextOffset(PropertyValue<float>); + + static PropertyValue<std::vector<DynamicTextAnchorType>> getDefaultDynamicTextAnchor(); + PropertyValue<std::vector<DynamicTextAnchorType>> getDynamicTextAnchor() const; + void setDynamicTextAnchor(PropertyValue<std::vector<DynamicTextAnchorType>>); + static PropertyValue<SymbolAnchorType> getDefaultTextAnchor(); PropertyValue<SymbolAnchorType> getTextAnchor() const; void setTextAnchor(PropertyValue<SymbolAnchorType>); diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index ed875733c7..2a7635ff2d 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -98,6 +98,19 @@ enum class SymbolAnchorType : uint8_t { BottomRight }; +enum class DynamicTextAnchorType : uint8_t { + Auto, + Center, + Left, + Right, + Top, + Bottom, + TopLeft, + TopRight, + BottomLeft, + BottomRight +}; + enum class TextTransformType : uint8_t { None, Uppercase, diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index 121d2d774a..8c8d0c3979 100755 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -49,7 +49,7 @@ global.evaluatedType = function (property) { if (property.length) { return `std::array<${evaluatedType({type: property.value})}, ${property.length}>`; } else { - return `std::vector<${evaluatedType({type: property.value})}>`; + return `std::vector<${evaluatedType({type: property.value, values: property.values, name: property.name})}>`; } default: throw new Error(`unknown type for ${property.name}`) } diff --git a/src/mbgl/style/conversion/constant.cpp b/src/mbgl/style/conversion/constant.cpp index bdc6371722..dc2a86d89b 100644 --- a/src/mbgl/style/conversion/constant.cpp +++ b/src/mbgl/style/conversion/constant.cpp @@ -64,6 +64,7 @@ template optional<TextJustifyType> Converter<TextJustifyType>::operator()(const template optional<TextTransformType> Converter<TextTransformType>::operator()(const Convertible&, Error&) const; template optional<TranslateAnchorType> Converter<TranslateAnchorType>::operator()(const Convertible&, Error&) const; template optional<VisibilityType> Converter<VisibilityType>::operator()(const Convertible&, Error&) const; +template optional<DynamicTextAnchorType> Converter<DynamicTextAnchorType>::operator()(const Convertible&, Error&) const; optional<Color> Converter<Color>::operator()(const Convertible& value, Error& error) const { optional<std::string> string = toString(value); @@ -146,6 +147,27 @@ optional<std::vector<std::string>> Converter<std::vector<std::string>>::operator return result; } +optional<std::vector<DynamicTextAnchorType>> Converter<std::vector<DynamicTextAnchorType>>::operator()(const Convertible& value, Error& error) const { + if (!isArray(value)) { + error.message = "value must be an array"; + return nullopt; + } + + std::vector<DynamicTextAnchorType> result; + result.reserve(arrayLength(value)); + + for (std::size_t i = 0; i < arrayLength(value); ++i) { + optional<DynamicTextAnchorType> string = Converter<DynamicTextAnchorType>{}(arrayMember(value, i), error); + if (!string) { + error.message = "value must be an array of strings"; + return nullopt; + } + result.push_back(*string); + } + + return result; +} + } // namespace conversion } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp index 5877d0eb7c..76db1aadae 100644 --- a/src/mbgl/style/conversion/function.cpp +++ b/src/mbgl/style/conversion/function.cpp @@ -136,6 +136,8 @@ template optional<PropertyExpression<std::vector<std::string>>> convertFunctionToExpression<std::vector<std::string>>(const Convertible&, Error&, bool); template optional<PropertyExpression<SymbolAnchorType>> convertFunctionToExpression<SymbolAnchorType>(const Convertible&, Error&, bool); +template optional<PropertyExpression<std::vector<DynamicTextAnchorType>>> + convertFunctionToExpression<std::vector<DynamicTextAnchorType>>(const Convertible&, Error&, bool); template optional<PropertyExpression<SymbolPlacementType>> convertFunctionToExpression<SymbolPlacementType>(const Convertible&, Error&, bool); template optional<PropertyExpression<SymbolZOrderType>> diff --git a/src/mbgl/style/conversion/property_value.cpp b/src/mbgl/style/conversion/property_value.cpp index ff038908b6..8d85f2596c 100644 --- a/src/mbgl/style/conversion/property_value.cpp +++ b/src/mbgl/style/conversion/property_value.cpp @@ -73,6 +73,7 @@ template optional<PropertyValue<LineJoinType>> Converter<PropertyValue<LineJoinT template optional<PropertyValue<Position>> Converter<PropertyValue<Position>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; template optional<PropertyValue<RasterResamplingType>> Converter<PropertyValue<RasterResamplingType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; template optional<PropertyValue<SymbolAnchorType>> Converter<PropertyValue<SymbolAnchorType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template optional<PropertyValue<std::vector<DynamicTextAnchorType>>> Converter<PropertyValue<std::vector<DynamicTextAnchorType>>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; template optional<PropertyValue<SymbolPlacementType>> Converter<PropertyValue<SymbolPlacementType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; template optional<PropertyValue<SymbolZOrderType>> Converter<PropertyValue<SymbolZOrderType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; template optional<PropertyValue<TextJustifyType>> Converter<PropertyValue<TextJustifyType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp index 436ed83ecd..c6757042a4 100644 --- a/src/mbgl/style/expression/value.cpp +++ b/src/mbgl/style/expression/value.cpp @@ -324,6 +324,9 @@ template struct ValueConverter<std::vector<float>>; template type::Type valueTypeToExpressionType<std::vector<std::string>>(); template struct ValueConverter<std::vector<std::string>>; +template type::Type valueTypeToExpressionType<std::vector<DynamicTextAnchorType>>(); +template struct ValueConverter<std::vector<DynamicTextAnchorType>>; + template type::Type valueTypeToExpressionType<AlignmentType>(); template struct ValueConverter<AlignmentType>; @@ -354,6 +357,9 @@ template struct ValueConverter<TextJustifyType>; template type::Type valueTypeToExpressionType<TextTransformType>(); template struct ValueConverter<TextTransformType>; +template type::Type valueTypeToExpressionType<DynamicTextAnchorType>(); +template struct ValueConverter<DynamicTextAnchorType>; + template type::Type valueTypeToExpressionType<TranslateAnchorType>(); template struct ValueConverter<TranslateAnchorType>; diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index be25594f54..3cb5bd131a 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -491,6 +491,38 @@ void SymbolLayer::setTextJustify(PropertyValue<TextJustifyType> value) { baseImpl = std::move(impl_); observer->onLayerChanged(*this); } +PropertyValue<float> SymbolLayer::getDefaultDynamicTextOffset() { + return DynamicTextOffset::defaultValue(); +} + +PropertyValue<float> SymbolLayer::getDynamicTextOffset() const { + return impl().layout.get<DynamicTextOffset>(); +} + +void SymbolLayer::setDynamicTextOffset(PropertyValue<float> value) { + if (value == getDynamicTextOffset()) + return; + auto impl_ = mutableImpl(); + impl_->layout.get<DynamicTextOffset>() = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} +PropertyValue<std::vector<DynamicTextAnchorType>> SymbolLayer::getDefaultDynamicTextAnchor() { + return DynamicTextAnchor::defaultValue(); +} + +PropertyValue<std::vector<DynamicTextAnchorType>> SymbolLayer::getDynamicTextAnchor() const { + return impl().layout.get<DynamicTextAnchor>(); +} + +void SymbolLayer::setDynamicTextAnchor(PropertyValue<std::vector<DynamicTextAnchorType>> value) { + if (value == getDynamicTextAnchor()) + return; + auto impl_ = mutableImpl(); + impl_->layout.get<DynamicTextAnchor>() = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} PropertyValue<SymbolAnchorType> SymbolLayer::getDefaultTextAnchor() { return TextAnchor::defaultValue(); } @@ -1438,6 +1470,8 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co TextLineHeight, TextLetterSpacing, TextJustify, + DynamicTextOffset, + DynamicTextAnchor, TextAnchor, TextMaxAngle, TextRotate, @@ -1615,6 +1649,18 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co } break; + case util::hashFNV1a("dynamic-text-offset"): + if (name == "dynamic-text-offset") { + property = Property::DynamicTextOffset; + } + break; + + case util::hashFNV1a("dynamic-text-anchor"): + if (name == "dynamic-text-anchor") { + property = Property::DynamicTextAnchor; + } + break; + case util::hashFNV1a("text-anchor"): if (name == "text-anchor") { property = Property::TextAnchor; @@ -1823,7 +1869,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::DynamicTextOffset || property == Property::TextRotate) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { @@ -1855,6 +1901,11 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co return nullopt; } + if (property == Property::DynamicTextOffset) { + setDynamicTextOffset(*typedValue); + return nullopt; + } + if (property == Property::TextRotate) { setTextRotate(*typedValue); return nullopt; @@ -1972,6 +2023,18 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co } + if (property == Property::DynamicTextAnchor) { + Error error; + optional<PropertyValue<std::vector<DynamicTextAnchorType>>> typedValue = convert<PropertyValue<std::vector<DynamicTextAnchorType>>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setDynamicTextAnchor(*typedValue); + return nullopt; + + } + if (property == Property::TextTransform) { Error error; optional<PropertyValue<TextTransformType>> typedValue = convert<PropertyValue<TextTransformType>>(value, error, true, false); diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index 6c147f440d..5c34841162 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -147,6 +147,16 @@ struct TextJustify : DataDrivenLayoutProperty<TextJustifyType> { static TextJustifyType defaultValue() { return TextJustifyType::Center; } }; +struct DynamicTextOffset : DataDrivenLayoutProperty<float> { + static constexpr const char * key = "dynamic-text-offset"; + static float defaultValue() { return 0; } +}; + +struct DynamicTextAnchor : LayoutProperty<std::vector<DynamicTextAnchorType>> { + static constexpr const char * key = "dynamic-text-anchor"; + static std::vector<DynamicTextAnchorType> defaultValue() { return { }; } +}; + struct TextAnchor : DataDrivenLayoutProperty<SymbolAnchorType> { static constexpr const char * key = "text-anchor"; static SymbolAnchorType defaultValue() { return SymbolAnchorType::Center; } @@ -281,6 +291,8 @@ class SymbolLayoutProperties : public Properties< TextLineHeight, TextLetterSpacing, TextJustify, + DynamicTextOffset, + DynamicTextAnchor, TextAnchor, TextMaxAngle, TextRotate, diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp index 51174cf152..26e3a58d97 100644 --- a/src/mbgl/style/types.cpp +++ b/src/mbgl/style/types.cpp @@ -77,6 +77,19 @@ MBGL_DEFINE_ENUM(SymbolAnchorType, { { SymbolAnchorType::BottomRight, "bottom-right" } }); +MBGL_DEFINE_ENUM(DynamicTextAnchorType, { + { DynamicTextAnchorType::Auto, "auto" }, + { DynamicTextAnchorType::Center, "center" }, + { DynamicTextAnchorType::Left, "left" }, + { DynamicTextAnchorType::Right, "right" }, + { DynamicTextAnchorType::Top, "top" }, + { DynamicTextAnchorType::Bottom, "bottom" }, + { DynamicTextAnchorType::TopLeft, "top-left" }, + { DynamicTextAnchorType::TopRight, "top-right" }, + { DynamicTextAnchorType::BottomLeft, "bottom-left" }, + { DynamicTextAnchorType::BottomRight, "bottom-right" } +}); + MBGL_DEFINE_ENUM(SymbolZOrderType, { { SymbolZOrderType::ViewportY, "viewport-y" }, { SymbolZOrderType::Source, "source" } |