1 #pragma once 2 3 #include <mbgl/style/color_ramp_property_value.hpp> 4 #include <mbgl/style/conversion.hpp> 5 #include <mbgl/style/conversion/constant.hpp> 6 #include <mbgl/style/expression/value.hpp> 7 #include <mbgl/style/expression/is_constant.hpp> 8 #include <mbgl/style/expression/is_expression.hpp> 9 #include <mbgl/style/expression/parsing_context.hpp> 10 11 namespace mbgl { 12 namespace style { 13 namespace conversion { 14 15 template <> 16 struct Converter<ColorRampPropertyValue> { operator ()mbgl::style::conversion::Converter17 optional<ColorRampPropertyValue> operator()(const Convertible& value, Error& error, bool /* convertTokens */ = false) const { 18 using namespace mbgl::style::expression; 19 if (isUndefined(value)) { 20 return ColorRampPropertyValue(); 21 } else if (isExpression(value)) { 22 ParsingContext ctx(type::Color); 23 ParseResult expression = ctx.parseLayerPropertyExpression(value); 24 if (!expression) { 25 error = { ctx.getCombinedErrors() }; 26 return {}; 27 } 28 assert(*expression); 29 if (!isFeatureConstant(**expression)) { 30 error = { "property expressions not supported" }; 31 return {}; 32 } 33 if (!isZoomConstant(**expression)) { 34 error = { "zoom expressions not supported" }; 35 return {}; 36 } 37 return {ColorRampPropertyValue(std::move(*expression))}; 38 } else { 39 error = { "color ramp must be an expression" }; 40 return {}; 41 } 42 } 43 }; 44 45 } // namespace conversion 46 } // namespace style 47 } // namespace mbgl 48