summaryrefslogtreecommitdiff
path: root/include/mbgl/style/conversion_impl.hpp
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-09-24 23:06:05 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-09-26 11:57:39 +0300
commitc2dc873cf9c026e964d1d73a2c8301d21509da6e (patch)
tree02080365402a7f704e562a111c9cc2675423ab16 /include/mbgl/style/conversion_impl.hpp
parent2b834001cca8c2b0552c106dd404da1b238f043b (diff)
downloadqtlocation-mapboxgl-c2dc873cf9c026e964d1d73a2c8301d21509da6e.tar.gz
[core] Introduce Layer::getPaintProperty() generic getter
Diffstat (limited to 'include/mbgl/style/conversion_impl.hpp')
-rw-r--r--include/mbgl/style/conversion_impl.hpp35
1 files changed, 31 insertions, 4 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