diff options
author | Molly Lloyd <molly@mapbox.com> | 2018-06-14 14:35:39 -0700 |
---|---|---|
committer | Molly Lloyd <mollymerp@users.noreply.github.com> | 2018-08-31 13:08:47 -0700 |
commit | 4a5dc37245d23805d13865f5ef9c5f26e539a9ca (patch) | |
tree | de77bfeff6f7afbe02210c9189bf72da59293083 /src/mbgl/renderer/possibly_evaluated_property_value.hpp | |
parent | ec62e321531b1a836074056e86de8e20018280fb (diff) | |
download | qtlocation-mapboxgl-4a5dc37245d23805d13865f5ef9c5f26e539a9ca.tar.gz |
[core] Implement CrossFadedDataDrivenProperty to add support for feature expressions in `*-pattern` properties
Diffstat (limited to 'src/mbgl/renderer/possibly_evaluated_property_value.hpp')
-rw-r--r-- | src/mbgl/renderer/possibly_evaluated_property_value.hpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp index f2d265f2f7..353df2ab90 100644 --- a/src/mbgl/renderer/possibly_evaluated_property_value.hpp +++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/style/property_expression.hpp> +#include <mbgl/renderer/cross_faded_property_evaluator.hpp> #include <mbgl/util/interpolate.hpp> #include <mbgl/util/variant.hpp> @@ -57,6 +58,61 @@ public: bool useIntegerZoom; }; +template <class T> +class PossiblyEvaluatedPropertyValue<Faded<T>> { +private: + using Value = variant< + Faded<T>, + style::PropertyExpression<T>>; + + Value value; + +public: + PossiblyEvaluatedPropertyValue() = default; + PossiblyEvaluatedPropertyValue(Value v, bool useIntegerZoom_ = false) + : value(std::move(v)), + useIntegerZoom(useIntegerZoom_) {} + + bool isConstant() const { + return value.template is<Faded<T>>(); + } + + optional<Faded<T>> constant() const { + return value.match( + [&] (const Faded<T>& t) { return optional<Faded<T>>(t); }, + [&] (const auto&) { return optional<Faded<T>>(); }); + } + + Faded<T> constantOr(const Faded<T>& t) const { + return constant().value_or(t); + } + + template <class... Ts> + auto match(Ts&&... ts) const { + return value.match(std::forward<Ts>(ts)...); + } + + template <class Feature> + Faded<T> evaluate(const Feature& feature, float zoom, T defaultValue) const { + return this->match( + [&] (const Faded<T>& constant_) { return constant_; }, + [&] (const style::PropertyExpression<T>& expression) { + if (!expression.isZoomConstant()) { + const T min = expression.evaluate(floor(zoom), feature, defaultValue); + const T max = expression.evaluate(floor(zoom) + 1, feature, defaultValue); + return Faded<T> {min, max}; + } else { + const T evaluated = expression.evaluate(feature, defaultValue); + return Faded<T> {evaluated, evaluated}; + } + } + ); + } + + bool useIntegerZoom; +}; + + namespace util { template <typename T> |