From c2dc873cf9c026e964d1d73a2c8301d21509da6e Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Tue, 24 Sep 2019 23:06:05 +0300 Subject: [core] Introduce Layer::getPaintProperty() generic getter --- include/mbgl/style/conversion_impl.hpp | 35 +++++++++++++++++++--- include/mbgl/style/layer.hpp | 18 +++++++++-- include/mbgl/style/layers/background_layer.hpp | 2 ++ include/mbgl/style/layers/circle_layer.hpp | 2 ++ include/mbgl/style/layers/custom_layer.hpp | 2 +- include/mbgl/style/layers/fill_extrusion_layer.hpp | 2 ++ include/mbgl/style/layers/fill_layer.hpp | 2 ++ include/mbgl/style/layers/heatmap_layer.hpp | 2 ++ include/mbgl/style/layers/hillshade_layer.hpp | 2 ++ include/mbgl/style/layers/layer.hpp.ejs | 2 ++ include/mbgl/style/layers/line_layer.hpp | 2 ++ include/mbgl/style/layers/raster_layer.hpp | 2 ++ include/mbgl/style/layers/symbol_layer.hpp | 2 ++ 13 files changed, 67 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index 7ac4ec649b..866eff9eb5 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -2,7 +2,9 @@ #include #include +#include #include +#include #include #include #include @@ -10,6 +12,7 @@ #include #include +#include #include #include @@ -313,6 +316,18 @@ struct ValueFactory { static Value make(const ColorRampPropertyValue& value) { return value.getExpression().serialize(); } }; +template <> +struct ValueFactory { + static Value make(const TransitionOptions& value) { + return mapbox::base::ValueArray{ + {std::chrono::duration_cast(value.duration.value_or(mbgl::Duration::zero())) + .count(), + std::chrono::duration_cast(value.delay.value_or(mbgl::Duration::zero())) + .count(), + value.enablePlacementTransitions}}; + } +}; + template <> struct ValueFactory { static Value make(const Color& color) { return color.toObject(); } @@ -334,10 +349,22 @@ Value makeValue(T&& arg) { } template -Value makeValue(const PropertyValue& value) { - return value.match([](const Undefined&) -> Value { return {}; }, - [](const T& t) -> Value { return makeValue(t); }, - [](const PropertyExpression& fn) { return fn.getExpression().serialize(); }); +LayerProperty makeLayerProperty(const PropertyValue& value) { + return value.match([](const Undefined&) -> LayerProperty { return {}; }, + [](const T& t) -> LayerProperty { + return {makeValue(t), LayerProperty::Kind::Constant}; + }, + [](const PropertyExpression& fn) -> LayerProperty { + return {fn.getExpression().serialize(), LayerProperty::Kind::Expression}; + }); +} + +inline LayerProperty makeLayerProperty(const TransitionOptions& value) { + return {makeValue(value), LayerProperty::Kind::Transition}; +} + +inline LayerProperty makeLayerProperty(const ColorRampPropertyValue& value) { + return {makeValue(value), LayerProperty::Kind::Expression}; } } // namespace conversion diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 35577411eb..646bad898c 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -1,9 +1,10 @@ #pragma once +#include +#include +#include #include #include -#include -#include #include #include @@ -65,6 +66,14 @@ struct LayerTypeInfo { const enum class TileKind : uint8_t { Geometry, Raster, RasterDEM, NotRequired } tileKind; }; +struct LayerProperty { + enum class Kind : uint8_t { Undefined, Constant, Expression, Transition }; + LayerProperty(Value value_, Kind kind_) : value(std::move(value_)), kind(kind_) {} + LayerProperty() = default; + const Value value; + const Kind kind = Kind::Undefined; +}; + /** * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style * Specification. @@ -110,9 +119,12 @@ public: // 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 setPaintProperty(const std::string& name, + const conversion::Convertible& value) = 0; optional setVisibility(const conversion::Convertible& value); + virtual LayerProperty getPaintProperty(const std::string&) const = 0; + // Private implementation // TODO : We should not have public mutable data members. class Impl; diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 4a73ae4a0b..8caade26b0 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -24,6 +24,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue getDefaultBackgroundColor(); diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index f171805806..be4fe5cee4 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -24,6 +24,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue getDefaultCircleBlur(); diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 4ae59dfae3..9ae68c4fff 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -71,7 +71,7 @@ public: // Dynamic properties optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; - + LayerProperty getPaintProperty(const std::string&) const final; // Private implementation class Impl; diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index 2e89032ae7..63ccf369d4 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -24,6 +24,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue getDefaultFillExtrusionBase(); diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 0c4369de4c..acf60cec0d 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -24,6 +24,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue getDefaultFillAntialias(); diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 2023d8c21e..7eb7bb8edd 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -25,6 +25,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static ColorRampPropertyValue getDefaultHeatmapColor(); diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index f6b04a0062..7c8f6fa573 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -24,6 +24,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue getDefaultHillshadeAccentColor(); diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 638db5fe4b..f678adeda7 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -40,6 +40,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + <% if (layoutProperties.length) { -%> // Layout properties diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 8f1d51295c..a1c69e9475 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -27,6 +27,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Layout properties static PropertyValue getDefaultLineCap(); diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index ba2ea45428..e516e1a0fc 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -24,6 +24,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue getDefaultRasterBrightnessMax(); diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index b60e991f49..578d7d1701 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -26,6 +26,8 @@ public: optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Layout properties static PropertyValue getDefaultIconAllowOverlap(); -- cgit v1.2.1