diff options
author | zmiao <miao.zhao@mapbox.com> | 2020-01-29 12:46:16 +0200 |
---|---|---|
committer | zmiao <miao.zhao@mapbox.com> | 2020-02-12 12:24:05 +0200 |
commit | 3e99c08ea610d791b21f1631308451687c464d98 (patch) | |
tree | c7f3e20ad9ddc161ab3378d37bde9aa31675da83 /include | |
parent | 4f18d5fa92df175ac30f856a9273a00349b56cc3 (diff) | |
download | qtlocation-mapboxgl-3e99c08ea610d791b21f1631308451687c464d98.tar.gz |
Enable parse within expression
Add geometry type checker
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/style/expression/expression.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/expression/within.hpp | 43 |
2 files changed, 56 insertions, 5 deletions
diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index 9893daa8c4..f19f64c1e7 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -1,11 +1,12 @@ #pragma once -#include <mbgl/util/optional.hpp> -#include <mbgl/util/variant.hpp> -#include <mbgl/util/color.hpp> +#include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/type.hpp> #include <mbgl/style/expression/value.hpp> -#include <mbgl/style/expression/parsing_context.hpp> +#include <mbgl/tile/tile_id.hpp> +#include <mbgl/util/color.hpp> +#include <mbgl/util/optional.hpp> +#include <mbgl/util/variant.hpp> #include <array> #include <vector> @@ -53,8 +54,14 @@ public: return *this; }; + EvaluationContext& withCanonicalTileID(const mbgl::CanonicalTileID& canonical_) noexcept { + canonical = canonical_; + return *this; + }; + optional<float> zoom; optional<mbgl::Value> accumulated; + optional<mbgl::CanonicalTileID> canonical; GeometryTileFeature const * feature = nullptr; optional<double> colorRampParameter; // Contains formatted section object, std::unordered_map<std::string, Value>. @@ -160,7 +167,8 @@ enum class Kind : int32_t { FormatExpression, FormatSectionOverride, NumberFormat, - ImageExpression + ImageExpression, + Within }; class Expression { diff --git a/include/mbgl/style/expression/within.hpp b/include/mbgl/style/expression/within.hpp new file mode 100644 index 0000000000..5e2b5e0671 --- /dev/null +++ b/include/mbgl/style/expression/within.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/expression/parsing_context.hpp> +#include <mbgl/util/geojson.hpp> + +#include <memory> + +namespace mbgl { +namespace style { +namespace expression { + +class Within : public Expression { +public: + Within(GeoJSON& geojson) : Expression(Kind::Within, type::Boolean), geoJSONSource(geojson) {} + + EvaluationResult evaluate(const EvaluationContext&) const override; + + static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); + + void eachChild(const std::function<void(const Expression&)>&) const override {} + + bool operator==(const Expression& e) const override { + if (e.getKind() == Kind::Within) { + auto rhs = static_cast<const Within*>(&e); + return geoJSONSource == rhs->geoJSONSource; + } + return false; + } + + std::vector<optional<Value>> possibleOutputs() const override { return {{false}}; } + + mbgl::Value serialize() const override; + std::string getOperator() const override { return "Within"; } + +private: + GeoJSON geoJSONSource; +}; + +} // namespace expression +} // namespace style +} // namespace mbgl |