diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-09-24 23:06:05 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-09-26 11:57:39 +0300 |
commit | c2dc873cf9c026e964d1d73a2c8301d21509da6e (patch) | |
tree | 02080365402a7f704e562a111c9cc2675423ab16 /include | |
parent | 2b834001cca8c2b0552c106dd404da1b238f043b (diff) | |
download | qtlocation-mapboxgl-c2dc873cf9c026e964d1d73a2c8301d21509da6e.tar.gz |
[core] Introduce Layer::getPaintProperty() generic getter
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/style/conversion_impl.hpp | 35 | ||||
-rw-r--r-- | include/mbgl/style/layer.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/layers/background_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/circle_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/custom_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/fill_extrusion_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/fill_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/heatmap_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/hillshade_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/layer.hpp.ejs | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/line_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/raster_layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layers/symbol_layer.hpp | 2 |
13 files changed, 67 insertions, 8 deletions
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 <mbgl/style/color_ramp_property_value.hpp> #include <mbgl/style/conversion.hpp> +#include <mbgl/style/layer.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/style/transition_options.hpp> #include <mbgl/util/feature.hpp> #include <mbgl/util/geojson.hpp> #include <mbgl/util/optional.hpp> @@ -10,6 +12,7 @@ #include <mapbox/value.hpp> #include <array> +#include <chrono> #include <string> #include <type_traits> @@ -314,6 +317,18 @@ struct ValueFactory<ColorRampPropertyValue> { }; template <> +struct ValueFactory<TransitionOptions> { + static Value make(const TransitionOptions& value) { + return mapbox::base::ValueArray{ + {std::chrono::duration_cast<std::chrono::milliseconds>(value.duration.value_or(mbgl::Duration::zero())) + .count(), + std::chrono::duration_cast<std::chrono::milliseconds>(value.delay.value_or(mbgl::Duration::zero())) + .count(), + value.enablePlacementTransitions}}; + } +}; + +template <> struct ValueFactory<Color> { static Value make(const Color& color) { return color.toObject(); } }; @@ -334,10 +349,22 @@ Value makeValue(T&& arg) { } template <typename T> -Value makeValue(const PropertyValue<T>& value) { - return value.match([](const Undefined&) -> Value { return {}; }, - [](const T& t) -> Value { return makeValue(t); }, - [](const PropertyExpression<T>& fn) { return fn.getExpression().serialize(); }); +LayerProperty makeLayerProperty(const PropertyValue<T>& value) { + return value.match([](const Undefined&) -> LayerProperty { return {}; }, + [](const T& t) -> LayerProperty { + return {makeValue(t), LayerProperty::Kind::Constant}; + }, + [](const PropertyExpression<T>& 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 <mbgl/style/conversion.hpp> +#include <mbgl/style/types.hpp> +#include <mbgl/util/feature.hpp> #include <mbgl/util/immutable.hpp> #include <mbgl/util/optional.hpp> -#include <mbgl/style/types.hpp> -#include <mbgl/style/conversion.hpp> #include <mapbox/weak.hpp> #include <mapbox/type_wrapper.hpp> @@ -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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) = 0; - virtual optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) = 0; + virtual optional<conversion::Error> setPaintProperty(const std::string& name, + const conversion::Convertible& value) = 0; optional<conversion::Error> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue<Color> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue<bool> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue<Color> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Layout properties static PropertyValue<LineCapType> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> 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<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + LayerProperty getPaintProperty(const std::string& name) const final; + // Layout properties static PropertyValue<bool> getDefaultIconAllowOverlap(); |