summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-04-24 14:39:11 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-05-04 13:48:09 -0400
commita980f9c717151b30bf835d5a0c02edaf8b1ef94a (patch)
treeb673df55971b62b4942a458472d0ef0b4110ffee
parentc47f17d220c5a82c28cb4c1c298062e48241a9d0 (diff)
downloadqtlocation-mapboxgl-a980f9c717151b30bf835d5a0c02edaf8b1ef94a.tar.gz
[ios, macos] Add support for to-rgba expression operator.
-rw-r--r--platform/darwin/docs/guides/For Style Authors.md.ejs8
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm6
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm6
-rw-r--r--platform/ios/docs/guides/For Style Authors.md4
-rw-r--r--platform/macos/docs/guides/For Style Authors.md4
5 files changed, 22 insertions, 6 deletions
diff --git a/platform/darwin/docs/guides/For Style Authors.md.ejs b/platform/darwin/docs/guides/For Style Authors.md.ejs
index 37ddd68410..dca6c2905c 100644
--- a/platform/darwin/docs/guides/For Style Authors.md.ejs
+++ b/platform/darwin/docs/guides/For Style Authors.md.ejs
@@ -335,7 +335,11 @@ In style specification | Method, function, or predicate type | Format string syn
`number` | |
`string` | |
`to-boolean` | `boolValue` |
-`to-color` | |
+<% if (macOS) { -%>
+`to-color` | | `CAST(var, 'NScolor')`
+<% } else { -%>
+`to-color` | | `CAST(var, 'UIColor')`
+<% } -%>
`to-number` | `mgl_numberWithFallbackValues:` | `CAST(zipCode, 'NSNumber')`
`to-string` | `stringValue` | `CAST(ele, 'NSString')`
`typeof` | |
@@ -372,7 +376,7 @@ In style specification | Method, function, or predicate type | Format string syn
`rgb` | `+[UIColor colorWithRed:green:blue:alpha:]` |
`rgba` | `+[UIColor colorWithRed:green:blue:alpha:]` |
<% } -%>
-`to-rgba` | | `CAST(var, 'UIColor')` or `CAST(var, 'NSColor')`
+`to-rgba` | | `CAST(var, 'NSArray')`
`-` | `from:subtract:` | `2 - 1`
`*` | `multiply:by:` | `1 * 2`
`/` | `divide:by:` | `1 / 2`
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 5fc9eb6cb9..4ef744e918 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -810,6 +810,9 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
return [NSExpression expressionWithFormat:@"CAST(%@, 'NSColor')", operand];
#endif
+ } else if ([op isEqualToString:@"to-rgba"]) {
+ NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject];
+ return [NSExpression expressionWithFormat:@"CAST(%@, 'NSArray')", operand];
} else if ([op isEqualToString:@"get"]) {
if (argumentObjects.count == 2) {
NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.lastObject];
@@ -1182,6 +1185,9 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
return @[@"to-color", object];
}
#endif
+ else if ([type isEqualToString:@"NSArray"]) {
+ return @[@"to-rgba", object];
+ }
[NSException raise:NSInvalidArgumentException
format:@"Casting expression to %@ not yet implemented.", type];
} else if ([function isEqualToString:@"MGL_FUNCTION"]) {
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 942658e326..531c326f31 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -684,6 +684,12 @@ using namespace std::string_literals;
NSArray *jsonExpression = @[@"to-color", @[@"get", @"x"]];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
}
+ {
+ NSExpression *expression = [NSExpression expressionWithFormat:@"CAST(x, 'NSArray')"];
+ NSArray *jsonExpression = @[@"to-rgba", @[@"get", @"x"]];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
+ }
}
- (void)testInterpolationExpressionObject {
diff --git a/platform/ios/docs/guides/For Style Authors.md b/platform/ios/docs/guides/For Style Authors.md
index 30697b357c..cc92ee0433 100644
--- a/platform/ios/docs/guides/For Style Authors.md
+++ b/platform/ios/docs/guides/For Style Authors.md
@@ -325,7 +325,7 @@ In style specification | Method, function, or predicate type | Format string syn
`number` | |
`string` | |
`to-boolean` | `boolValue` |
-`to-color` | |
+`to-color` | | `CAST(var, 'UIColor')`
`to-number` | `mgl_numberWithFallbackValues:` | `CAST(zipCode, 'NSNumber')`
`to-string` | `stringValue` | `CAST(ele, 'NSString')`
`typeof` | |
@@ -357,7 +357,7 @@ In style specification | Method, function, or predicate type | Format string syn
`upcase` | `uppercase:` | `uppercase('Elysian Fields')`
`rgb` | `+[UIColor colorWithRed:green:blue:alpha:]` |
`rgba` | `+[UIColor colorWithRed:green:blue:alpha:]` |
-`to-rgba` | | `CAST(var, 'UIColor')` or `CAST(var, 'NSColor')`
+`to-rgba` | | `CAST(var, 'NSArray')`
`-` | `from:subtract:` | `2 - 1`
`*` | `multiply:by:` | `1 * 2`
`/` | `divide:by:` | `1 / 2`
diff --git a/platform/macos/docs/guides/For Style Authors.md b/platform/macos/docs/guides/For Style Authors.md
index 842866a3c0..e257b1fdb8 100644
--- a/platform/macos/docs/guides/For Style Authors.md
+++ b/platform/macos/docs/guides/For Style Authors.md
@@ -318,7 +318,7 @@ In style specification | Method, function, or predicate type | Format string syn
`number` | |
`string` | |
`to-boolean` | `boolValue` |
-`to-color` | |
+`to-color` | | `CAST(var, 'NScolor')`
`to-number` | `mgl_numberWithFallbackValues:` | `CAST(zipCode, 'NSNumber')`
`to-string` | `stringValue` | `CAST(ele, 'NSString')`
`typeof` | |
@@ -350,7 +350,7 @@ In style specification | Method, function, or predicate type | Format string syn
`upcase` | `uppercase:` | `uppercase('Elysian Fields')`
`rgb` | `+[NSColor colorWithCalibratedRed:green:blue:alpha:]` |
`rgba` | `+[NSColor colorWithCalibratedRed:green:blue:alpha:]` |
-`to-rgba` | | `CAST(var, 'UIColor')` or `CAST(var, 'NSColor')`
+`to-rgba` | | `CAST(var, 'NSArray')`
`-` | `from:subtract:` | `2 - 1`
`*` | `multiply:by:` | `1 * 2`
`/` | `divide:by:` | `1 / 2`