diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-11-04 10:08:06 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-11-11 18:20:01 +0200 |
commit | 9fc9cc30e8bd934563495aac0153d8446e946f80 (patch) | |
tree | 5116a34108803aa79fc375fa0bd0ab87bcc30304 | |
parent | 3f7ed99d89be9cad32fc1ecdfcc256aa3030f166 (diff) | |
download | qtlocation-mapboxgl-9fc9cc30e8bd934563495aac0153d8446e946f80.tar.gz |
[darwin] Add conversion for resolvedImage
-rwxr-xr-x | platform/darwin/scripts/generate-style-code.js | 12 | ||||
-rw-r--r-- | platform/darwin/src/MGLBackgroundStyleLayer.mm | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLFillExtrusionStyleLayer.mm | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLFillStyleLayer.mm | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLLineStyleLayer.mm | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayer.mm.ejs | 3 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleValue_Private.h | 10 | ||||
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.mm | 8 | ||||
-rw-r--r-- | platform/darwin/test/MGLBackgroundStyleLayerTests.mm | 8 | ||||
-rw-r--r-- | platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm | 8 | ||||
-rw-r--r-- | platform/darwin/test/MGLFillStyleLayerTests.mm | 8 | ||||
-rw-r--r-- | platform/darwin/test/MGLLineStyleLayerTests.mm | 8 | ||||
-rw-r--r-- | platform/darwin/test/MGLSymbolStyleLayerTests.mm | 10 |
13 files changed, 53 insertions, 38 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 5d0434f9ea..cb2e3a9408 100755 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -153,13 +153,13 @@ 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 'string': - case 'resolvedImage': // TODO: replace once we implement image expressions return `@"'${_.startCase(propertyName)}'"`; case 'enum': return `@"'${_.last(_.keys(property.values))}'"`; @@ -296,7 +296,7 @@ global.testHelperMessage = function (property, layerType, isFunction) { return 'testNumber' + fnSuffix; case 'formatted': case 'string': - case 'image': // TODO: replace once we implement image expressions + case 'resolvedImage': return 'testString' + fnSuffix; case 'enum': let objCType = global.objCType(layerType, property.name); @@ -526,7 +526,7 @@ global.describeValue = function (value, property, layerType) { return 'the float ' + '`' + formatNumber(value) + '`'; case 'formatted': case 'string': - case 'image': // TODO: replace once we implement image expressions + case 'resolvedImage': if (value === '') { return 'the empty string'; } @@ -659,8 +659,9 @@ global.valueTransformerArguments = function (property) { return ['float', objCType]; case 'formatted': return ['mbgl::style::expression::Formatted', objCType]; + case 'resolvedImage': + return ['mbgl::style::expression::Image', objCType]; case 'string': - case 'resolvedImage': // TODO: replace once we implement image expressions return ['std::string', objCType]; case 'enum': return [mbglType(property), 'NSValue *', mbglType(property), `MGL${camelize(property.name)}`]; @@ -699,8 +700,9 @@ global.mbglType = function(property) { return 'float'; case 'formatted': return 'mbgl::style::expression::Formatted'; + case 'resolvedImage': + return 'mbgl::style::expression::Image'; case 'string': - case 'resolvedImage': // TODO: replace once we implement image expressions return 'std::string'; case 'enum': { let type = camelize(originalPropertyName(property)); diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 00b10cf2be..053e05c5c4 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -106,7 +106,7 @@ MGLAssertStyleLayerIsValid(); MGLLogDebug(@"Setting backgroundPattern: %@", backgroundPattern); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(backgroundPattern, false); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::expression::Image>>(backgroundPattern, false); self.rawLayer->setBackgroundPattern(mbglValue); } @@ -117,7 +117,7 @@ if (propertyValue.isUndefined()) { propertyValue = self.rawLayer->getDefaultBackgroundPattern(); } - return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); + return MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toExpression(propertyValue); } - (void)setBackgroundPatternTransition:(MGLTransition )transition { diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm index 1039a8facc..ed6cd58460 100644 --- a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm @@ -244,7 +244,7 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); MGLLogDebug(@"Setting fillExtrusionPattern: %@", fillExtrusionPattern); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(fillExtrusionPattern, true); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::expression::Image>>(fillExtrusionPattern, true); self.rawLayer->setFillExtrusionPattern(mbglValue); } @@ -255,7 +255,7 @@ namespace mbgl { if (propertyValue.isUndefined()) { propertyValue = self.rawLayer->getDefaultFillExtrusionPattern(); } - return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); + return MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toExpression(propertyValue); } - (void)setFillExtrusionPatternTransition:(MGLTransition )transition { diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 5a91320656..d8c5516f3a 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -211,7 +211,7 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); MGLLogDebug(@"Setting fillPattern: %@", fillPattern); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(fillPattern, true); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::expression::Image>>(fillPattern, true); self.rawLayer->setFillPattern(mbglValue); } @@ -222,7 +222,7 @@ namespace mbgl { if (propertyValue.isUndefined()) { propertyValue = self.rawLayer->getDefaultFillPattern(); } - return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); + return MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toExpression(propertyValue); } - (void)setFillPatternTransition:(MGLTransition )transition { diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index fe37be361c..62d778a6f3 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -396,7 +396,7 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); MGLLogDebug(@"Setting linePattern: %@", linePattern); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(linePattern, true); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::expression::Image>>(linePattern, true); self.rawLayer->setLinePattern(mbglValue); } @@ -407,7 +407,7 @@ namespace mbgl { if (propertyValue.isUndefined()) { propertyValue = self.rawLayer->getDefaultLinePattern(); } - return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); + return MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toExpression(propertyValue); } - (void)setLinePatternTransition:(MGLTransition )transition { diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 5d9f546cd7..5664f7fd45 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -136,6 +136,9 @@ namespace mbgl { <% if (property.type === 'formatted') { -%> self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbgl::style::PropertyValue<mbgl::style::expression::Formatted>( mbgl::style::conversion::convertTokenStringToFormatExpression(string))); +<% } else if (property.type === 'resolvedImage') { -%> + self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbgl::style::PropertyValue<mbgl::style::expression::Image>( + mbgl::style::conversion::convertTokenStringToImageExpression(string))); <% } else { -%> self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbgl::style::PropertyValue<std::string>( mbgl::style::conversion::convertTokenStringToExpression(string))); diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index 82ce232c6b..07dbd31238 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -217,6 +217,11 @@ private: // Private utilities for converting from mgl to mbgl values mbglValue = rawValue.mgl_color; } + // Image + void getMBGLValue(NSString *rawValue, mbgl::style::expression::Image &mbglValue) { + mbglValue = mbgl::style::expression::Image(rawValue.UTF8String); + } + // Array void getMBGLValue(ObjCType rawValue, std::vector<MBGLElement> &mbglValue) { mbglValue.reserve(rawValue.count); @@ -295,6 +300,11 @@ private: // Private utilities for converting from mbgl to mgl values return [MGLColor mgl_colorWithColor:mbglStopValue]; } + // Image + static NSString *toMGLRawStyleValue(const mbgl::style::expression::Image &mbglImageValue) { + return @(mbglImageValue.id().c_str()); + } + // Array static NSArray<NSExpression*> *toMGLRawStyleValue(const std::vector<MBGLElement> &mbglStopValue) { NSMutableArray *array = [NSMutableArray arrayWithCapacity:mbglStopValue.size()]; diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index e89b9c3e88..966386e0f2 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -248,12 +248,12 @@ namespace mbgl { if (iconImageName && iconImageName.expressionType == NSConstantValueExpressionType) { std::string string = ((NSString *)iconImageName.constantValue).UTF8String; if (mbgl::style::conversion::hasTokens(string)) { - self.rawLayer->setIconImage(mbgl::style::PropertyValue<std::string>( - mbgl::style::conversion::convertTokenStringToExpression(string))); + self.rawLayer->setIconImage(mbgl::style::PropertyValue<mbgl::style::expression::Image>( + mbgl::style::conversion::convertTokenStringToImageExpression(string))); return; } } - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(iconImageName, true); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::expression::Image>>(iconImageName, true); self.rawLayer->setIconImage(mbglValue); } @@ -264,7 +264,7 @@ namespace mbgl { if (propertyValue.isUndefined()) { propertyValue = self.rawLayer->getDefaultIconImage(); } - return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); + return MGLStyleValueTransformer<mbgl::style::expression::Image, NSString *>().toExpression(propertyValue); } - (void)setIconImage:(NSExpression *)iconImage { diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm index 600f81acfe..3e59000c11 100644 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm @@ -140,21 +140,21 @@ @"background-pattern should be unset initially."); NSExpression *defaultExpression = layer.backgroundPattern; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'Background Pattern'"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Background Pattern"]; layer.backgroundPattern = constantExpression; - mbgl::style::PropertyValue<std::string> propertyValue = { "Background Pattern" }; + mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Background Pattern" }; XCTAssertEqual(rawLayer->getBackgroundPattern(), propertyValue, @"Setting backgroundPattern to a constant value expression should update background-pattern."); XCTAssertEqualObjects(layer.backgroundPattern, constantExpression, @"backgroundPattern should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"'Background Pattern'"]; + constantExpression = [NSExpression expressionWithFormat:@"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<std::string>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>( step(zoom(), literal("Background Pattern"), 18.0, literal("Background Pattern")) ); } diff --git a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm index 357ee888bc..d35d76535e 100644 --- a/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillExtrusionStyleLayerTests.mm @@ -386,21 +386,21 @@ @"fill-extrusion-pattern should be unset initially."); NSExpression *defaultExpression = layer.fillExtrusionPattern; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'Fill Extrusion Pattern'"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Fill Extrusion Pattern"]; layer.fillExtrusionPattern = constantExpression; - mbgl::style::PropertyValue<std::string> propertyValue = { "Fill Extrusion Pattern" }; + mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Fill Extrusion Pattern" }; XCTAssertEqual(rawLayer->getFillExtrusionPattern(), propertyValue, @"Setting fillExtrusionPattern to a constant value expression should update fill-extrusion-pattern."); XCTAssertEqualObjects(layer.fillExtrusionPattern, constantExpression, @"fillExtrusionPattern should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"'Fill Extrusion Pattern'"]; + constantExpression = [NSExpression expressionWithFormat:@"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<std::string>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>( step(zoom(), literal("Fill Extrusion Pattern"), 18.0, literal("Fill Extrusion Pattern")) ); } diff --git a/platform/darwin/test/MGLFillStyleLayerTests.mm b/platform/darwin/test/MGLFillStyleLayerTests.mm index 3762c4095e..667d48125e 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillStyleLayerTests.mm @@ -333,21 +333,21 @@ @"fill-pattern should be unset initially."); NSExpression *defaultExpression = layer.fillPattern; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'Fill Pattern'"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Fill Pattern"]; layer.fillPattern = constantExpression; - mbgl::style::PropertyValue<std::string> propertyValue = { "Fill Pattern" }; + mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Fill Pattern" }; XCTAssertEqual(rawLayer->getFillPattern(), propertyValue, @"Setting fillPattern to a constant value expression should update fill-pattern."); XCTAssertEqualObjects(layer.fillPattern, constantExpression, @"fillPattern should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"'Fill Pattern'"]; + constantExpression = [NSExpression expressionWithFormat:@"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<std::string>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>( step(zoom(), literal("Fill Pattern"), 18.0, literal("Fill Pattern")) ); } diff --git a/platform/darwin/test/MGLLineStyleLayerTests.mm b/platform/darwin/test/MGLLineStyleLayerTests.mm index f4fd714ad7..99350c388c 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.mm +++ b/platform/darwin/test/MGLLineStyleLayerTests.mm @@ -659,21 +659,21 @@ @"line-pattern should be unset initially."); NSExpression *defaultExpression = layer.linePattern; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'Line Pattern'"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Line Pattern"]; layer.linePattern = constantExpression; - mbgl::style::PropertyValue<std::string> propertyValue = { "Line Pattern" }; + mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Line Pattern" }; XCTAssertEqual(rawLayer->getLinePattern(), propertyValue, @"Setting linePattern to a constant value expression should update line-pattern."); XCTAssertEqualObjects(layer.linePattern, constantExpression, @"linePattern should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"'Line Pattern'"]; + constantExpression = [NSExpression expressionWithFormat:@"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<std::string>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>( step(zoom(), literal("Line Pattern"), 18.0, literal("Line Pattern")) ); } diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index 5cc9c3c332..cfb62fd4df 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -182,21 +182,21 @@ @"icon-image should be unset initially."); NSExpression *defaultExpression = layer.iconImageName; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'Icon Image'"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"Icon Image"]; layer.iconImageName = constantExpression; - mbgl::style::PropertyValue<std::string> propertyValue = { "Icon Image" }; + mbgl::style::PropertyValue<mbgl::style::expression::Image> propertyValue = { "Icon Image" }; XCTAssertEqual(rawLayer->getIconImage(), propertyValue, @"Setting iconImageName to a constant value expression should update icon-image."); XCTAssertEqualObjects(layer.iconImageName, constantExpression, @"iconImageName should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"'Icon Image'"]; + constantExpression = [NSExpression expressionWithFormat:@"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<std::string>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>( step(zoom(), literal("Icon Image"), 18.0, literal("Icon Image")) ); } @@ -218,7 +218,7 @@ { using namespace mbgl::style::expression::dsl; - propertyValue = mbgl::style::PropertyExpression<std::string>( + propertyValue = mbgl::style::PropertyExpression<mbgl::style::expression::Image>( toString(get(literal("token"))) ); } |