diff options
author | ryanhamley <ryan.hamley@mapbox.com> | 2018-08-30 17:18:29 -0700 |
---|---|---|
committer | ryanhamley <ryan.hamley@mapbox.com> | 2018-09-07 13:05:19 -0700 |
commit | 31cca05fc6a9d08d3b0028149f7ef2f2348b18e9 (patch) | |
tree | 0fc6980686269d0deade28823be33bf9446610a7 /platform/darwin | |
parent | 79bf0e8af6bf9ec829a352d56b8e70ccc8f4fa41 (diff) | |
download | qtlocation-mapboxgl-31cca05fc6a9d08d3b0028149f7ef2f2348b18e9.tar.gz |
Port symbol-z-order symbol layout style-spec property to Nativeupstream/sort-by-y
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/scripts/style-spec-overrides-v8.json | 10 | ||||
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.h | 59 | ||||
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.mm | 32 | ||||
-rw-r--r-- | platform/darwin/test/MGLSymbolStyleLayerTests.mm | 47 |
4 files changed, 148 insertions, 0 deletions
diff --git a/platform/darwin/scripts/style-spec-overrides-v8.json b/platform/darwin/scripts/style-spec-overrides-v8.json index d47b13cdb2..0c787cd96e 100644 --- a/platform/darwin/scripts/style-spec-overrides-v8.json +++ b/platform/darwin/scripts/style-spec-overrides-v8.json @@ -39,6 +39,16 @@ } }, "layout_symbol": { + "symbol-z-order": { + "values": { + "viewport-y": { + "doc": "Specify this z order if symbols’ appearance relies on lower features overlapping higher features. For example, symbols with a pin-like appearance would require this z order." + }, + "source": { + "doc": "Specify this z order if the order in which features appear in the source is significant." + } + } + }, "icon-text-fit-padding": { "doc": "Size of the additional area added to dimensions determined by `icon-text-fit`." }, diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index afaea9a74f..363f9efee7 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -151,6 +151,26 @@ typedef NS_ENUM(NSUInteger, MGLSymbolPlacement) { }; /** + Controls the order in which overlapping symbols in the same layer are rendered + + Values of this type are used in the `MGLSymbolStyleLayer.symbolZOrder` + property. + */ +typedef NS_ENUM(NSUInteger, MGLSymbolZOrder) { + /** + Specify this z order if symbols’ appearance relies on lower features + overlapping higher features. For example, symbols with a pin-like + appearance would require this z order. + */ + MGLSymbolZOrderViewportY, + /** + Specify this z order if the order in which features appear in the source is + significant. + */ + MGLSymbolZOrderSource, +}; + +/** Part of the text placed closest to the anchor. Values of this type are used in the `MGLSymbolStyleLayer.textAnchor` @@ -1005,6 +1025,32 @@ MGL_EXPORT @property (nonatomic, null_resettable) NSExpression *symbolSpacing; /** + Controls the order in which overlapping symbols in the same layer are rendered + + The default value of this property is an expression that evaluates to + `viewport-y`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant `MGLSymbolZOrder` values + * Any of the following constant string values: + * `viewport-y`: Specify this z order if symbols’ appearance relies on lower + features overlapping higher features. For example, symbols with a pin-like + appearance would require this z order. + * `source`: Specify this z order if the order in which features appear in the + source is significant. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. + */ +@property (nonatomic, null_resettable) NSExpression *symbolZOrder; + +/** Value to use for a text label. Within a constant string value, a feature attribute name enclosed in curly @@ -2141,6 +2187,19 @@ MGL_EXPORT @property (readonly) MGLSymbolPlacement MGLSymbolPlacementValue; /** + Creates a new value object containing the given `MGLSymbolZOrder` enumeration. + + @param symbolZOrder The value for the new object. + @return A new value object that contains the enumeration value. + */ ++ (instancetype)valueWithMGLSymbolZOrder:(MGLSymbolZOrder)symbolZOrder; + +/** + The `MGLSymbolZOrder` enumeration representation of the value. + */ +@property (readonly) MGLSymbolZOrder MGLSymbolZOrderValue; + +/** Creates a new value object containing the given `MGLTextAnchor` enumeration. @param textAnchor The value for the new object. diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index ad023a1a03..4c0fcfe539 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -50,6 +50,11 @@ namespace mbgl { { MGLSymbolPlacementLineCenter, "line-center" }, }); + MBGL_DEFINE_ENUM(MGLSymbolZOrder, { + { MGLSymbolZOrderViewportY, "viewport-y" }, + { MGLSymbolZOrderSource, "source" }, + }); + MBGL_DEFINE_ENUM(MGLTextAnchor, { { MGLTextAnchorCenter, "center" }, { MGLTextAnchorLeft, "left" }, @@ -573,6 +578,23 @@ namespace mbgl { return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } +- (void)setSymbolZOrder:(NSExpression *)symbolZOrder { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<mbgl::style::SymbolZOrderType, NSValue *, mbgl::style::SymbolZOrderType, MGLSymbolZOrder>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::SymbolZOrderType>>(symbolZOrder, false); + self.rawLayer->setSymbolZOrder(mbglValue); +} + +- (NSExpression *)symbolZOrder { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getSymbolZOrder(); + if (propertyValue.isUndefined()) { + propertyValue = self.rawLayer->getDefaultSymbolZOrder(); + } + return MGLStyleValueTransformer<mbgl::style::SymbolZOrderType, NSValue *, mbgl::style::SymbolZOrderType, MGLSymbolZOrder>().toExpression(propertyValue); +} + - (void)setText:(NSExpression *)text { MGLAssertStyleLayerIsValid(); @@ -1440,6 +1462,16 @@ namespace mbgl { return symbolPlacement; } ++ (NSValue *)valueWithMGLSymbolZOrder:(MGLSymbolZOrder)symbolZOrder { + return [NSValue value:&symbolZOrder withObjCType:@encode(MGLSymbolZOrder)]; +} + +- (MGLSymbolZOrder)MGLSymbolZOrderValue { + MGLSymbolZOrder symbolZOrder; + [self getValue:&symbolZOrder]; + return symbolZOrder; +} + + (NSValue *)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor { return [NSValue value:&textAnchor withObjCType:@encode(MGLTextAnchor)]; } diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index 5c108a1ac3..865de68933 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -1044,6 +1044,50 @@ XCTAssertThrowsSpecificNamed(layer.symbolSpacing = functionExpression, NSException, NSInvalidArgumentException, @"MGLSymbolLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); } + // symbol-z-order + { + XCTAssertTrue(rawLayer->getSymbolZOrder().isUndefined(), + @"symbol-z-order should be unset initially."); + NSExpression *defaultExpression = layer.symbolZOrder; + + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'source'"]; + layer.symbolZOrder = constantExpression; + mbgl::style::PropertyValue<mbgl::style::SymbolZOrderType> propertyValue = { mbgl::style::SymbolZOrderType::Source }; + XCTAssertEqual(rawLayer->getSymbolZOrder(), propertyValue, + @"Setting symbolZOrder to a constant value expression should update symbol-z-order."); + XCTAssertEqualObjects(layer.symbolZOrder, constantExpression, + @"symbolZOrder should round-trip constant value expressions."); + + constantExpression = [NSExpression expressionWithFormat:@"'source'"]; + NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; + layer.symbolZOrder = functionExpression; + + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::PropertyExpression<mbgl::style::SymbolZOrderType>( + step(zoom(), literal("source"), 18.0, literal("source")) + ); + } + + XCTAssertEqual(rawLayer->getSymbolZOrder(), propertyValue, + @"Setting symbolZOrder to a camera expression should update symbol-z-order."); + XCTAssertEqualObjects(layer.symbolZOrder, functionExpression, + @"symbolZOrder should round-trip camera expressions."); + + + layer.symbolZOrder = nil; + XCTAssertTrue(rawLayer->getSymbolZOrder().isUndefined(), + @"Unsetting symbolZOrder should return symbol-z-order to the default value."); + XCTAssertEqualObjects(layer.symbolZOrder, defaultExpression, + @"symbolZOrder should return the default value after being unset."); + + functionExpression = [NSExpression expressionForKeyPath:@"bogus"]; + XCTAssertThrowsSpecificNamed(layer.symbolZOrder = functionExpression, NSException, NSInvalidArgumentException, @"MGLSymbolLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); + functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:(bogus, %@, %@)", constantExpression, @{@18: constantExpression}]; + functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; + XCTAssertThrowsSpecificNamed(layer.symbolZOrder = functionExpression, NSException, NSInvalidArgumentException, @"MGLSymbolLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); + } + // text-field { XCTAssertTrue(rawLayer->getTextField().isUndefined(), @@ -2829,6 +2873,7 @@ [self testPropertyName:@"symbol-avoids-edges" isBoolean:YES]; [self testPropertyName:@"symbol-placement" isBoolean:NO]; [self testPropertyName:@"symbol-spacing" isBoolean:NO]; + [self testPropertyName:@"symbol-z-order" isBoolean:NO]; [self testPropertyName:@"text" isBoolean:NO]; [self testPropertyName:@"text-allows-overlap" isBoolean:YES]; [self testPropertyName:@"text-anchor" isBoolean:NO]; @@ -2884,6 +2929,8 @@ XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementPoint].MGLSymbolPlacementValue, MGLSymbolPlacementPoint); XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementLine].MGLSymbolPlacementValue, MGLSymbolPlacementLine); XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementLineCenter].MGLSymbolPlacementValue, MGLSymbolPlacementLineCenter); + XCTAssertEqual([NSValue valueWithMGLSymbolZOrder:MGLSymbolZOrderViewportY].MGLSymbolZOrderValue, MGLSymbolZOrderViewportY); + XCTAssertEqual([NSValue valueWithMGLSymbolZOrder:MGLSymbolZOrderSource].MGLSymbolZOrderValue, MGLSymbolZOrderSource); XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorCenter].MGLTextAnchorValue, MGLTextAnchorCenter); XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorLeft].MGLTextAnchorValue, MGLTextAnchorLeft); XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorRight].MGLTextAnchorValue, MGLTextAnchorRight); |