diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index c7082f232..93275e6dd 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -38,6 +38,10 @@ public: const PropertyValue& getSymbolAvoidEdges() const; void setSymbolAvoidEdges(const PropertyValue&); + static PropertyValue getDefaultSymbolSortKey(); + const PropertyValue& getSymbolSortKey() const; + void setSymbolSortKey(const PropertyValue&); + static PropertyValue getDefaultSymbolZOrder(); const PropertyValue& getSymbolZOrder() const; void setSymbolZOrder(const PropertyValue&); diff --git a/scripts/style-spec.js b/scripts/style-spec.js index 19b7378cf..8a9c9d414 100644 --- a/scripts/style-spec.js +++ b/scripts/style-spec.js @@ -1,4 +1 @@ var spec = module.exports = require('../mapbox-gl-js/src/style-spec/reference/v8'); - -// Make temporary modifications here when Native doesn't have all features that JS has. -delete spec.layout_symbol['symbol-sort-key']; diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index c8d781618..0284ba0d3 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -108,6 +108,22 @@ void SymbolLayer::setSymbolAvoidEdges(const PropertyValue& value) { baseImpl = std::move(impl_); observer->onLayerChanged(*this); } +PropertyValue SymbolLayer::getDefaultSymbolSortKey() { + return SymbolSortKey::defaultValue(); +} + +const PropertyValue& SymbolLayer::getSymbolSortKey() const { + return impl().layout.get(); +} + +void SymbolLayer::setSymbolSortKey(const PropertyValue& value) { + if (value == getSymbolSortKey()) + return; + auto impl_ = mutableImpl(); + impl_->layout.get() = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} PropertyValue SymbolLayer::getDefaultSymbolZOrder() { return SymbolZOrder::defaultValue(); } @@ -1333,6 +1349,7 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co SymbolPlacement, SymbolSpacing, SymbolAvoidEdges, + SymbolSortKey, SymbolZOrder, IconAllowOverlap, IconIgnorePlacement, @@ -1374,6 +1391,7 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co { "symbol-placement", static_cast(Property::SymbolPlacement) }, { "symbol-spacing", static_cast(Property::SymbolSpacing) }, { "symbol-avoid-edges", static_cast(Property::SymbolAvoidEdges) }, + { "symbol-sort-key", static_cast(Property::SymbolSortKey) }, { "symbol-z-order", static_cast(Property::SymbolZOrder) }, { "icon-allow-overlap", static_cast(Property::IconAllowOverlap) }, { "icon-ignore-placement", static_cast(Property::IconIgnorePlacement) }, @@ -1520,6 +1538,55 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co } + if (property == Property::SymbolSortKey || 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) { + return error; + } + + if (property == Property::SymbolSortKey) { + setSymbolSortKey(*typedValue); + return nullopt; + } + + if (property == Property::IconSize) { + setIconSize(*typedValue); + return nullopt; + } + + if (property == Property::IconRotate) { + setIconRotate(*typedValue); + return nullopt; + } + + if (property == Property::TextSize) { + setTextSize(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxWidth) { + setTextMaxWidth(*typedValue); + return nullopt; + } + + if (property == Property::TextLetterSpacing) { + setTextLetterSpacing(*typedValue); + return nullopt; + } + + if (property == Property::TextRadialOffset) { + setTextRadialOffset(*typedValue); + return nullopt; + } + + if (property == Property::TextRotate) { + setTextRotate(*typedValue); + return nullopt; + } + + } + if (property == Property::SymbolZOrder) { Error error; optional> typedValue = convert>(value, error, false, false); @@ -1561,50 +1628,6 @@ 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::TextRadialOffset || property == Property::TextRotate) { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconSize) { - setIconSize(*typedValue); - return nullopt; - } - - if (property == Property::IconRotate) { - setIconRotate(*typedValue); - return nullopt; - } - - if (property == Property::TextSize) { - setTextSize(*typedValue); - return nullopt; - } - - if (property == Property::TextMaxWidth) { - setTextMaxWidth(*typedValue); - return nullopt; - } - - if (property == Property::TextLetterSpacing) { - setTextLetterSpacing(*typedValue); - return nullopt; - } - - if (property == Property::TextRadialOffset) { - setTextRadialOffset(*typedValue); - return nullopt; - } - - if (property == Property::TextRotate) { - setTextRotate(*typedValue); - return nullopt; - } - - } - if (property == Property::IconTextFit) { Error error; optional> typedValue = convert>(value, error, false, false); diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index 6b6e86fc3..caefbad13 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -27,6 +27,11 @@ struct SymbolAvoidEdges : LayoutProperty { static bool defaultValue() { return false; } }; +struct SymbolSortKey : DataDrivenLayoutProperty { + static constexpr const char *name() { return "symbol-sort-key"; } + static float defaultValue() { return 0; } +}; + struct SymbolZOrder : LayoutProperty { static constexpr const char *name() { return "symbol-z-order"; } static SymbolZOrderType defaultValue() { return SymbolZOrderType::Auto; } @@ -270,6 +275,7 @@ class SymbolLayoutProperties : public Properties< SymbolPlacement, SymbolSpacing, SymbolAvoidEdges, + SymbolSortKey, SymbolZOrder, IconAllowOverlap, IconIgnorePlacement,