From 684000fc263ac6c4064e80505bd1a2f6c15fb0fa Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Mon, 2 Dec 2019 16:09:06 +0200 Subject: [core] Merge style::Layer::set{Layout,Paint}Property --- include/mbgl/style/layer.hpp | 4 +- include/mbgl/style/layers/background_layer.hpp | 3 +- include/mbgl/style/layers/circle_layer.hpp | 3 +- include/mbgl/style/layers/custom_layer.hpp | 3 +- include/mbgl/style/layers/fill_extrusion_layer.hpp | 3 +- include/mbgl/style/layers/fill_layer.hpp | 3 +- include/mbgl/style/layers/heatmap_layer.hpp | 3 +- include/mbgl/style/layers/hillshade_layer.hpp | 3 +- include/mbgl/style/layers/layer.hpp.ejs | 3 +- include/mbgl/style/layers/line_layer.hpp | 3 +- include/mbgl/style/layers/raster_layer.hpp | 3 +- include/mbgl/style/layers/symbol_layer.hpp | 3 +- src/mbgl/style/conversion/layer.cpp | 9 +- src/mbgl/style/layers/background_layer.cpp | 35 +- src/mbgl/style/layers/circle_layer.cpp | 68 +- src/mbgl/style/layers/custom_layer.cpp | 6 +- src/mbgl/style/layers/fill_extrusion_layer.cpp | 63 +- src/mbgl/style/layers/fill_layer.cpp | 57 +- src/mbgl/style/layers/heatmap_layer.cpp | 38 +- src/mbgl/style/layers/hillshade_layer.cpp | 44 +- src/mbgl/style/layers/layer.cpp.ejs | 105 +-- src/mbgl/style/layers/line_layer.cpp | 161 ++--- src/mbgl/style/layers/raster_layer.cpp | 46 +- src/mbgl/style/layers/symbol_layer.cpp | 731 ++++++++++----------- 24 files changed, 548 insertions(+), 852 deletions(-) diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index b50ca75067..c80312bc23 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -110,9 +110,7 @@ public: void setMaxZoom(float); // Dynamic properties - virtual optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) = 0; - virtual optional setPaintProperty(const std::string& name, - const conversion::Convertible& value) = 0; + virtual optional setProperty(const std::string& name, const conversion::Convertible& value) = 0; optional setVisibility(const conversion::Convertible& value); virtual StyleProperty getProperty(const std::string&) const = 0; diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index bc9d5222fd..1f499884bb 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -21,8 +21,7 @@ public: ~BackgroundLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index 842094f944..6c511345f0 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -21,8 +21,7 @@ public: ~CircleLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index c193cfb8d9..5dce484980 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -69,8 +69,7 @@ public: ~CustomLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string&) const final; // Private implementation diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index 2996cd0066..d4655bd726 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -21,8 +21,7 @@ public: ~FillExtrusionLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 90e51c85a3..d5249c2696 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -21,8 +21,7 @@ public: ~FillLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 2dec03b927..ae3eb22214 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -22,8 +22,7 @@ public: ~HeatmapLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index 824606c29b..4c52cd9a22 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -21,8 +21,7 @@ public: ~HillshadeLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 7b60fcf6ea..3709f53bee 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -37,8 +37,7 @@ public: ~<%- camelize(type) %>Layer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 33312795d0..5b93d99cee 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -24,8 +24,7 @@ public: ~LineLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index bff38d42ac..50e9d6d20c 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -21,8 +21,7 @@ public: ~RasterLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 0ef212a3b9..8620869928 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -23,8 +23,7 @@ public: ~SymbolLayer() final; // Dynamic properties - optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; - optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + optional setProperty(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; diff --git a/src/mbgl/style/conversion/layer.cpp b/src/mbgl/style/conversion/layer.cpp index e8f94a1064..baf078c3a3 100644 --- a/src/mbgl/style/conversion/layer.cpp +++ b/src/mbgl/style/conversion/layer.cpp @@ -17,9 +17,7 @@ optional setPaintProperties(Layer& layer, const Convertible& value) { if (!isObject(*paintValue)) { return { { "paint must be an object" } }; } - return eachMember(*paintValue, [&] (const std::string& k, const Convertible& v) { - return layer.setPaintProperty(k, v); - }); + return eachMember(*paintValue, [&](const std::string& k, const Convertible& v) { return layer.setProperty(k, v); }); } optional> Converter>::operator()(const Convertible& value, Error& error) const { @@ -83,9 +81,8 @@ optional> Converter>::operator()(c error.message = "layout must be an object"; return nullopt; } - optional error_ = eachMember(*layoutValue, [&] (const std::string& k, const Convertible& v) { - return layer->setLayoutProperty(k, v); - }); + optional error_ = eachMember( + *layoutValue, [&](const std::string& k, const Convertible& v) { return layer->setProperty(k, v); }); if (error_) { error = *error_; return nullopt; diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 6629044018..68b07cba3c 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -169,56 +169,47 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"background-color-transition", toUint8(Property::BackgroundColorTransition)}, {"background-opacity-transition", toUint8(Property::BackgroundOpacityTransition)}, {"background-pattern-transition", toUint8(Property::BackgroundPatternTransition)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::BackgroundPatternTransition); } // namespace -optional BackgroundLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional BackgroundLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - if (property == Property::BackgroundColor) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundColor(*typedValue); return nullopt; - } - if (property == Property::BackgroundOpacity) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundOpacity(*typedValue); return nullopt; - } - if (property == Property::BackgroundPattern) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundPattern(*typedValue); return nullopt; - } - Error error; optional transition = convert(value, error); @@ -267,14 +258,6 @@ StyleProperty BackgroundLayer::getProperty(const std::string& name) const { return {}; } -optional BackgroundLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - - return Error { "layer doesn't support this property" }; -} - Mutable BackgroundLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index 619c58c366..7de6fef482 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -417,123 +417,107 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"circle-stroke-width-transition", toUint8(Property::CircleStrokeWidthTransition)}, {"circle-translate-transition", toUint8(Property::CircleTranslateTransition)}, {"circle-translate-anchor-transition", toUint8(Property::CircleTranslateAnchorTransition)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::CircleTranslateAnchorTransition); } // namespace -optional CircleLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional CircleLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - - if (property == Property::CircleBlur || property == Property::CircleOpacity || property == Property::CircleRadius || property == Property::CircleStrokeOpacity || property == Property::CircleStrokeWidth) { + if (property == Property::CircleBlur || property == Property::CircleOpacity || property == Property::CircleRadius || + property == Property::CircleStrokeOpacity || property == Property::CircleStrokeWidth) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::CircleBlur) { setCircleBlur(*typedValue); return nullopt; } - + if (property == Property::CircleOpacity) { setCircleOpacity(*typedValue); return nullopt; } - + if (property == Property::CircleRadius) { setCircleRadius(*typedValue); return nullopt; } - + if (property == Property::CircleStrokeOpacity) { setCircleStrokeOpacity(*typedValue); return nullopt; } - + if (property == Property::CircleStrokeWidth) { setCircleStrokeWidth(*typedValue); return nullopt; } - } - if (property == Property::CircleColor || property == Property::CircleStrokeColor) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::CircleColor) { setCircleColor(*typedValue); return nullopt; } - + if (property == Property::CircleStrokeColor) { setCircleStrokeColor(*typedValue); return nullopt; } - } - if (property == Property::CirclePitchAlignment) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setCirclePitchAlignment(*typedValue); return nullopt; - } - if (property == Property::CirclePitchScale) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setCirclePitchScale(*typedValue); return nullopt; - } - if (property == Property::CircleTranslate) { Error error; - optional>> typedValue = - convert>>(value, error, false, false); + const auto& typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setCircleTranslate(*typedValue); return nullopt; - } - if (property == Property::CircleTranslateAnchor) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setCircleTranslateAnchor(*typedValue); return nullopt; - } - Error error; optional transition = convert(value, error); @@ -654,14 +638,6 @@ StyleProperty CircleLayer::getProperty(const std::string& name) const { return {}; } -optional CircleLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - - return Error { "layer doesn't support this property" }; -} - Mutable CircleLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/custom_layer.cpp b/src/mbgl/style/layers/custom_layer.cpp index e13cf0069a..30bb2d220e 100644 --- a/src/mbgl/style/layers/custom_layer.cpp +++ b/src/mbgl/style/layers/custom_layer.cpp @@ -39,11 +39,7 @@ std::unique_ptr CustomLayer::cloneRef(const std::string&) const { using namespace conversion; -optional CustomLayer::setPaintProperty(const std::string&, const Convertible&) { - return Error { "layer doesn't support this property" }; -} - -optional CustomLayer::setLayoutProperty(const std::string&, const Convertible&) { +optional CustomLayer::setProperty(const std::string&, const Convertible&) { return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index e04e192298..2de27f3903 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -324,113 +324,94 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"fill-extrusion-translate-transition", toUint8(Property::FillExtrusionTranslateTransition)}, {"fill-extrusion-translate-anchor-transition", toUint8(Property::FillExtrusionTranslateAnchorTransition)}, {"fill-extrusion-vertical-gradient-transition", toUint8(Property::FillExtrusionVerticalGradientTransition)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::FillExtrusionVerticalGradientTransition); } // namespace -optional FillExtrusionLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional FillExtrusionLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - if (property == Property::FillExtrusionBase || property == Property::FillExtrusionHeight) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::FillExtrusionBase) { setFillExtrusionBase(*typedValue); return nullopt; } - + if (property == Property::FillExtrusionHeight) { setFillExtrusionHeight(*typedValue); return nullopt; } - } - if (property == Property::FillExtrusionColor) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setFillExtrusionColor(*typedValue); return nullopt; - } - if (property == Property::FillExtrusionOpacity) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionOpacity(*typedValue); return nullopt; - } - if (property == Property::FillExtrusionPattern) { Error error; - optional> typedValue = - convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setFillExtrusionPattern(*typedValue); return nullopt; - } - if (property == Property::FillExtrusionTranslate) { Error error; - optional>> typedValue = - convert>>(value, error, false, false); + const auto& typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionTranslate(*typedValue); return nullopt; - } - if (property == Property::FillExtrusionTranslateAnchor) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionTranslateAnchor(*typedValue); return nullopt; - } - if (property == Property::FillExtrusionVerticalGradient) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionVerticalGradient(*typedValue); return nullopt; - } - Error error; optional transition = convert(value, error); @@ -524,14 +505,6 @@ StyleProperty FillExtrusionLayer::getProperty(const std::string& name) const { return {}; } -optional FillExtrusionLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - - return Error { "layer doesn't support this property" }; -} - Mutable FillExtrusionLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index ad1f0ae847..9a43037871 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -293,101 +293,84 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"fill-pattern-transition", toUint8(Property::FillPatternTransition)}, {"fill-translate-transition", toUint8(Property::FillTranslateTransition)}, {"fill-translate-anchor-transition", toUint8(Property::FillTranslateAnchorTransition)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::FillTranslateAnchorTransition); } // namespace -optional FillLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional FillLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - if (property == Property::FillAntialias) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillAntialias(*typedValue); return nullopt; - } - if (property == Property::FillColor || property == Property::FillOutlineColor) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::FillColor) { setFillColor(*typedValue); return nullopt; } - + if (property == Property::FillOutlineColor) { setFillOutlineColor(*typedValue); return nullopt; } - } - if (property == Property::FillOpacity) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setFillOpacity(*typedValue); return nullopt; - } - if (property == Property::FillPattern) { Error error; - optional> typedValue = - convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setFillPattern(*typedValue); return nullopt; - } - if (property == Property::FillTranslate) { Error error; - optional>> typedValue = - convert>>(value, error, false, false); + const auto& typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setFillTranslate(*typedValue); return nullopt; - } - if (property == Property::FillTranslateAnchor) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillTranslateAnchor(*typedValue); return nullopt; - } - Error error; optional transition = convert(value, error); @@ -472,14 +455,6 @@ StyleProperty FillLayer::getProperty(const std::string& name) const { return {}; } -optional FillLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - - return Error { "layer doesn't support this property" }; -} - Mutable FillLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp index 234dda6c73..ba645a4a18 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -233,69 +233,61 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"heatmap-opacity-transition", toUint8(Property::HeatmapOpacityTransition)}, {"heatmap-radius-transition", toUint8(Property::HeatmapRadiusTransition)}, {"heatmap-weight-transition", toUint8(Property::HeatmapWeightTransition)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::HeatmapWeightTransition); } // namespace -optional HeatmapLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional HeatmapLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - if (property == Property::HeatmapColor) { Error error; - optional typedValue = convert(value, error, false, false); + const auto& typedValue = convert(value, error, false, false); if (!typedValue) { return error; } - + setHeatmapColor(*typedValue); return nullopt; - } - if (property == Property::HeatmapIntensity || property == Property::HeatmapOpacity) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + if (property == Property::HeatmapIntensity) { setHeatmapIntensity(*typedValue); return nullopt; } - + if (property == Property::HeatmapOpacity) { setHeatmapOpacity(*typedValue); return nullopt; } - } - if (property == Property::HeatmapRadius || property == Property::HeatmapWeight) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::HeatmapRadius) { setHeatmapRadius(*typedValue); return nullopt; } - + if (property == Property::HeatmapWeight) { setHeatmapWeight(*typedValue); return nullopt; } - } - Error error; optional transition = convert(value, error); @@ -362,14 +354,6 @@ StyleProperty HeatmapLayer::getProperty(const std::string& name) const { return {}; } -optional HeatmapLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - - return Error { "layer doesn't support this property" }; -} - Mutable HeatmapLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 5d84b7ded3..26ecfadfcc 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -262,75 +262,67 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"hillshade-illumination-anchor-transition", toUint8(Property::HillshadeIlluminationAnchorTransition)}, {"hillshade-illumination-direction-transition", toUint8(Property::HillshadeIlluminationDirectionTransition)}, {"hillshade-shadow-color-transition", toUint8(Property::HillshadeShadowColorTransition)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::HillshadeShadowColorTransition); } // namespace -optional HillshadeLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional HillshadeLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - - if (property == Property::HillshadeAccentColor || property == Property::HillshadeHighlightColor || property == Property::HillshadeShadowColor) { + if (property == Property::HillshadeAccentColor || property == Property::HillshadeHighlightColor || + property == Property::HillshadeShadowColor) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + if (property == Property::HillshadeAccentColor) { setHillshadeAccentColor(*typedValue); return nullopt; } - + if (property == Property::HillshadeHighlightColor) { setHillshadeHighlightColor(*typedValue); return nullopt; } - + if (property == Property::HillshadeShadowColor) { setHillshadeShadowColor(*typedValue); return nullopt; } - } - if (property == Property::HillshadeExaggeration || property == Property::HillshadeIlluminationDirection) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + if (property == Property::HillshadeExaggeration) { setHillshadeExaggeration(*typedValue); return nullopt; } - + if (property == Property::HillshadeIlluminationDirection) { setHillshadeIlluminationDirection(*typedValue); return nullopt; } - } - if (property == Property::HillshadeIlluminationAnchor) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setHillshadeIlluminationAnchor(*typedValue); return nullopt; - } - Error error; optional transition = convert(value, error); @@ -406,14 +398,6 @@ StyleProperty HillshadeLayer::getProperty(const std::string& name) const { return {}; } -optional HillshadeLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - - return Error { "layer doesn't support this property" }; -} - Mutable HillshadeLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index a47e5b95b4..bcec4098d5 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -2,6 +2,7 @@ const type = locals.type; const layoutProperties = locals.layoutProperties; const paintProperties = locals.paintProperties; + const allProperties = paintProperties.concat(layoutProperties); -%> // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. @@ -80,8 +81,9 @@ layerCapabilities['raster'] = defaults.require('Source').set('TileKind', // Splits lines that are over 120 characters at the firts occurance of '='. const split120Line = line => { - if (line.length > 120) { - return line.replace('=', '=\n '); + const ident = ' '; + if (line.length + ident.length > 120) { + return line.replace('=', `=\n${ident}`); } return line; }; @@ -224,50 +226,55 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< <%- paintProperties.map(p => `{"${p.name}-transition", toUint8(Property::${camelize(p.name)}Transition)}`).join(',\n ') %>, <%- layoutProperties.map(p => `{"${p.name}", toUint8(Property::${camelize(p.name)})}`).join(',\n ') %>}); <% } -%> - -<% const lastPaintProperty = paintProperties[paintProperties.length - 1]; -%> -<%-`constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::${camelize(lastPaintProperty.name)}Transition);` %> } // namespace -optional <%- camelize(type) %>Layer::setPaintProperty(const std::string& name, const Convertible& value) { +optional <%- camelize(type) %>Layer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - <% - const paintConversions = {}; - for (const property of paintProperties) { - const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven'; - const convertTokens = property.name === 'icon-image' || property.name === 'text-field'; - const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; - paintConversions[conversion] = paintConversions[conversion] || []; - paintConversions[conversion].push(property); - } - -%> - <% for (const key in paintConversions) { - const properties = paintConversions[key]; - %> - if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).join(' || ') %>) { +<% + const conversions = {}; + for (const property of allProperties) { + const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven'; + const convertTokens = property.name === 'icon-image' || property.name === 'text-field'; + const conversion = `const auto& typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; + conversions[conversion] = conversions[conversion] || []; + conversions[conversion].push(property); + } + const reduceConditions = (total, e) => { + const splitter = ' || '; + const ident = ' '; + let totalLength = total.length + e.length + ident.length + splitter.length + 3 /* ||*/; + const lastCR = total.lastIndexOf('\n'); + const length = (lastCR == -1) ? totalLength : (totalLength - (ident.length + lastCR)); + return total + (length <= 120 ? splitter : ` ||\n${ident}`) + e; + } +-%> +<% for (const key in conversions) { + const properties = conversions[key]; +-%> + if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).reduce(reduceConditions) %>) { Error error; <%- split120Line(key) %>; if (!typedValue) { return error; } - <% if (properties.length == 1) { %> +<% if (properties.length == 1) { %> set<%- camelize(properties[0].name) %>(*typedValue); return nullopt; - <% } else for (const property of properties) { %> +<% } else for (const property of properties) { %> if (property == Property::<%- camelize(property.name) %>) { set<%- camelize(property.name) %>(*typedValue); return nullopt; } - <% } %> +<% } -%> } - <% } %> - +<% } %> Error error; optional transition = convert(value, error); if (!transition) { @@ -305,52 +312,6 @@ StyleProperty <%- camelize(type) %>Layer::getProperty(const std::string& name) c return {}; } -optional <%- camelize(type) %>Layer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } -<% if (layoutProperties.length) { -%> - const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second <= lastPaintPropertyIndex) { - return Error { "layer doesn't support this property" }; - } - - auto property = static_cast(it->second); - - <% - const layoutConversions = {}; - for (const property of layoutProperties) { - const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven'; - const convertTokens = property.name === 'icon-image' || property.name === 'text-field'; - const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; - layoutConversions[conversion] = layoutConversions[conversion] || []; - layoutConversions[conversion].push(property); - } - -%> - <% for (const key in layoutConversions) { - const properties = layoutConversions[key]; - %> - if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).join(' || ') %>) { - Error error; - <%- split120Line(key) %>; - if (!typedValue) { - return error; - } - <% if (properties.length == 1) { %> - set<%- camelize(properties[0].name) %>(*typedValue); - return nullopt; - <% } else for (const property of properties) { %> - if (property == Property::<%- camelize(property.name) %>) { - set<%- camelize(property.name) %>(*typedValue); - return nullopt; - } - <% } %> - } - <% } %> -<% } /* if (layoutProperties.length) */ %> - return Error { "layer doesn't support this property" }; -} - Mutable <%- camelize(type) %>Layer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index 813ef68dec..0f3e49963c 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -491,129 +491,147 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"line-join", toUint8(Property::LineJoin)}, {"line-miter-limit", toUint8(Property::LineMiterLimit)}, {"line-round-limit", toUint8(Property::LineRoundLimit)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::LineWidthTransition); } // namespace -optional LineLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional LineLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - - if (property == Property::LineBlur || property == Property::LineGapWidth || property == Property::LineOffset || property == Property::LineOpacity || property == Property::LineWidth) { + if (property == Property::LineBlur || property == Property::LineGapWidth || property == Property::LineOffset || + property == Property::LineOpacity || property == Property::LineWidth) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::LineBlur) { setLineBlur(*typedValue); return nullopt; } - + if (property == Property::LineGapWidth) { setLineGapWidth(*typedValue); return nullopt; } - + if (property == Property::LineOffset) { setLineOffset(*typedValue); return nullopt; } - + if (property == Property::LineOpacity) { setLineOpacity(*typedValue); return nullopt; } - + if (property == Property::LineWidth) { setLineWidth(*typedValue); return nullopt; } - } - if (property == Property::LineColor) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setLineColor(*typedValue); return nullopt; - } - if (property == Property::LineDasharray) { Error error; - optional>> typedValue = - convert>>(value, error, false, false); + const auto& typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setLineDasharray(*typedValue); return nullopt; - } - if (property == Property::LineGradient) { Error error; - optional typedValue = convert(value, error, false, false); + const auto& typedValue = convert(value, error, false, false); if (!typedValue) { return error; } - + setLineGradient(*typedValue); return nullopt; - } - if (property == Property::LinePattern) { Error error; - optional> typedValue = - convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setLinePattern(*typedValue); return nullopt; - } - if (property == Property::LineTranslate) { Error error; - optional>> typedValue = - convert>>(value, error, false, false); + const auto& typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setLineTranslate(*typedValue); return nullopt; - } - if (property == Property::LineTranslateAnchor) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setLineTranslateAnchor(*typedValue); return nullopt; - } - + if (property == Property::LineCap) { + Error error; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + setLineCap(*typedValue); + return nullopt; + } + if (property == Property::LineJoin) { + Error error; + const auto& typedValue = convert>(value, error, true, false); + if (!typedValue) { + return error; + } + + setLineJoin(*typedValue); + return nullopt; + } + if (property == Property::LineMiterLimit || property == Property::LineRoundLimit) { + Error error; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::LineMiterLimit) { + setLineMiterLimit(*typedValue); + return nullopt; + } + + if (property == Property::LineRoundLimit) { + setLineRoundLimit(*typedValue); + return nullopt; + } + } Error error; optional transition = convert(value, error); @@ -742,65 +760,6 @@ StyleProperty LineLayer::getProperty(const std::string& name) const { return {}; } -optional LineLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second <= lastPaintPropertyIndex) { - return Error { "layer doesn't support this property" }; - } - - auto property = static_cast(it->second); - - - if (property == Property::LineCap) { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setLineCap(*typedValue); - return nullopt; - - } - - if (property == Property::LineJoin) { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setLineJoin(*typedValue); - return nullopt; - - } - - if (property == Property::LineMiterLimit || property == Property::LineRoundLimit) { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - if (property == Property::LineMiterLimit) { - setLineMiterLimit(*typedValue); - return nullopt; - } - - if (property == Property::LineRoundLimit) { - setLineRoundLimit(*typedValue); - return nullopt; - } - - } - - - return Error { "layer doesn't support this property" }; -} - Mutable LineLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index b990409886..97c67de299 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -324,76 +324,72 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"raster-opacity-transition", toUint8(Property::RasterOpacityTransition)}, {"raster-resampling-transition", toUint8(Property::RasterResamplingTransition)}, {"raster-saturation-transition", toUint8(Property::RasterSaturationTransition)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::RasterSaturationTransition); } // namespace -optional RasterLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional RasterLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - - if (property == Property::RasterBrightnessMax || property == Property::RasterBrightnessMin || property == Property::RasterContrast || property == Property::RasterFadeDuration || property == Property::RasterHueRotate || property == Property::RasterOpacity || property == Property::RasterSaturation) { + if (property == Property::RasterBrightnessMax || property == Property::RasterBrightnessMin || + property == Property::RasterContrast || property == Property::RasterFadeDuration || + property == Property::RasterHueRotate || property == Property::RasterOpacity || + property == Property::RasterSaturation) { Error error; - optional> typedValue = convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + if (property == Property::RasterBrightnessMax) { setRasterBrightnessMax(*typedValue); return nullopt; } - + if (property == Property::RasterBrightnessMin) { setRasterBrightnessMin(*typedValue); return nullopt; } - + if (property == Property::RasterContrast) { setRasterContrast(*typedValue); return nullopt; } - + if (property == Property::RasterFadeDuration) { setRasterFadeDuration(*typedValue); return nullopt; } - + if (property == Property::RasterHueRotate) { setRasterHueRotate(*typedValue); return nullopt; } - + if (property == Property::RasterOpacity) { setRasterOpacity(*typedValue); return nullopt; } - + if (property == Property::RasterSaturation) { setRasterSaturation(*typedValue); return nullopt; } - } - if (property == Property::RasterResampling) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setRasterResampling(*typedValue); return nullopt; - } - Error error; optional transition = convert(value, error); @@ -487,14 +483,6 @@ StyleProperty RasterLayer::getProperty(const std::string& name) const { return {}; } -optional RasterLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - - return Error { "layer doesn't support this property" }; -} - Mutable RasterLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 1383293d6d..fe9658b25a 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -1249,127 +1249,424 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"text-transform", toUint8(Property::TextTransform)}, {"text-variable-anchor", toUint8(Property::TextVariableAnchor)}, {"text-writing-mode", toUint8(Property::TextWritingMode)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::TextTranslateAnchorTransition); } // namespace -optional SymbolLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional SymbolLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast(it->second); - - if (property == Property::IconColor || property == Property::IconHaloColor || property == Property::TextColor || property == Property::TextHaloColor) { + if (property == Property::IconColor || property == Property::IconHaloColor || property == Property::TextColor || + property == Property::TextHaloColor) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::IconColor) { setIconColor(*typedValue); return nullopt; } - + if (property == Property::IconHaloColor) { setIconHaloColor(*typedValue); return nullopt; } - + if (property == Property::TextColor) { setTextColor(*typedValue); return nullopt; } - + if (property == Property::TextHaloColor) { setTextHaloColor(*typedValue); return nullopt; } - } - - if (property == Property::IconHaloBlur || property == Property::IconHaloWidth || property == Property::IconOpacity || property == Property::TextHaloBlur || property == Property::TextHaloWidth || property == Property::TextOpacity) { + if (property == Property::IconHaloBlur || property == Property::IconHaloWidth || + property == Property::IconOpacity || property == Property::TextHaloBlur || + property == Property::TextHaloWidth || property == Property::TextOpacity || property == Property::IconRotate || + property == Property::IconSize || property == Property::SymbolSortKey || + property == Property::TextLetterSpacing || property == Property::TextMaxWidth || + property == Property::TextRadialOffset || property == Property::TextRotate || property == Property::TextSize) { Error error; - optional> typedValue = convert>(value, error, true, false); + const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::IconHaloBlur) { setIconHaloBlur(*typedValue); return nullopt; } - + if (property == Property::IconHaloWidth) { setIconHaloWidth(*typedValue); return nullopt; } - + if (property == Property::IconOpacity) { setIconOpacity(*typedValue); return nullopt; } - + if (property == Property::TextHaloBlur) { setTextHaloBlur(*typedValue); return nullopt; } - + if (property == Property::TextHaloWidth) { setTextHaloWidth(*typedValue); return nullopt; } - + if (property == Property::TextOpacity) { setTextOpacity(*typedValue); return nullopt; } - + + if (property == Property::IconRotate) { + setIconRotate(*typedValue); + return nullopt; + } + + if (property == Property::IconSize) { + setIconSize(*typedValue); + return nullopt; + } + + if (property == Property::SymbolSortKey) { + setSymbolSortKey(*typedValue); + return nullopt; + } + + if (property == Property::TextLetterSpacing) { + setTextLetterSpacing(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxWidth) { + setTextMaxWidth(*typedValue); + return nullopt; + } + + if (property == Property::TextRadialOffset) { + setTextRadialOffset(*typedValue); + return nullopt; + } + + if (property == Property::TextRotate) { + setTextRotate(*typedValue); + return nullopt; + } + + if (property == Property::TextSize) { + setTextSize(*typedValue); + return nullopt; + } } - if (property == Property::IconTranslate || property == Property::TextTranslate) { Error error; - optional>> typedValue = - convert>>(value, error, false, false); + const auto& typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + if (property == Property::IconTranslate) { setIconTranslate(*typedValue); return nullopt; } - + if (property == Property::TextTranslate) { setTextTranslate(*typedValue); return nullopt; } - } - if (property == Property::IconTranslateAnchor || property == Property::TextTranslateAnchor) { Error error; - optional> typedValue = - convert>(value, error, false, false); + const auto& typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + if (property == Property::IconTranslateAnchor) { setIconTranslateAnchor(*typedValue); return nullopt; } - + if (property == Property::TextTranslateAnchor) { setTextTranslateAnchor(*typedValue); return nullopt; } - } - + if (property == Property::IconAllowOverlap || property == Property::IconIgnorePlacement || + property == Property::IconKeepUpright || property == Property::IconOptional || + property == Property::SymbolAvoidEdges || property == Property::TextAllowOverlap || + property == Property::TextIgnorePlacement || property == Property::TextKeepUpright || + property == Property::TextOptional) { + Error error; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconAllowOverlap) { + setIconAllowOverlap(*typedValue); + return nullopt; + } + + if (property == Property::IconIgnorePlacement) { + setIconIgnorePlacement(*typedValue); + return nullopt; + } + + if (property == Property::IconKeepUpright) { + setIconKeepUpright(*typedValue); + return nullopt; + } + + if (property == Property::IconOptional) { + setIconOptional(*typedValue); + return nullopt; + } + + if (property == Property::SymbolAvoidEdges) { + setSymbolAvoidEdges(*typedValue); + return nullopt; + } + + if (property == Property::TextAllowOverlap) { + setTextAllowOverlap(*typedValue); + return nullopt; + } + + if (property == Property::TextIgnorePlacement) { + setTextIgnorePlacement(*typedValue); + return nullopt; + } + + if (property == Property::TextKeepUpright) { + setTextKeepUpright(*typedValue); + return nullopt; + } + + if (property == Property::TextOptional) { + setTextOptional(*typedValue); + return nullopt; + } + } + if (property == Property::IconAnchor || property == Property::TextAnchor) { + Error error; + const auto& typedValue = convert>(value, error, true, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconAnchor) { + setIconAnchor(*typedValue); + return nullopt; + } + + if (property == Property::TextAnchor) { + setTextAnchor(*typedValue); + return nullopt; + } + } + if (property == Property::IconImage) { + Error error; + const auto& typedValue = convert>(value, error, true, true); + if (!typedValue) { + return error; + } + + setIconImage(*typedValue); + return nullopt; + } + if (property == Property::IconOffset || property == Property::TextOffset) { + Error error; + const auto& typedValue = convert>>(value, error, true, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconOffset) { + setIconOffset(*typedValue); + return nullopt; + } + + if (property == Property::TextOffset) { + setTextOffset(*typedValue); + return nullopt; + } + } + if (property == Property::IconPadding || property == Property::SymbolSpacing || + property == Property::TextLineHeight || property == Property::TextMaxAngle || + property == Property::TextPadding) { + Error error; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconPadding) { + setIconPadding(*typedValue); + return nullopt; + } + + if (property == Property::SymbolSpacing) { + setSymbolSpacing(*typedValue); + return nullopt; + } + + if (property == Property::TextLineHeight) { + setTextLineHeight(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxAngle) { + setTextMaxAngle(*typedValue); + return nullopt; + } + + if (property == Property::TextPadding) { + setTextPadding(*typedValue); + return nullopt; + } + } + if (property == Property::IconPitchAlignment || property == Property::IconRotationAlignment || + property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) { + Error error; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconPitchAlignment) { + setIconPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::IconRotationAlignment) { + setIconRotationAlignment(*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; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + setIconTextFit(*typedValue); + return nullopt; + } + if (property == Property::IconTextFitPadding) { + Error error; + const auto& typedValue = convert>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setIconTextFitPadding(*typedValue); + return nullopt; + } + if (property == Property::SymbolPlacement) { + Error error; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + setSymbolPlacement(*typedValue); + return nullopt; + } + if (property == Property::SymbolZOrder) { + Error error; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + setSymbolZOrder(*typedValue); + return nullopt; + } + if (property == Property::TextField) { + Error error; + const auto& typedValue = convert>(value, error, true, true); + if (!typedValue) { + return error; + } + + setTextField(*typedValue); + return nullopt; + } + if (property == Property::TextFont) { + Error error; + const auto& typedValue = convert>>(value, error, true, false); + if (!typedValue) { + return error; + } + + setTextFont(*typedValue); + return nullopt; + } + if (property == Property::TextJustify) { + Error error; + const auto& typedValue = convert>(value, error, true, false); + if (!typedValue) { + return error; + } + + setTextJustify(*typedValue); + return nullopt; + } + if (property == Property::TextTransform) { + Error error; + const auto& typedValue = convert>(value, error, true, false); + if (!typedValue) { + return error; + } + + setTextTransform(*typedValue); + return nullopt; + } + if (property == Property::TextVariableAnchor) { + Error error; + const auto& typedValue = + convert>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setTextVariableAnchor(*typedValue); + return nullopt; + } + if (property == Property::TextWritingMode) { + Error error; + const auto& typedValue = convert>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setTextWritingMode(*typedValue); + return nullopt; + } Error error; optional transition = convert(value, error); @@ -1599,370 +1896,6 @@ StyleProperty SymbolLayer::getProperty(const std::string& name) const { return {}; } -optional SymbolLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second <= lastPaintPropertyIndex) { - return Error { "layer doesn't support this property" }; - } - - auto property = static_cast(it->second); - - - if (property == Property::IconAllowOverlap || property == Property::IconIgnorePlacement || property == Property::IconKeepUpright || property == Property::IconOptional || property == Property::SymbolAvoidEdges || property == Property::TextAllowOverlap || property == Property::TextIgnorePlacement || property == Property::TextKeepUpright || property == Property::TextOptional) { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconAllowOverlap) { - setIconAllowOverlap(*typedValue); - return nullopt; - } - - if (property == Property::IconIgnorePlacement) { - setIconIgnorePlacement(*typedValue); - return nullopt; - } - - if (property == Property::IconKeepUpright) { - setIconKeepUpright(*typedValue); - return nullopt; - } - - if (property == Property::IconOptional) { - setIconOptional(*typedValue); - return nullopt; - } - - if (property == Property::SymbolAvoidEdges) { - setSymbolAvoidEdges(*typedValue); - return nullopt; - } - - if (property == Property::TextAllowOverlap) { - setTextAllowOverlap(*typedValue); - return nullopt; - } - - if (property == Property::TextIgnorePlacement) { - setTextIgnorePlacement(*typedValue); - return nullopt; - } - - if (property == Property::TextKeepUpright) { - setTextKeepUpright(*typedValue); - return nullopt; - } - - if (property == Property::TextOptional) { - setTextOptional(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconAnchor || property == Property::TextAnchor) { - Error error; - optional> typedValue = - convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconAnchor) { - setIconAnchor(*typedValue); - return nullopt; - } - - if (property == Property::TextAnchor) { - setTextAnchor(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconImage) { - Error error; - optional> typedValue = - convert>(value, error, true, true); - if (!typedValue) { - return error; - } - - setIconImage(*typedValue); - return nullopt; - - } - - if (property == Property::IconOffset || property == Property::TextOffset) { - Error error; - optional>> typedValue = - convert>>(value, error, true, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconOffset) { - setIconOffset(*typedValue); - return nullopt; - } - - if (property == Property::TextOffset) { - setTextOffset(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconPadding || property == Property::SymbolSpacing || property == Property::TextLineHeight || property == Property::TextMaxAngle || property == Property::TextPadding) { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconPadding) { - setIconPadding(*typedValue); - return nullopt; - } - - if (property == Property::SymbolSpacing) { - setSymbolSpacing(*typedValue); - return nullopt; - } - - if (property == Property::TextLineHeight) { - setTextLineHeight(*typedValue); - return nullopt; - } - - if (property == Property::TextMaxAngle) { - setTextMaxAngle(*typedValue); - return nullopt; - } - - if (property == Property::TextPadding) { - setTextPadding(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconPitchAlignment || property == Property::IconRotationAlignment || property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconPitchAlignment) { - setIconPitchAlignment(*typedValue); - return nullopt; - } - - if (property == Property::IconRotationAlignment) { - setIconRotationAlignment(*typedValue); - return nullopt; - } - - if (property == Property::TextPitchAlignment) { - setTextPitchAlignment(*typedValue); - return nullopt; - } - - if (property == Property::TextRotationAlignment) { - setTextRotationAlignment(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconRotate || property == Property::IconSize || property == Property::SymbolSortKey || property == Property::TextLetterSpacing || property == Property::TextMaxWidth || property == Property::TextRadialOffset || property == Property::TextRotate || property == Property::TextSize) { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconRotate) { - setIconRotate(*typedValue); - return nullopt; - } - - if (property == Property::IconSize) { - setIconSize(*typedValue); - return nullopt; - } - - if (property == Property::SymbolSortKey) { - setSymbolSortKey(*typedValue); - return nullopt; - } - - if (property == Property::TextLetterSpacing) { - setTextLetterSpacing(*typedValue); - return nullopt; - } - - if (property == Property::TextMaxWidth) { - setTextMaxWidth(*typedValue); - return nullopt; - } - - if (property == Property::TextRadialOffset) { - setTextRadialOffset(*typedValue); - return nullopt; - } - - if (property == Property::TextRotate) { - setTextRotate(*typedValue); - return nullopt; - } - - if (property == Property::TextSize) { - setTextSize(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconTextFit) { - Error error; - optional> typedValue = - convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconTextFit(*typedValue); - return nullopt; - - } - - if (property == Property::IconTextFitPadding) { - Error error; - optional>> typedValue = - convert>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconTextFitPadding(*typedValue); - return nullopt; - - } - - if (property == Property::SymbolPlacement) { - Error error; - optional> typedValue = - convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setSymbolPlacement(*typedValue); - return nullopt; - - } - - if (property == Property::SymbolZOrder) { - Error error; - optional> typedValue = - convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setSymbolZOrder(*typedValue); - return nullopt; - - } - - if (property == Property::TextField) { - Error error; - optional> typedValue = - convert>(value, error, true, true); - if (!typedValue) { - return error; - } - - setTextField(*typedValue); - return nullopt; - - } - - if (property == Property::TextFont) { - Error error; - optional>> typedValue = - convert>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextFont(*typedValue); - return nullopt; - - } - - if (property == Property::TextJustify) { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextJustify(*typedValue); - return nullopt; - - } - - if (property == Property::TextTransform) { - Error error; - optional> typedValue = - convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextTransform(*typedValue); - return nullopt; - - } - - if (property == Property::TextVariableAnchor) { - Error error; - optional>> typedValue = - convert>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextVariableAnchor(*typedValue); - return nullopt; - - } - - if (property == Property::TextWritingMode) { - Error error; - optional>> typedValue = - convert>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextWritingMode(*typedValue); - return nullopt; - - } - - - return Error { "layer doesn't support this property" }; -} - Mutable SymbolLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -- cgit v1.2.1