diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp index 8880d28fb..5f4395f35 100644 --- a/include/mbgl/style/conversion/data_driven_property_value.hpp +++ b/include/mbgl/style/conversion/data_driven_property_value.hpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include @@ -32,12 +34,25 @@ struct Converter> { return {}; } - if (isFeatureConstant(**expression)) { + bool featureConstant = isFeatureConstant(**expression); + bool zoomConstant = isZoomConstant(**expression); + + if (featureConstant && !zoomConstant) { return DataDrivenPropertyValue(CameraFunction(std::move(*expression))); - } else if (isZoomConstant(**expression)) { + } else if (!featureConstant && zoomConstant) { return DataDrivenPropertyValue(SourceFunction(std::move(*expression))); - } else { + } else if (!featureConstant && !zoomConstant) { return DataDrivenPropertyValue(CompositeFunction(std::move(*expression))); + } else { + // If an expression is neither zoom- nor feature-dependent, it + // should have been reduced to a Literal when it was parsed. + auto literal = dynamic_cast(expression->get()); + assert(literal); + optional constant = fromExpressionValue(literal->getValue()); + if (!constant) { + return {}; + } + return DataDrivenPropertyValue(*constant); } } else if (!isObject(value)) { optional constant = convert(value, error); diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp index 82983d78a..a5c5fa109 100644 --- a/include/mbgl/style/expression/literal.hpp +++ b/include/mbgl/style/expression/literal.hpp @@ -32,6 +32,10 @@ public: std::vector> possibleOutputs() const override { return {{ value }}; } + + Value getValue() const { + return value; + } private: Value value;