summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSExpression+MGLAdditions.mm
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2019-03-22 13:45:39 -0700
committerFabian Guerra Soto <fabian.guerra@mapbox.com>2019-03-22 15:08:58 -0700
commit79582487aa69569933e38cadc0faf5ea04711303 (patch)
tree7f44ae7c6654171fd58faaafd6bfd3ab7e9306aa /platform/darwin/src/NSExpression+MGLAdditions.mm
parentbe46a707f992ce48e65163353924e0d7be25c722 (diff)
downloadqtlocation-mapboxgl-79582487aa69569933e38cadc0faf5ea04711303.tar.gz
[ios, macos] Support expressions in formatting parameters. (#14198)
Modified MGLAttributedExpression object to support NSExpressions as formatting attributes only. This aligns with GL and Android implementation and specification. Modified the documentation accordingly, and changed MGLFontSizeAttribute to MGLFontScaleAttribute to clarify the true function of the formatting parameter.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm27
1 files changed, 7 insertions, 20 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index b509c12172..4b1fdb818e 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -882,19 +882,8 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
attrs = [NSMutableDictionary dictionaryWithDictionary:argumentObjects[index + 1]];
}
- if (attrs.count) {
- if (NSArray *fontNames = MGL_OBJC_DYNAMIC_CAST(attrs[MGLFontNamesAttribute], NSArray)) {
- attrs[MGLFontNamesAttribute] = fontNames[1];
- }
- if (NSArray *colorArray = MGL_OBJC_DYNAMIC_CAST(attrs[MGLFontColorAttribute], NSArray)) {
- if ([colorArray[0] isEqualToString:@"rgb"] || [colorArray[0] isEqualToString:@"rgba"]) {
- NSArray *colorArguments = [colorArray subarrayWithRange:NSMakeRange(1, colorArray.count - 1)];
- NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(colorArguments);
- MGLColor *color = [NSExpression mgl_colorWithRGBComponents:subexpressions];
-
- attrs[MGLFontColorAttribute] = color;
- }
- }
+ for (NSString *key in attrs.allKeys) {
+ attrs[key] = [NSExpression expressionWithMGLJSONObject:attrs[key]];
}
MGLAttributedExpression *attributedExpression = [[MGLAttributedExpression alloc] initWithExpression:expression attributes:attrs];
@@ -1016,17 +1005,15 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
if ([constantValue isKindOfClass:[MGLAttributedExpression class]]) {
MGLAttributedExpression *attributedExpression = (MGLAttributedExpression *)constantValue;
id jsonObject = attributedExpression.expression.mgl_jsonExpressionObject;
- NSMutableDictionary *attributedDictionary = [NSMutableDictionary dictionary];
+ NSMutableDictionary<MGLAttributedExpressionKey, NSExpression *> *attributedDictionary = [NSMutableDictionary dictionary];
if (attributedExpression.attributes) {
attributedDictionary = [NSMutableDictionary dictionaryWithDictionary:attributedExpression.attributes];
- if (attributedDictionary[MGLFontNamesAttribute]) {
- attributedDictionary[MGLFontNamesAttribute] = @[@"literal", attributedDictionary[MGLFontNamesAttribute]];
- }
- if (attributedDictionary[MGLFontColorAttribute] && [attributedDictionary[MGLFontColorAttribute] isKindOfClass:[MGLColor class]]) {
- MGLColor *color = attributedDictionary[MGLFontColorAttribute];
- attributedDictionary[MGLFontColorAttribute] = color.mgl_jsonExpressionObject;
+
+ for (NSString *key in attributedExpression.attributes.allKeys) {
+ attributedDictionary[key] = attributedExpression.attributes[key].mgl_jsonExpressionObject;
}
+
}
return @[jsonObject, attributedDictionary];
}