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/src | |
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/src')
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.h | 59 | ||||
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.mm | 32 |
2 files changed, 91 insertions, 0 deletions
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)]; } |