summaryrefslogtreecommitdiff
path: root/include/mbgl/style/conversion/property_value.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/style/conversion/property_value.hpp')
-rw-r--r--include/mbgl/style/conversion/property_value.hpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp
index 4d13144dd7..fa6752867b 100644
--- a/include/mbgl/style/conversion/property_value.hpp
+++ b/include/mbgl/style/conversion/property_value.hpp
@@ -16,13 +16,9 @@ namespace conversion {
template <class T>
struct Converter<PropertyValue<T>> {
- optional<PropertyValue<T>> operator()(const Convertible& value, Error& error, bool convertTokens = false) const {
+ optional<PropertyValue<T>> operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const {
using namespace mbgl::style::expression;
- // Only icon-image and text-field support tokens, and they are both data-driven.
- assert(!convertTokens);
- (void)convertTokens;
-
if (isUndefined(value)) {
return PropertyValue<T>();
}
@@ -38,21 +34,21 @@ struct Converter<PropertyValue<T>> {
}
expression = PropertyExpression<T>(std::move(*parsed));
} else if (isObject(value)) {
- expression = convertFunctionToExpression<T>(value, error, false);
+ expression = convertFunctionToExpression<T>(value, error, convertTokens);
} else {
optional<T> constant = convert<T>(value, error);
if (!constant) {
return nullopt;
}
- return { *constant };
+ return convertTokens ? maybeConvertTokens(*constant) : PropertyValue<T>(*constant);
}
if (!expression) {
return nullopt;
- } else if (!(*expression).isFeatureConstant()) {
+ } else if (!allowDataExpressions && !(*expression).isFeatureConstant()) {
error.message = "data expressions not supported";
return nullopt;
- } else if (!(*expression).isZoomConstant()) {
+ } else if (!(*expression).isFeatureConstant() || !(*expression).isZoomConstant()) {
return { std::move(*expression) };
} else if ((*expression).getExpression().getKind() == Kind::Literal) {
optional<T> constant = fromExpressionValue<T>(
@@ -67,6 +63,17 @@ struct Converter<PropertyValue<T>> {
return nullopt;
}
}
+
+ template <class S>
+ PropertyValue<T> maybeConvertTokens(const S& t) const {
+ return PropertyValue<T>(t);
+ };
+
+ PropertyValue<T> maybeConvertTokens(const std::string& t) const {
+ return hasTokens(t)
+ ? PropertyValue<T>(PropertyExpression<T>(convertTokenStringToExpression(t)))
+ : PropertyValue<T>(t);
+ }
};
} // namespace conversion