summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnand Thakker <github@anandthakker.net>2018-01-12 09:44:23 -0500
committerAnand Thakker <github@anandthakker.net>2018-01-12 12:01:23 -0500
commitb88b9743bc95951a4b574c1435c8d430a4456fa9 (patch)
treea319a65213ec4eb766b3c2aaced08bed25a00bbb /include
parent01e733136acb62ccefca32868ffabd0ba7176265 (diff)
downloadqtlocation-mapboxgl-b88b9743bc95951a4b574c1435c8d430a4456fa9.tar.gz
Add special-case HeatmapColor paint property traits class
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/style/conversion/heatmap_color_property_value.hpp46
-rw-r--r--include/mbgl/style/heatmap_color_property_value.hpp47
-rw-r--r--include/mbgl/style/layers/heatmap_layer.hpp7
-rw-r--r--include/mbgl/style/layers/layer.hpp.ejs3
4 files changed, 100 insertions, 3 deletions
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..72b17bc112
--- /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 {};
+ }
+ 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/heatmap_color_property_value.hpp b/include/mbgl/style/heatmap_color_property_value.hpp
new file mode 100644
index 0000000000..98640c2a41
--- /dev/null
+++ b/include/mbgl/style/heatmap_color_property_value.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <mbgl/util/variant.hpp>
+#include <mbgl/style/undefined.hpp>
+#include <mbgl/style/function/camera_function.hpp>
+#include <mbgl/renderer/property_evaluation_parameters.hpp>
+
+namespace mbgl {
+namespace style {
+
+class NoopPropertyEvaluator {
+public:
+ using ResultType = Color;
+ NoopPropertyEvaluator(const PropertyEvaluationParameters&, Color) {}
+};
+
+/*
+ * 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.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
+ Color evaluate(const NoopPropertyEvaluator&, TimePoint = {}) const { return {}; }
+ bool isDataDriven() const { return false; }
+ bool hasDataDrivenPropertyDifference(const HeatmapColorPropertyValue&) const { return false; }
+};
+
+
+} // namespace style
+} // namespace mbgl
diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp
index b9ce3b1539..77d25b4ee0 100644
--- a/include/mbgl/style/layers/heatmap_layer.hpp
+++ b/include/mbgl/style/layers/heatmap_layer.hpp
@@ -6,6 +6,7 @@
#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>
@@ -54,9 +55,9 @@ public:
void setHeatmapIntensityTransition(const TransitionOptions&);
TransitionOptions getHeatmapIntensityTransition() const;
- static PropertyValue<Color> getDefaultHeatmapColor();
- PropertyValue<Color> getHeatmapColor() const;
- void setHeatmapColor(PropertyValue<Color>);
+ static HeatmapColorPropertyValue getDefaultHeatmapColor();
+ HeatmapColorPropertyValue getHeatmapColor() const;
+ void setHeatmapColor(HeatmapColorPropertyValue);
void setHeatmapColorTransition(const TransitionOptions&);
TransitionOptions getHeatmapColorTransition() const;
diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs
index 4ee5545247..fafc0af790 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>