From 75d18e32fce61f4c20cc2fe78d4cdf5eb357ccca Mon Sep 17 00:00:00 2001 From: Juha Alanen Date: Wed, 21 Aug 2019 16:21:46 +0300 Subject: [PATCH] [core] Add feature state support to expression --- include/mbgl/style/expression/expression.hpp | 9 +++++++++ include/mbgl/style/property_expression.hpp | 4 ++++ .../possibly_evaluated_property_value.hpp | 10 ++++++++++ src/mbgl/style/properties.hpp | 17 +++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index ad5774867..994254fed 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -34,6 +34,9 @@ public: EvaluationContext(optional accumulated_, GeometryTileFeature const * feature_) : accumulated(std::move(accumulated_)), feature(feature_) {} + EvaluationContext(float zoom_, GeometryTileFeature const * feature_, const FeatureState* state_) : + zoom(zoom_), feature(feature_), featureState(state_) + {} EvaluationContext(optional zoom_, GeometryTileFeature const * feature_, optional colorRampParameter_) : zoom(std::move(zoom_)), feature(feature_), colorRampParameter(std::move(colorRampParameter_)) {} @@ -43,12 +46,18 @@ public: return *this; }; + EvaluationContext& withFeatureState(const FeatureState* featureState_) noexcept { + featureState = featureState_; + return *this; + }; + optional zoom; optional accumulated; GeometryTileFeature const * feature = nullptr; optional colorRampParameter; // Contains formatted section object, std::unordered_map. const Value* formattedSection = nullptr; + const FeatureState* featureState = nullptr; }; template diff --git a/include/mbgl/style/property_expression.hpp b/include/mbgl/style/property_expression.hpp index 32983e238..f68285fb1 100644 --- a/include/mbgl/style/property_expression.hpp +++ b/include/mbgl/style/property_expression.hpp @@ -61,6 +61,10 @@ public: return evaluate(expression::EvaluationContext(zoom, &feature), finalDefaultValue); } + T evaluate(float zoom, const GeometryTileFeature& feature, const FeatureState& state, T finalDefaultValue) const { + return evaluate(expression::EvaluationContext(zoom, &feature, &state), finalDefaultValue); + } + std::vector> possibleOutputs() const { return expression::fromExpressionValues(expression->possibleOutputs()); } diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp index 625235011..2e47e6c85 100644 --- a/src/mbgl/renderer/possibly_evaluated_property_value.hpp +++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp @@ -49,6 +49,16 @@ public: } ); } + + template + T evaluate(const Feature& feature, float zoom, const FeatureState& featureState, T defaultValue) const { + return this->match( + [&] (const T& constant_) { return constant_; }, + [&] (const style::PropertyExpression& expression) { + return expression.evaluate(zoom, feature, featureState, defaultValue); + } + ); + } }; template diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp index 9d66f850d..b07456a96 100644 --- a/src/mbgl/style/properties.hpp +++ b/src/mbgl/style/properties.hpp @@ -180,11 +180,28 @@ public: }); } + template + static T evaluate(float z, const GeometryTileFeature& feature, const FeatureState& state, + const PossiblyEvaluatedPropertyValue& v, const T& defaultValue) { + return v.match( + [&] (const T& t) { + return t; + }, + [&] (const PropertyExpression& t) { + return t.evaluate(z, feature, state, defaultValue); + }); + } + template auto evaluate(float z, const GeometryTileFeature& feature) const { return evaluate(z, feature, this->template get

(), P::defaultValue()); } + template + auto evaluate(float z, const GeometryTileFeature& feature, const FeatureState& state) const { + return evaluate(z, feature, state, this->template get

(), P::defaultValue()); + } + Evaluated evaluate(float z, const GeometryTileFeature& feature) const { return Evaluated { evaluate(z, feature)...