diff options
Diffstat (limited to 'include/mbgl/style')
25 files changed, 270 insertions, 8 deletions
diff --git a/include/mbgl/style/conversion/custom_geometry_source_options.hpp b/include/mbgl/style/conversion/custom_geometry_source_options.hpp index 73b141e799..dedecd1aa4 100644 --- a/include/mbgl/style/conversion/custom_geometry_source_options.hpp +++ b/include/mbgl/style/conversion/custom_geometry_source_options.hpp @@ -54,6 +54,26 @@ struct Converter<CustomGeometrySource::Options> { } } + const auto wrapValue = objectMember(value, "wrap"); + if (wrapValue) { + if (toBool(*wrapValue)) { + options.tileOptions.wrap = static_cast<bool>(*toBool(*wrapValue)); + } else { + error = { "CustomGeometrySource TileOptions wrap value must be a boolean" }; + return {}; + } + } + + const auto clipValue = objectMember(value, "clip"); + if (clipValue) { + if (toBool(*clipValue)) { + options.tileOptions.clip = static_cast<double>(*toBool(*clipValue)); + } else { + error = { "CustomGeometrySource TileOptiosn clip value must be a boolean" }; + return {}; + } + } + return { options }; } diff --git a/include/mbgl/style/conversion/heatmap_color_property_value.hpp b/include/mbgl/style/conversion/heatmap_color_property_value.hpp new file mode 100644 index 0000000000..e3689c524c --- /dev/null +++ b/include/mbgl/style/conversion/heatmap_color_property_value.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include <mbgl/style/heatmap_color_property_value.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/constant.hpp> +#include <mbgl/style/conversion/function.hpp> +#include <mbgl/style/conversion/expression.hpp> +#include <mbgl/style/expression/value.hpp> +#include <mbgl/style/expression/is_constant.hpp> +#include <mbgl/style/expression/is_expression.hpp> +#include <mbgl/style/expression/find_zoom_curve.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter<HeatmapColorPropertyValue> { + optional<HeatmapColorPropertyValue> operator()(const Convertible& value, Error& error) const { + if (isUndefined(value)) { + return HeatmapColorPropertyValue(); + } else if (isExpression(value)) { + optional<std::unique_ptr<Expression>> expression = convert<std::unique_ptr<Expression>>(value, error, expression::type::Color); + if (!expression) { + return {}; + } + assert(*expression); + if (!isFeatureConstant(**expression)) { + error = { "property expressions not supported" }; + return {}; + } + if (!isZoomConstant(**expression)) { + error = { "zoom expressions not supported" }; + return {}; + } + return {HeatmapColorPropertyValue(std::move(*expression))}; + } else { + error = { "heatmap-color must be an expression" }; + return {}; + } + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/expression/array_assertion.hpp b/include/mbgl/style/expression/array_assertion.hpp index 7f36f8aac2..af153611ff 100644 --- a/include/mbgl/style/expression/array_assertion.hpp +++ b/include/mbgl/style/expression/array_assertion.hpp @@ -33,6 +33,9 @@ public: std::vector<optional<Value>> possibleOutputs() const override { return input->possibleOutputs(); } + + mbgl::Value serialize() const override; + std::string getOperator() const override { return "array"; } private: std::unique_ptr<Expression> input; diff --git a/include/mbgl/style/expression/assertion.hpp b/include/mbgl/style/expression/assertion.hpp index 43ea73f2ba..d1e919b10f 100644 --- a/include/mbgl/style/expression/assertion.hpp +++ b/include/mbgl/style/expression/assertion.hpp @@ -26,6 +26,8 @@ public: bool operator==(const Expression& e) const override; std::vector<optional<Value>> possibleOutputs() const override; + + std::string getOperator() const override; private: std::vector<std::unique_ptr<Expression>> inputs; diff --git a/include/mbgl/style/expression/at.hpp b/include/mbgl/style/expression/at.hpp index 27fccc761f..1e6f1c7dd2 100644 --- a/include/mbgl/style/expression/at.hpp +++ b/include/mbgl/style/expression/at.hpp @@ -31,6 +31,8 @@ public: std::vector<optional<Value>> possibleOutputs() const override { return { nullopt }; } + + std::string getOperator() const override { return "at"; } private: std::unique_ptr<Expression> index; diff --git a/include/mbgl/style/expression/boolean_operator.hpp b/include/mbgl/style/expression/boolean_operator.hpp index 115a096665..6d0f85756a 100644 --- a/include/mbgl/style/expression/boolean_operator.hpp +++ b/include/mbgl/style/expression/boolean_operator.hpp @@ -23,6 +23,7 @@ public: bool operator==(const Expression& e) const override; std::vector<optional<Value>> possibleOutputs() const override; + std::string getOperator() const override { return "any"; } private: std::vector<std::unique_ptr<Expression>> inputs; }; @@ -41,6 +42,7 @@ public: bool operator==(const Expression& e) const override; std::vector<optional<Value>> possibleOutputs() const override; + std::string getOperator() const override { return "all"; } private: std::vector<std::unique_ptr<Expression>> inputs; }; diff --git a/include/mbgl/style/expression/case.hpp b/include/mbgl/style/expression/case.hpp index e61a55fc6d..667ca53712 100644 --- a/include/mbgl/style/expression/case.hpp +++ b/include/mbgl/style/expression/case.hpp @@ -28,6 +28,7 @@ public: std::vector<optional<Value>> possibleOutputs() const override; + std::string getOperator() const override { return "case"; } private: std::vector<Branch> branches; std::unique_ptr<Expression> otherwise; diff --git a/include/mbgl/style/expression/coalesce.hpp b/include/mbgl/style/expression/coalesce.hpp index 52d9498cbd..a858bef695 100644 --- a/include/mbgl/style/expression/coalesce.hpp +++ b/include/mbgl/style/expression/coalesce.hpp @@ -38,6 +38,7 @@ public: return args.at(i).get(); } + std::string getOperator() const override { return "coalesce"; } private: Args args; }; diff --git a/include/mbgl/style/expression/coercion.hpp b/include/mbgl/style/expression/coercion.hpp index 40d2490186..d83bd6dfa7 100644 --- a/include/mbgl/style/expression/coercion.hpp +++ b/include/mbgl/style/expression/coercion.hpp @@ -28,6 +28,7 @@ public: std::vector<optional<Value>> possibleOutputs() const override; + std::string getOperator() const override; private: EvaluationResult (*coerceSingleValue) (const Value& v); std::vector<std::unique_ptr<Expression>> inputs; diff --git a/include/mbgl/style/expression/compound_expression.hpp b/include/mbgl/style/expression/compound_expression.hpp index 8b74027578..6baaae862f 100644 --- a/include/mbgl/style/expression/compound_expression.hpp +++ b/include/mbgl/style/expression/compound_expression.hpp @@ -40,14 +40,16 @@ namespace detail { // each CompoundExpression definition's type::Type data from the type of its // "evaluate" function. struct SignatureBase { - SignatureBase(type::Type result_, variant<std::vector<type::Type>, VarargsType> params_) : + SignatureBase(type::Type result_, variant<std::vector<type::Type>, VarargsType> params_, std::string name_) : result(std::move(result_)), - params(std::move(params_)) + params(std::move(params_)), + name(std::move(name_)) {} virtual ~SignatureBase() = default; - virtual std::unique_ptr<Expression> makeExpression(const std::string& name, std::vector<std::unique_ptr<Expression>>) const = 0; + virtual std::unique_ptr<Expression> makeExpression(std::vector<std::unique_ptr<Expression>>) const = 0; type::Type result; variant<std::vector<type::Type>, VarargsType> params; + std::string name; }; } // namespace detail @@ -111,6 +113,10 @@ public: } return false; } + + std::string getOperator() const override { + return signature.name; + } private: Signature signature; @@ -128,8 +134,7 @@ struct CompoundExpressionRegistry { ParseResult parseCompoundExpression(const std::string name, const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); -ParseResult createCompoundExpression(const std::string& name, - const CompoundExpressionRegistry::Definition& definition, +ParseResult createCompoundExpression(const CompoundExpressionRegistry::Definition& definition, std::vector<std::unique_ptr<Expression>> args, ParsingContext& ctx); diff --git a/include/mbgl/style/expression/equals.hpp b/include/mbgl/style/expression/equals.hpp index 80550bd59d..54df890a68 100644 --- a/include/mbgl/style/expression/equals.hpp +++ b/include/mbgl/style/expression/equals.hpp @@ -21,6 +21,7 @@ public: EvaluationResult evaluate(const EvaluationContext&) const override; std::vector<optional<Value>> possibleOutputs() const override; + std::string getOperator() const override { return negate ? "!=" : "=="; } private: std::unique_ptr<Expression> lhs; std::unique_ptr<Expression> rhs; diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index cf9fa0cb21..c41ac0b5f1 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -135,6 +135,17 @@ public: * complete set of outputs is statically undecidable. */ virtual std::vector<optional<Value>> possibleOutputs() const = 0; + + virtual mbgl::Value serialize() const { + std::vector<mbgl::Value> serialized; + serialized.emplace_back(getOperator()); + eachChild([&](const Expression &child) { + serialized.emplace_back(child.serialize()); + }); + return serialized; + }; + + virtual std::string getOperator() const = 0; protected: template <typename T> diff --git a/include/mbgl/style/expression/interpolate.hpp b/include/mbgl/style/expression/interpolate.hpp index dbed74b4cd..cc744ac7b7 100644 --- a/include/mbgl/style/expression/interpolate.hpp +++ b/include/mbgl/style/expression/interpolate.hpp @@ -185,6 +185,9 @@ public: } return false; } + + mbgl::Value serialize() const override; + std::string getOperator() const override { return "interpolate"; } }; } // namespace expression diff --git a/include/mbgl/style/expression/let.hpp b/include/mbgl/style/expression/let.hpp index 6829ded9b8..75d2adda62 100644 --- a/include/mbgl/style/expression/let.hpp +++ b/include/mbgl/style/expression/let.hpp @@ -39,6 +39,8 @@ public: return result.get(); } + mbgl::Value serialize() const override; + std::string getOperator() const override { return "let"; } private: Bindings bindings; std::unique_ptr<Expression> result; @@ -66,6 +68,8 @@ public: std::vector<optional<Value>> possibleOutputs() const override; + mbgl::Value serialize() const override; + std::string getOperator() const override { return "var"; } private: std::string name; std::shared_ptr<Expression> value; diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp index 82983d78af..d854b419f4 100644 --- a/include/mbgl/style/expression/literal.hpp +++ b/include/mbgl/style/expression/literal.hpp @@ -12,8 +12,16 @@ namespace expression { class Literal : public Expression { public: - Literal(Value value_) : Expression(typeOf(value_)), value(value_) {} - Literal(type::Array type_, std::vector<Value> value_) : Expression(type_), value(value_) {} + Literal(Value value_) + : Expression(typeOf(value_)) + , value(value_) + {} + + Literal(type::Array type_, std::vector<Value> value_) + : Expression(type_) + , value(value_) + {} + EvaluationResult evaluate(const EvaluationContext&) const override { return value; } @@ -33,6 +41,8 @@ public: return {{ value }}; } + mbgl::Value serialize() const override; + std::string getOperator() const override { return "literal"; } private: Value value; }; diff --git a/include/mbgl/style/expression/match.hpp b/include/mbgl/style/expression/match.hpp index 682d784b0f..3775e38067 100644 --- a/include/mbgl/style/expression/match.hpp +++ b/include/mbgl/style/expression/match.hpp @@ -32,7 +32,9 @@ public: bool operator==(const Expression& e) const override; std::vector<optional<Value>> possibleOutputs() const override; - + + mbgl::Value serialize() const override; + std::string getOperator() const override { return "match"; } private: std::unique_ptr<Expression> input; Branches branches; diff --git a/include/mbgl/style/expression/step.hpp b/include/mbgl/style/expression/step.hpp index 6bf42e20f1..2f9524a53c 100644 --- a/include/mbgl/style/expression/step.hpp +++ b/include/mbgl/style/expression/step.hpp @@ -38,6 +38,8 @@ public: static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); + mbgl::Value serialize() const override; + std::string getOperator() const override { return "step"; } private: const std::unique_ptr<Expression> input; const std::map<double, std::unique_ptr<Expression>> stops; diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index be5be64752..7839ff2ca7 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -110,6 +110,7 @@ struct ValueConverter<float> { template<> struct ValueConverter<mbgl::Value> { static Value toExpressionValue(const mbgl::Value& value); + static mbgl::Value fromExpressionValue(const Value& value); }; template <typename T, std::size_t N> diff --git a/include/mbgl/style/function/convert.hpp b/include/mbgl/style/function/convert.hpp index 8e544d3ad5..401a81d52e 100644 --- a/include/mbgl/style/function/convert.hpp +++ b/include/mbgl/style/function/convert.hpp @@ -49,6 +49,7 @@ public: return {}; } + std::string getOperator() const override { return "error"; } private: std::string message; }; diff --git a/include/mbgl/style/heatmap_color_property_value.hpp b/include/mbgl/style/heatmap_color_property_value.hpp new file mode 100644 index 0000000000..130639c6e2 --- /dev/null +++ b/include/mbgl/style/heatmap_color_property_value.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include <mbgl/util/variant.hpp> +#include <mbgl/style/undefined.hpp> +#include <mbgl/style/function/camera_function.hpp> + +namespace mbgl { +namespace style { + +/* + * Special-case implementation of (a subset of) the PropertyValue<T> interface + * used for building the HeatmapColor paint property traits class. + */ +class HeatmapColorPropertyValue { +private: + std::shared_ptr<expression::Expression> value; + + friend bool operator==(const HeatmapColorPropertyValue& lhs, const HeatmapColorPropertyValue& rhs) { + return (lhs.isUndefined() && rhs.isUndefined()) || (lhs.value && rhs.value && *(lhs.value) == *(rhs.value)); + } + + friend bool operator!=(const HeatmapColorPropertyValue& lhs, const HeatmapColorPropertyValue& rhs) { + return !(lhs == rhs); + } + +public: + HeatmapColorPropertyValue() : value(nullptr) {} + HeatmapColorPropertyValue(std::shared_ptr<expression::Expression> value_) : value(std::move(value_)) {} + + bool isUndefined() const { return value.get() == nullptr; } + + // noop, needed for batch evaluation of paint property values to compile + template <typename Evaluator> + Color evaluate(const Evaluator&, TimePoint = {}) const { return {}; } + + Color evaluate(double heatmapDensity) const { + const auto result = value->evaluate(expression::EvaluationContext({}, nullptr, {heatmapDensity})); + return *expression::fromExpressionValue<Color>(*result); + } + + bool isDataDriven() const { return false; } + bool hasDataDrivenPropertyDifference(const HeatmapColorPropertyValue&) const { return false; } + + const expression::Expression& getExpression() const { return *value; } +}; + + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 8a5a4236b3..12494f5387 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -23,6 +23,7 @@ class HillshadeLayer; class BackgroundLayer; class CustomLayer; class FillExtrusionLayer; +class HeatmapLayer; class LayerObserver; /** @@ -93,6 +94,8 @@ public: return std::forward<V>(visitor)(*as<CustomLayer>()); case LayerType::FillExtrusion: return std::forward<V>(visitor)(*as<FillExtrusionLayer>()); + case LayerType::Heatmap: + return std::forward<V>(visitor)(*as<HeatmapLayer>()); } diff --git a/include/mbgl/style/layer_type.hpp b/include/mbgl/style/layer_type.hpp index 951757134b..0987ea4d0a 100644 --- a/include/mbgl/style/layer_type.hpp +++ b/include/mbgl/style/layer_type.hpp @@ -13,6 +13,7 @@ enum class LayerType { Background, Custom, FillExtrusion, + Heatmap, }; } // namespace style diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp new file mode 100644 index 0000000000..33d927ad38 --- /dev/null +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -0,0 +1,86 @@ +// This file is generated. Do not edit. + +#pragma once + +#include <mbgl/style/layer.hpp> +#include <mbgl/style/filter.hpp> +#include <mbgl/style/property_value.hpp> +#include <mbgl/style/data_driven_property_value.hpp> +#include <mbgl/style/heatmap_color_property_value.hpp> + +#include <mbgl/util/color.hpp> + +namespace mbgl { +namespace style { + +class TransitionOptions; + +class HeatmapLayer : public Layer { +public: + HeatmapLayer(const std::string& layerID, const std::string& sourceID); + ~HeatmapLayer() final; + + // Source + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + void setSourceLayer(const std::string& sourceLayer); + + void setFilter(const Filter&); + const Filter& getFilter() const; + + // Visibility + void setVisibility(VisibilityType) final; + + // Zoom range + void setMinZoom(float) final; + void setMaxZoom(float) final; + + // Paint properties + + static DataDrivenPropertyValue<float> getDefaultHeatmapRadius(); + DataDrivenPropertyValue<float> getHeatmapRadius() const; + void setHeatmapRadius(DataDrivenPropertyValue<float>); + void setHeatmapRadiusTransition(const TransitionOptions&); + TransitionOptions getHeatmapRadiusTransition() const; + + static DataDrivenPropertyValue<float> getDefaultHeatmapWeight(); + DataDrivenPropertyValue<float> getHeatmapWeight() const; + void setHeatmapWeight(DataDrivenPropertyValue<float>); + void setHeatmapWeightTransition(const TransitionOptions&); + TransitionOptions getHeatmapWeightTransition() const; + + static PropertyValue<float> getDefaultHeatmapIntensity(); + PropertyValue<float> getHeatmapIntensity() const; + void setHeatmapIntensity(PropertyValue<float>); + void setHeatmapIntensityTransition(const TransitionOptions&); + TransitionOptions getHeatmapIntensityTransition() const; + + static HeatmapColorPropertyValue getDefaultHeatmapColor(); + HeatmapColorPropertyValue getHeatmapColor() const; + void setHeatmapColor(HeatmapColorPropertyValue); + void setHeatmapColorTransition(const TransitionOptions&); + TransitionOptions getHeatmapColorTransition() const; + + static PropertyValue<float> getDefaultHeatmapOpacity(); + PropertyValue<float> getHeatmapOpacity() const; + void setHeatmapOpacity(PropertyValue<float>); + void setHeatmapOpacityTransition(const TransitionOptions&); + TransitionOptions getHeatmapOpacityTransition() const; + + // Private implementation + + class Impl; + const Impl& impl() const; + + Mutable<Impl> mutableImpl() const; + HeatmapLayer(Immutable<Impl>); + std::unique_ptr<Layer> cloneRef(const std::string& id) const final; +}; + +template <> +inline bool Layer::is<HeatmapLayer>() const { + return getType() == LayerType::Heatmap; +} + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 265dd57e1f..6d40405ccd 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -11,6 +11,9 @@ #include <mbgl/style/filter.hpp> #include <mbgl/style/property_value.hpp> #include <mbgl/style/data_driven_property_value.hpp> +<% if (type === 'heatmap') { -%> +#include <mbgl/style/heatmap_color_property_value.hpp> +<% } -%> #include <mbgl/util/color.hpp> diff --git a/include/mbgl/style/sources/custom_geometry_source.hpp b/include/mbgl/style/sources/custom_geometry_source.hpp index a0b990b44b..9daeeb3819 100644 --- a/include/mbgl/style/sources/custom_geometry_source.hpp +++ b/include/mbgl/style/sources/custom_geometry_source.hpp @@ -25,6 +25,8 @@ public: double tolerance = 0.375; uint16_t tileSize = util::tileSize; uint16_t buffer = 128; + bool clip = false; + bool wrap = false; }; struct Options { |