From 905ca29866b4353dc61c455989fdeec0b3e8a470 Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Mon, 8 Apr 2019 18:13:22 +0300 Subject: [core] Enable 'symbol-sort-key' layout property and generate style code --- include/mbgl/style/layers/symbol_layer.hpp | 4 + scripts/style-spec.js | 3 - src/mbgl/style/layers/symbol_layer.cpp | 103 +++++++++++++--------- src/mbgl/style/layers/symbol_layer_properties.hpp | 6 ++ 4 files changed, 73 insertions(+), 43 deletions(-) diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index c7082f232d..93275e6dd2 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 19b7378cf8..8a9c9d4144 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 c8d7816180..0284ba0d3c 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,54 +1538,18 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co } - if (property == Property::SymbolZOrder) { + 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, false, false); - if (!typedValue) { - return error; - } - - setSymbolZOrder(*typedValue); - return nullopt; - - } - - if (property == Property::IconRotationAlignment || property == Property::IconPitchAlignment || property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) { - Error error; - optional> typedValue = convert>(value, error, false, false); + optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - if (property == Property::IconRotationAlignment) { - setIconRotationAlignment(*typedValue); - return nullopt; - } - - if (property == Property::IconPitchAlignment) { - setIconPitchAlignment(*typedValue); - return nullopt; - } - - if (property == Property::TextPitchAlignment) { - setTextPitchAlignment(*typedValue); + if (property == Property::SymbolSortKey) { + setSymbolSortKey(*typedValue); return nullopt; } - if (property == Property::TextRotationAlignment) { - setTextRotationAlignment(*typedValue); - return nullopt; - } - - } - - 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; @@ -1605,6 +1587,47 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co } + if (property == Property::SymbolZOrder) { + Error error; + optional> typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + setSymbolZOrder(*typedValue); + return nullopt; + + } + + if (property == Property::IconRotationAlignment || property == Property::IconPitchAlignment || property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) { + Error error; + optional> typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconRotationAlignment) { + setIconRotationAlignment(*typedValue); + return nullopt; + } + + if (property == Property::IconPitchAlignment) { + setIconPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::TextPitchAlignment) { + setTextPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::TextRotationAlignment) { + setTextRotationAlignment(*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 6b6e86fc3e..caefbad137 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, -- cgit v1.2.1