diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-17 12:21:50 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-20 12:35:00 -0700 |
commit | 2c5d0e74a1ef6743a23dbd346b79958e4b2f8614 (patch) | |
tree | 5dd56c0079294b6cebf2d26970bcb12852add27e /platform/darwin/src/MGLSymbolStyleLayer.mm | |
parent | af89318b1d3bef15e92e591887c9d65b10be54ce (diff) | |
download | qtlocation-mapboxgl-2c5d0e74a1ef6743a23dbd346b79958e4b2f8614.tar.gz |
[ios, macos] Convert token strings to expressions on input
Removes mgl_expressionByReplacingTokensWithKeyPaths and associated code. Converting on output is no longer necessary: from the prior commit, core converts token strings to expressions at parse time; all that's necessary is to ensure that the runtime styling API does so as well.
Diffstat (limited to 'platform/darwin/src/MGLSymbolStyleLayer.mm')
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.mm | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 7ec7816c3b..f5522b800d 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -222,6 +222,14 @@ namespace mbgl { - (void)setIconImageName:(NSExpression *)iconImageName { MGLAssertStyleLayerIsValid(); + if (iconImageName && iconImageName.expressionType == NSConstantValueExpressionType) { + std::string string = ((NSString *)iconImageName.constantValue).UTF8String; + if (mbgl::style::conversion::hasTokens(string)) { + self.rawLayer->setIconImage(mbgl::style::DataDrivenPropertyValue<std::string>( + mbgl::style::conversion::convertTokenStringToExpression(string))); + return; + } + } auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<std::string>>(iconImageName); self.rawLayer->setIconImage(mbglValue); } @@ -233,8 +241,7 @@ namespace mbgl { if (propertyValue.isUndefined()) { propertyValue = self.rawLayer->getDefaultIconImage(); } - NSExpression *expression = MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); - return expression.mgl_expressionByReplacingTokensWithKeyPaths; + return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); } - (void)setIconImage:(NSExpression *)iconImage { @@ -568,6 +575,14 @@ namespace mbgl { - (void)setText:(NSExpression *)text { MGLAssertStyleLayerIsValid(); + if (text && text.expressionType == NSConstantValueExpressionType) { + std::string string = ((NSString *)text.constantValue).UTF8String; + if (mbgl::style::conversion::hasTokens(string)) { + self.rawLayer->setTextField(mbgl::style::DataDrivenPropertyValue<std::string>( + mbgl::style::conversion::convertTokenStringToExpression(string))); + return; + } + } auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<std::string>>(text); self.rawLayer->setTextField(mbglValue); } @@ -579,8 +594,7 @@ namespace mbgl { if (propertyValue.isUndefined()) { propertyValue = self.rawLayer->getDefaultTextField(); } - NSExpression *expression = MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); - return expression.mgl_expressionByReplacingTokensWithKeyPaths; + return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); } - (void)setTextField:(NSExpression *)textField { |