diff options
author | zmiao <zmiao.jamie@gmail.com> | 2019-07-22 18:27:36 +0300 |
---|---|---|
committer | zmiao <zmiao.jamie@gmail.com> | 2019-07-22 18:27:36 +0300 |
commit | 570b871b910aae375ce202398f205c6cda863f24 (patch) | |
tree | 19a26845e1a30c0ca3896334ec269b5737b3f508 /src/mbgl/style/expression | |
parent | 8cb116a73b88436d7ba56df084fb9a99d8a5ea67 (diff) | |
download | qtlocation-mapboxgl-570b871b910aae375ce202398f205c6cda863f24.tar.gz |
implement simple clusterOption exression
Diffstat (limited to 'src/mbgl/style/expression')
-rw-r--r-- | src/mbgl/style/expression/compound_expression.cpp | 13 | ||||
-rw-r--r-- | src/mbgl/style/expression/expression.cpp | 17 | ||||
-rw-r--r-- | src/mbgl/style/expression/parsing_context.cpp | 3 |
3 files changed, 26 insertions, 7 deletions
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp index cc1d58025b..6ca6eec850 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -368,6 +368,18 @@ const auto& lineProgressCompoundExpression() { return signature; } +const auto& accumulatedCompoundExpression() { + static auto signature = detail::makeSignature("accumulated", [](const EvaluationContext& params) -> Result<double> { + if (!params.accumulated) { + return EvaluationError { + "The 'accumulated' expression is unavailable in the current evaluation context." + }; + } + return *(params.accumulated); + }); + return signature; +} + const auto& hasContextCompoundExpression() { static auto signature = detail::makeSignature("has", [](const EvaluationContext& params, const std::string& key) -> Result<bool> { if (!params.feature) { @@ -870,6 +882,7 @@ MAPBOX_ETERNAL_CONSTEXPR const auto compoundExpressionRegistry = mapbox::eternal { "zoom", zoomCompoundExpression }, { "heatmap-density", heatmapDensityCompoundExpression }, { "line-progress", lineProgressCompoundExpression }, + { "accumulated", accumulatedCompoundExpression}, { "has", hasContextCompoundExpression }, { "has", hasObjectCompoundExpression }, { "get", getContextCompoundExpression }, diff --git a/src/mbgl/style/expression/expression.cpp b/src/mbgl/style/expression/expression.cpp index 1e5b1581d2..e826cf6ec0 100644 --- a/src/mbgl/style/expression/expression.cpp +++ b/src/mbgl/style/expression/expression.cpp @@ -5,13 +5,13 @@ namespace mbgl { namespace style { namespace expression { - + class GeoJSONFeature : public GeometryTileFeature { public: const Feature& feature; - - GeoJSONFeature(const Feature& feature_) : feature(feature_) {} - + + GeoJSONFeature( const Feature& feature_) : feature(feature_) {} + FeatureType getType() const override { return apply_visitor(ToFeatureType(), feature.geometry); } @@ -26,13 +26,18 @@ public: return optional<mbgl::Value>(); } }; - - + + EvaluationResult Expression::evaluate(optional<float> zoom, const Feature& feature, optional<double> colorRampParameter) const { GeoJSONFeature f(feature); return this->evaluate(EvaluationContext(zoom, &f, colorRampParameter)); } +EvaluationResult Expression::evaluate(const Feature& feature) const{ + GeoJSONFeature f(feature); + return this->evaluate(EvaluationContext(&f)); +} + } // namespace expression } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/expression/parsing_context.cpp b/src/mbgl/style/expression/parsing_context.cpp index a7c04f563d..6ce3a9bfaa 100644 --- a/src/mbgl/style/expression/parsing_context.cpp +++ b/src/mbgl/style/expression/parsing_context.cpp @@ -73,7 +73,8 @@ bool isConstant(const Expression& expression) { return isFeatureConstant(expression) && isGlobalPropertyConstant(expression, std::array<std::string, 2>{{"zoom", "heatmap-density"}}) && - isGlobalPropertyConstant(expression, std::array<std::string, 2>{{"zoom", "line-progress"}}); + isGlobalPropertyConstant(expression, std::array<std::string, 2>{{"zoom", "line-progress"}}) && + isGlobalPropertyConstant(expression, std::array<std::string, 2>{{"zoom", "accumulated"}}); } using namespace mbgl::style::conversion; |