diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-07-20 13:06:01 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-07-23 13:33:27 -0700 |
commit | 0b2221cb74ab79a0610ac44cee2a053da41a3dff (patch) | |
tree | 372e3e3215d70676c4625476889b4d9dbb6cd434 /platform/darwin | |
parent | f9b36f9f5b4cf09e08c2ff0181b339b53e8d0014 (diff) | |
download | qtlocation-mapboxgl-0b2221cb74ab79a0610ac44cee2a053da41a3dff.tar.gz |
[android, ios, macos] Generate symbol-placement: line-center wrappers
Diffstat (limited to 'platform/darwin')
-rwxr-xr-x | platform/darwin/scripts/generate-style-code.js | 11 | ||||
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.h | 54 | ||||
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.mm | 1 | ||||
-rw-r--r-- | platform/darwin/test/MGLSymbolStyleLayerTests.mm | 9 |
4 files changed, 49 insertions, 26 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 3809e9c636..0e5bf89fd4 100755 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -248,13 +248,20 @@ global.testHelperMessage = function (property, layerType, isFunction) { global.propertyDoc = function (propertyName, property, layerType, kind) { // Match references to other property names & values. // Requires the format 'When `foo` is set to `bar`,'. - let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) { + let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`(?: or `([^`]+?)`)?/g, function (m, peerPropertyName, propertyValue, secondPropertyValue, offset, str) { let otherProperty = camelizeWithLeadingLowercase(peerPropertyName); let otherValue = objCType(layerType, peerPropertyName) + camelize(propertyValue); if (property.type == 'array' && kind == 'light') { otherValue = propertyValue; } - return '`' + `${otherProperty}` + '` is set to `' + `${otherValue}` + '`'; + const firstPropertyValue = '`' + `${otherProperty}` + '` is set to `' + `${otherValue}` + '`'; + if (secondPropertyValue) { + return firstPropertyValue + ' or `' + + objCType(layerType, peerPropertyName) + camelize(secondPropertyValue) + + '`'; + } else { + return firstPropertyValue; + } }); // Match references to our own property values. // Requires the format 'is equivalent to `bar`'. diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index 2c899fe76f..afaea9a74f 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -83,8 +83,8 @@ typedef NS_ENUM(NSUInteger, MGLIconPitchAlignment) { typedef NS_ENUM(NSUInteger, MGLIconRotationAlignment) { /** When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, aligns icons - east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine`, - aligns icon x-axes with the line. + east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine` or + `MGLSymbolPlacementLineCenter`, aligns icon x-axes with the line. */ MGLIconRotationAlignmentMap, /** @@ -95,8 +95,8 @@ typedef NS_ENUM(NSUInteger, MGLIconRotationAlignment) { /** When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, this is equivalent to `MGLIconRotationAlignmentViewport`. When `symbolPlacement` is - set to `MGLSymbolPlacementLine`, this is equivalent to - `MGLIconRotationAlignmentMap`. + set to `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`, this is + equivalent to `MGLIconRotationAlignmentMap`. */ MGLIconRotationAlignmentAuto, }; @@ -142,6 +142,12 @@ typedef NS_ENUM(NSUInteger, MGLSymbolPlacement) { `LineString` and `Polygon` geometries. */ MGLSymbolPlacementLine, + /** + The label is placed at the center of the line of the geometry. Can only be + used on `LineString` and `Polygon` geometries. Note that a single feature + in a vector tile may contain multiple line geometries. + */ + MGLSymbolPlacementLineCenter, }; /** @@ -242,8 +248,8 @@ typedef NS_ENUM(NSUInteger, MGLTextPitchAlignment) { typedef NS_ENUM(NSUInteger, MGLTextRotationAlignment) { /** When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, aligns text - east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine`, - aligns text x-axes with the line. + east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine` or + `MGLSymbolPlacementLineCenter`, aligns text x-axes with the line. */ MGLTextRotationAlignmentMap, /** @@ -254,8 +260,8 @@ typedef NS_ENUM(NSUInteger, MGLTextRotationAlignment) { /** When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, this is equivalent to `MGLTextRotationAlignmentViewport`. When `symbolPlacement` is - set to `MGLSymbolPlacementLine`, this is equivalent to - `MGLTextRotationAlignmentMap`. + set to `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`, this is + equivalent to `MGLTextRotationAlignmentMap`. */ MGLTextRotationAlignmentAuto, }; @@ -653,12 +659,13 @@ MGL_EXPORT * Constant `MGLIconRotationAlignment` values * Any of the following constant string values: * `map`: When `symbol-placement` is set to `point`, aligns icons east-west. - When `symbol-placement` is set to `line`, aligns icon x-axes with the line. + When `symbol-placement` is set to `line` or `line-center`, aligns icon x-axes + with the line. * `viewport`: Produces icons whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbol-placement`. * `auto`: When `symbol-placement` is set to `point`, this is equivalent to - `viewport`. When `symbol-placement` is set to `line`, this is equivalent to - `map`. + `viewport`. When `symbol-placement` is set to `line` or `line-center`, this is + equivalent to `map`. * Predefined functions, including mathematical and string operators * Conditional expressions * Variable assignments and references to assigned variables @@ -795,8 +802,9 @@ MGL_EXPORT This property is only applied to the style if `iconImageName` is non-`nil`, and `iconRotationAlignment` is set to an expression that evaluates to `map`, and - `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise, - it is ignored. + `symbolPlacement` is set to an expression that evaluates to either + `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`. Otherwise, it is + ignored. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-icon-keep-upright"><code>icon-keep-upright</code></a> @@ -828,8 +836,9 @@ MGL_EXPORT This property is only applied to the style if `text` is non-`nil`, and `textRotationAlignment` is set to an expression that evaluates to `map`, and - `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise, - it is ignored. + `symbolPlacement` is set to an expression that evaluates to either + `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`. Otherwise, it is + ignored. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-keep-upright"><code>text-keep-upright</code></a> @@ -861,8 +870,9 @@ MGL_EXPORT `45`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`, and - `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise, - it is ignored. + `symbolPlacement` is set to an expression that evaluates to either + `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`. Otherwise, it is + ignored. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-max-angle"><code>text-max-angle</code></a> @@ -956,6 +966,9 @@ MGL_EXPORT * `point`: The label is placed at the point where the geometry is located. * `line`: The label is placed along the line of the geometry. Can only be used on `LineString` and `Polygon` geometries. + * `line-center`: The label is placed at the center of the line of the + geometry. Can only be used on `LineString` and `Polygon` geometries. Note that + a single feature in a vector tile may contain multiple line geometries. * Predefined functions, including mathematical and string operators * Conditional expressions * Variable assignments and references to assigned variables @@ -1427,12 +1440,13 @@ MGL_EXPORT * Constant `MGLTextRotationAlignment` values * Any of the following constant string values: * `map`: When `symbol-placement` is set to `point`, aligns text east-west. - When `symbol-placement` is set to `line`, aligns text x-axes with the line. + When `symbol-placement` is set to `line` or `line-center`, aligns text x-axes + with the line. * `viewport`: Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbol-placement`. * `auto`: When `symbol-placement` is set to `point`, this is equivalent to - `viewport`. When `symbol-placement` is set to `line`, this is equivalent to - `map`. + `viewport`. When `symbol-placement` is set to `line` or `line-center`, this is + equivalent to `map`. * Predefined functions, including mathematical and string operators * Conditional expressions * Variable assignments and references to assigned variables diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index f5522b800d..791bb5f894 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -47,6 +47,7 @@ namespace mbgl { MBGL_DEFINE_ENUM(MGLSymbolPlacement, { { MGLSymbolPlacementPoint, "point" }, { MGLSymbolPlacementLine, "line" }, + { MGLSymbolPlacementLineCenter, "line-center" }, }); MBGL_DEFINE_ENUM(MGLTextAnchor, { diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index 8643e8388b..9d772b6bd9 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -962,22 +962,22 @@ @"symbol-placement should be unset initially."); NSExpression *defaultExpression = layer.symbolPlacement; - NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'line'"]; + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'line-center'"]; layer.symbolPlacement = constantExpression; - mbgl::style::PropertyValue<mbgl::style::SymbolPlacementType> propertyValue = { mbgl::style::SymbolPlacementType::Line }; + mbgl::style::PropertyValue<mbgl::style::SymbolPlacementType> propertyValue = { mbgl::style::SymbolPlacementType::LineCenter }; XCTAssertEqual(rawLayer->getSymbolPlacement(), propertyValue, @"Setting symbolPlacement to a constant value expression should update symbol-placement."); XCTAssertEqualObjects(layer.symbolPlacement, constantExpression, @"symbolPlacement should round-trip constant value expressions."); - constantExpression = [NSExpression expressionWithFormat:@"'line'"]; + constantExpression = [NSExpression expressionWithFormat:@"'line-center'"]; NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; layer.symbolPlacement = functionExpression; { using namespace mbgl::style::expression::dsl; propertyValue = mbgl::style::PropertyExpression<mbgl::style::SymbolPlacementType>( - step(zoom(), literal("line"), 18.0, literal("line")) + step(zoom(), literal("line-center"), 18.0, literal("line-center")) ); } @@ -2883,6 +2883,7 @@ XCTAssertEqual([NSValue valueWithMGLIconTextFit:MGLIconTextFitBoth].MGLIconTextFitValue, MGLIconTextFitBoth); XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementPoint].MGLSymbolPlacementValue, MGLSymbolPlacementPoint); XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementLine].MGLSymbolPlacementValue, MGLSymbolPlacementLine); + XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementLineCenter].MGLSymbolPlacementValue, MGLSymbolPlacementLineCenter); XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorCenter].MGLTextAnchorValue, MGLTextAnchorCenter); XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorLeft].MGLTextAnchorValue, MGLTextAnchorLeft); XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorRight].MGLTextAnchorValue, MGLTextAnchorRight); |