summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuha Alanen <juha.alanen@mapbox.com>2019-08-21 16:21:46 +0300
committerJuha Alanen <19551460+jmalanen@users.noreply.github.com>2019-09-18 14:29:15 +0300
commit75d18e32fce61f4c20cc2fe78d4cdf5eb357ccca (patch)
treea75a88058a4f917ac2adaf1f5e381ca3aae98fcd
parente51fafd4ebab154472e8d00a8b16a374728f0863 (diff)
downloadqtlocation-mapboxgl-75d18e32fce61f4c20cc2fe78d4cdf5eb357ccca.tar.gz
[core] Add feature state support to expression
-rw-r--r--include/mbgl/style/expression/expression.hpp9
-rw-r--r--include/mbgl/style/property_expression.hpp4
-rw-r--r--src/mbgl/renderer/possibly_evaluated_property_value.hpp10
-rw-r--r--src/mbgl/style/properties.hpp17
4 files changed, 40 insertions, 0 deletions
diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp
index ad57748677..994254fed5 100644
--- a/include/mbgl/style/expression/expression.hpp
+++ b/include/mbgl/style/expression/expression.hpp
@@ -34,6 +34,9 @@ public:
EvaluationContext(optional<mbgl::Value> 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<float> zoom_, GeometryTileFeature const * feature_, optional<double> 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<float> zoom;
optional<mbgl::Value> accumulated;
GeometryTileFeature const * feature = nullptr;
optional<double> colorRampParameter;
// Contains formatted section object, std::unordered_map<std::string, Value>.
const Value* formattedSection = nullptr;
+ const FeatureState* featureState = nullptr;
};
template <typename T>
diff --git a/include/mbgl/style/property_expression.hpp b/include/mbgl/style/property_expression.hpp
index 32983e2380..f68285fb1b 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<optional<T>> possibleOutputs() const {
return expression::fromExpressionValues<T>(expression->possibleOutputs());
}
diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp
index 625235011c..2e47e6c854 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 <class Feature>
+ T evaluate(const Feature& feature, float zoom, const FeatureState& featureState, T defaultValue) const {
+ return this->match(
+ [&] (const T& constant_) { return constant_; },
+ [&] (const style::PropertyExpression<T>& expression) {
+ return expression.evaluate(zoom, feature, featureState, defaultValue);
+ }
+ );
+ }
};
template <class T>
diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp
index 9d66f850de..b07456a96d 100644
--- a/src/mbgl/style/properties.hpp
+++ b/src/mbgl/style/properties.hpp
@@ -180,11 +180,28 @@ public:
});
}
+ template <class T>
+ static T evaluate(float z, const GeometryTileFeature& feature, const FeatureState& state,
+ const PossiblyEvaluatedPropertyValue<T>& v, const T& defaultValue) {
+ return v.match(
+ [&] (const T& t) {
+ return t;
+ },
+ [&] (const PropertyExpression<T>& t) {
+ return t.evaluate(z, feature, state, defaultValue);
+ });
+ }
+
template <class P>
auto evaluate(float z, const GeometryTileFeature& feature) const {
return evaluate(z, feature, this->template get<P>(), P::defaultValue());
}
+ template <class P>
+ auto evaluate(float z, const GeometryTileFeature& feature, const FeatureState& state) const {
+ return evaluate(z, feature, state, this->template get<P>(), P::defaultValue());
+ }
+
Evaluated evaluate(float z, const GeometryTileFeature& feature) const {
return Evaluated {
evaluate<Ps>(z, feature)...