summaryrefslogtreecommitdiff
path: root/src/mbgl/style/conversion/color_ramp_property_value.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/conversion/color_ramp_property_value.cpp')
-rw-r--r--src/mbgl/style/conversion/color_ramp_property_value.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/color_ramp_property_value.cpp b/src/mbgl/style/conversion/color_ramp_property_value.cpp
new file mode 100644
index 0000000000..e792cf3fe4
--- /dev/null
+++ b/src/mbgl/style/conversion/color_ramp_property_value.cpp
@@ -0,0 +1,42 @@
+#include <mbgl/style/conversion/color_ramp_property_value.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/constant.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/parsing_context.hpp>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+optional<ColorRampPropertyValue> Converter<ColorRampPropertyValue>::operator()(const Convertible& value, Error& error, bool) const {
+ using namespace mbgl::style::expression;
+ if (isUndefined(value)) {
+ return ColorRampPropertyValue();
+ } else if (isExpression(value)) {
+ ParsingContext ctx(type::Color);
+ ParseResult expression = ctx.parseLayerPropertyExpression(value);
+ if (!expression) {
+ error.message = ctx.getCombinedErrors();
+ return nullopt;
+ }
+ assert(*expression);
+ if (!isFeatureConstant(**expression)) {
+ error.message = "data expressions not supported";
+ return nullopt;
+ }
+ if (!isZoomConstant(**expression)) {
+ error.message = "zoom expressions not supported";
+ return nullopt;
+ }
+ return ColorRampPropertyValue(std::move(*expression));
+ } else {
+ error.message = "color ramp must be an expression";
+ return nullopt;
+ }
+}
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl