summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-11-04 10:18:06 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-11-08 15:36:01 +0200
commitc764daf7337118b37d959321a1fd3f3f853add43 (patch)
tree8810712a6c8dc48182b064e6b42bd3611884de82
parente0ab21eb975373c384c1e632bb326c5c2a7e025a (diff)
downloadqtlocation-mapboxgl-upstream/alexshalamov_image_expression.tar.gz
[darwin] Fix image roundrip conversionupstream/alexshalamov_image_expression
-rwxr-xr-xplatform/darwin/scripts/generate-style-code.js11
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm1
-rw-r--r--platform/darwin/test/MGLBackgroundStyleLayerTests.mm6
-rw-r--r--platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm6
-rw-r--r--platform/darwin/test/MGLFillStyleLayerTests.mm6
-rw-r--r--platform/darwin/test/MGLLineStyleLayerTests.mm6
-rw-r--r--platform/darwin/test/MGLStyleLayerTests.mm.ejs8
-rw-r--r--platform/darwin/test/MGLSymbolStyleLayerTests.mm10
8 files changed, 33 insertions, 21 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index cb2e3a9408..bd5adb9685 100755
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -153,12 +153,15 @@ global.objCTestValue = function (property, layerType, arraysAsStructs, indent) {
case 'number':
return '@"1"';
case 'formatted':
- case 'resolvedImage':
// Special 'string' case to handle constant expression text-field that automatically
// converts Formatted back to string.
return layerType === 'string' ?
`@"'${_.startCase(propertyName)}'"` :
`@"${_.startCase(propertyName)}"`;
+ case 'resolvedImage':
+ return layerType === 'string' ?
+ `@"${_.startCase(propertyName)}"` :
+ `@"MGL_FUNCTION('image', '${_.startCase(propertyName)}')"`;
case 'string':
return `@"'${_.startCase(propertyName)}'"`;
case 'enum':
@@ -209,7 +212,7 @@ global.mbglTestValue = function (property, layerType) {
return '1.0';
case 'formatted':
case 'string':
- case 'resolvedImage': // TODO: replace once we implement image expressions
+ case 'resolvedImage':
return `"${_.startCase(propertyName)}"`;
case 'enum': {
let type = camelize(originalPropertyName(property));
@@ -477,7 +480,7 @@ global.describeType = function (property) {
return 'numeric';
case 'formatted':
case 'string':
- case 'resolvedImage': // TODO: replace once we implement image expressions
+ case 'resolvedImage':
return 'string';
case 'enum':
return '`MGL' + camelize(property.name) + '`';
@@ -613,7 +616,7 @@ global.propertyType = function (property) {
return 'NSNumber *';
case 'formatted':
case 'string':
- case 'resolvedImage': // TODO: replace once we implement image expressions
+ case 'resolvedImage':
return 'NSString *';
case 'enum':
return 'NSValue *';
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index f139b86a88..80008aa69b 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1229,6 +1229,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
return expressionObject;
}
+
return self.arguments.mgl_jsonExpressionObject;
} else if (op == [MGLColor class] && [function isEqualToString:@"colorWithRed:green:blue:alpha:"]) {
NSArray *arguments = self.arguments.mgl_jsonExpressionObject;
diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm
index 3e59000c11..4617cff598 100644
--- a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm
+++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm
@@ -140,7 +140,7 @@
@"background-pattern should be unset initially.");
NSExpression *defaultExpression = layer.backgroundPattern;
- NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Background Pattern"];
+ NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Background Pattern"];
layer.backgroundPattern = constantExpression;
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Background Pattern" };
XCTAssertEqual(rawLayer->getBackgroundPattern(), propertyValue,
@@ -148,14 +148,14 @@
XCTAssertEqualObjects(layer.backgroundPattern, constantExpression,
@"backgroundPattern should round-trip constant value expressions.");
- constantExpression = [NSExpression expressionWithFormat:@"Background Pattern"];
+ constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Background Pattern')"];
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
layer.backgroundPattern = functionExpression;
{
using namespace mbgl::style::expression::dsl;
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
- step(zoom(), literal("Background Pattern"), 18.0, literal("Background Pattern"))
+ step(zoom(), image(literal("Background Pattern")), 18.0, image(literal("Background Pattern")))
);
}
diff --git a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm
index d35d76535e..8dfc077777 100644
--- a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm
+++ b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm
@@ -386,7 +386,7 @@
@"fill-extrusion-pattern should be unset initially.");
NSExpression *defaultExpression = layer.fillExtrusionPattern;
- NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Fill Extrusion Pattern"];
+ NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Fill Extrusion Pattern"];
layer.fillExtrusionPattern = constantExpression;
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Fill Extrusion Pattern" };
XCTAssertEqual(rawLayer->getFillExtrusionPattern(), propertyValue,
@@ -394,14 +394,14 @@
XCTAssertEqualObjects(layer.fillExtrusionPattern, constantExpression,
@"fillExtrusionPattern should round-trip constant value expressions.");
- constantExpression = [NSExpression expressionWithFormat:@"Fill Extrusion Pattern"];
+ constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Fill Extrusion Pattern')"];
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
layer.fillExtrusionPattern = functionExpression;
{
using namespace mbgl::style::expression::dsl;
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
- step(zoom(), literal("Fill Extrusion Pattern"), 18.0, literal("Fill Extrusion Pattern"))
+ step(zoom(), image(literal("Fill Extrusion Pattern")), 18.0, image(literal("Fill Extrusion Pattern")))
);
}
diff --git a/platform/darwin/test/MGLFillStyleLayerTests.mm b/platform/darwin/test/MGLFillStyleLayerTests.mm
index 667d48125e..e37bd537a7 100644
--- a/platform/darwin/test/MGLFillStyleLayerTests.mm
+++ b/platform/darwin/test/MGLFillStyleLayerTests.mm
@@ -333,7 +333,7 @@
@"fill-pattern should be unset initially.");
NSExpression *defaultExpression = layer.fillPattern;
- NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Fill Pattern"];
+ NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Fill Pattern"];
layer.fillPattern = constantExpression;
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Fill Pattern" };
XCTAssertEqual(rawLayer->getFillPattern(), propertyValue,
@@ -341,14 +341,14 @@
XCTAssertEqualObjects(layer.fillPattern, constantExpression,
@"fillPattern should round-trip constant value expressions.");
- constantExpression = [NSExpression expressionWithFormat:@"Fill Pattern"];
+ constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Fill Pattern')"];
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
layer.fillPattern = functionExpression;
{
using namespace mbgl::style::expression::dsl;
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
- step(zoom(), literal("Fill Pattern"), 18.0, literal("Fill Pattern"))
+ step(zoom(), image(literal("Fill Pattern")), 18.0, image(literal("Fill Pattern")))
);
}
diff --git a/platform/darwin/test/MGLLineStyleLayerTests.mm b/platform/darwin/test/MGLLineStyleLayerTests.mm
index 99350c388c..46f040b601 100644
--- a/platform/darwin/test/MGLLineStyleLayerTests.mm
+++ b/platform/darwin/test/MGLLineStyleLayerTests.mm
@@ -659,7 +659,7 @@
@"line-pattern should be unset initially.");
NSExpression *defaultExpression = layer.linePattern;
- NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Line Pattern"];
+ NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Line Pattern"];
layer.linePattern = constantExpression;
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Line Pattern" };
XCTAssertEqual(rawLayer->getLinePattern(), propertyValue,
@@ -667,14 +667,14 @@
XCTAssertEqualObjects(layer.linePattern, constantExpression,
@"linePattern should round-trip constant value expressions.");
- constantExpression = [NSExpression expressionWithFormat:@"Line Pattern"];
+ constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Line Pattern')"];
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
layer.linePattern = functionExpression;
{
using namespace mbgl::style::expression::dsl;
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
- step(zoom(), literal("Line Pattern"), 18.0, literal("Line Pattern"))
+ step(zoom(), image(literal("Line Pattern")), 18.0, image(literal("Line Pattern")))
);
}
diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs
index 14c7c397d3..a764f163be 100644
--- a/platform/darwin/test/MGLStyleLayerTests.mm.ejs
+++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs
@@ -73,6 +73,8 @@
<% if (property.type === 'formatted') { -%>
NSExpression *constantExpression = [NSExpression expressionWithFormat:<%- objCTestValue(property, 'string', true, 3) %>];
+<% } else if (property.type === 'resolvedImage'){ -%>
+ NSExpression *constantExpression = [NSExpression expressionForConstantValue:<%- objCTestValue(property, 'string', true, 3) %>];
<% } else { -%>
NSExpression *constantExpression = [NSExpression expressionWithFormat:<%- objCTestValue(property, type, true, 3) %>];
<% } -%>
@@ -98,6 +100,8 @@
propertyValue = mbgl::style::PropertyExpression<<%- mbglType(property) %>>(
<% if (property.type === 'formatted') { -%>
step(zoom(), format(<%- mbglExpressionTestValue(property, type) %>), 18.0, format(<%- mbglExpressionTestValue(property, type) %>))
+<% } else if (property.type === 'resolvedImage') { -%>
+ step(zoom(), image(literal(<%- mbglExpressionTestValue(property, type) %>)), 18.0, image(literal(<%- mbglExpressionTestValue(property, type) %>)))
<% } else { -%>
step(zoom(), literal(<%- mbglExpressionTestValue(property, type) %>), 18.0, literal(<%- mbglExpressionTestValue(property, type) %>))
<% } -%>
@@ -179,6 +183,8 @@
propertyValue = mbgl::style::PropertyExpression<<%- mbglType(property) %>>(
<% if (property.type === 'formatted') { -%>
format(toString(get(literal("token"))))
+<% } else if (property.type === 'resolvedImage') { -%>
+ image(toString(get(literal("token"))))
<% } else { -%>
toString(get(literal("token")))
<% } -%>
@@ -192,6 +198,8 @@
MGLAttributedExpression *tokenAttibutedExpression = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionWithFormat:@"CAST(token, 'NSString')"]
attributes:@{}];
NSExpression* tokenExpression = [NSExpression mgl_expressionForAttributedExpressions:@[[NSExpression expressionForConstantValue:tokenAttibutedExpression]]];
+<% } else if (property.type === 'resolvedImage') { -%>
+ NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', CAST(token, \"NSString\"))"];
<% } else { -%>
NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"CAST(token, \"NSString\")"];
<% } -%>
diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
index cfb62fd4df..04ef3fc712 100644
--- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm
+++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
@@ -182,7 +182,7 @@
@"icon-image should be unset initially.");
NSExpression *defaultExpression = layer.iconImageName;
- NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Icon Image"];
+ NSExpression *constantExpression = [NSExpression expressionForConstantValue:@"Icon Image"];
layer.iconImageName = constantExpression;
mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Icon Image" };
XCTAssertEqual(rawLayer->getIconImage(), propertyValue,
@@ -190,14 +190,14 @@
XCTAssertEqualObjects(layer.iconImageName, constantExpression,
@"iconImageName should round-trip constant value expressions.");
- constantExpression = [NSExpression expressionWithFormat:@"Icon Image"];
+ constantExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', 'Icon Image')"];
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
layer.iconImageName = functionExpression;
{
using namespace mbgl::style::expression::dsl;
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
- step(zoom(), literal("Icon Image"), 18.0, literal("Icon Image"))
+ step(zoom(), image(literal("Icon Image")), 18.0, image(literal("Icon Image")))
);
}
@@ -219,14 +219,14 @@
{
using namespace mbgl::style::expression::dsl;
propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>(
- toString(get(literal("token")))
+ image(toString(get(literal("token"))))
);
}
XCTAssertEqual(rawLayer->getIconImage(), propertyValue,
@"Setting iconImageName to a constant string with tokens should convert to an expression.");
- NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"CAST(token, \"NSString\")"];
+ NSExpression* tokenExpression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('image', CAST(token, \"NSString\"))"];
XCTAssertEqualObjects(layer.iconImageName, tokenExpression,
@"Setting iconImageName to a constant string with tokens should convert to an expression.");
}