summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/conversion/constant.cpp22
-rw-r--r--src/mbgl/style/conversion/function.cpp2
-rw-r--r--src/mbgl/style/conversion/property_value.cpp1
-rw-r--r--src/mbgl/style/expression/value.cpp6
-rw-r--r--src/mbgl/style/layers/symbol_layer.cpp65
-rw-r--r--src/mbgl/style/layers/symbol_layer_properties.hpp12
-rw-r--r--src/mbgl/style/types.cpp13
7 files changed, 120 insertions, 1 deletions
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" }