diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h index e2b043a729..5409801768 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.h +++ b/platform/darwin/src/MGLCircleStyleLayer.h @@ -120,6 +120,23 @@ MGL_EXPORT */ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source; +#pragma mark - Accessing the Layout Attributes + +/** + Sorts features in ascending order based on this value. Features with a higher + sort key will appear above features with a lower sort key. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *circleSortKey; + #pragma mark - Accessing the Paint Attributes /** diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 6f82d85ce1..bccd7e29fc 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -91,6 +91,26 @@ - (NSPredicate *)predicate return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } +#pragma mark - Accessing the Layout Attributes + +- (void)setCircleSortKey:(NSExpression *)circleSortKey { + MGLAssertStyleLayerIsValid(); + MGLLogDebug(@"Setting circleSortKey: %@", circleSortKey); + + auto mbglValue = MGLStyleValueTransformer().toPropertyValue>(circleSortKey, true); + self.rawLayer->setCircleSortKey(mbglValue); +} + +- (NSExpression *)circleSortKey { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getCircleSortKey(); + if (propertyValue.isUndefined()) { + propertyValue = self.rawLayer->getDefaultCircleSortKey(); + } + return MGLStyleValueTransformer().toExpression(propertyValue); +} + #pragma mark - Accessing the Paint Attributes - (void)setCircleBlur:(NSExpression *)circleBlur { diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.mm b/platform/darwin/test/MGLCircleStyleLayerTests.mm index 5f789f4faf..3222073e86 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.mm +++ b/platform/darwin/test/MGLCircleStyleLayerTests.mm @@ -49,6 +49,75 @@ - (void)testProperties { MGLTransition transitionTest = MGLTransitionMake(5, 4); + // circle-sort-key + { + XCTAssertTrue(rawLayer->getCircleSortKey().isUndefined(), + @"circle-sort-key should be unset initially."); + NSExpression *defaultExpression = layer.circleSortKey; + + NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"]; + layer.circleSortKey = constantExpression; + mbgl::style::PropertyValue propertyValue = { 1.0 }; + XCTAssertEqual(rawLayer->getCircleSortKey(), propertyValue, + @"Setting circleSortKey to a constant value expression should update circle-sort-key."); + XCTAssertEqualObjects(layer.circleSortKey, constantExpression, + @"circleSortKey should round-trip constant value expressions."); + + constantExpression = [NSExpression expressionWithFormat:@"1"]; + NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}]; + layer.circleSortKey = functionExpression; + + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::PropertyExpression( + step(zoom(), literal(1.0), 18.0, literal(1.0)) + ); + } + + XCTAssertEqual(rawLayer->getCircleSortKey(), propertyValue, + @"Setting circleSortKey to a camera expression should update circle-sort-key."); + XCTAssertEqualObjects(layer.circleSortKey, functionExpression, + @"circleSortKey should round-trip camera expressions."); + + functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}]; + layer.circleSortKey = functionExpression; + + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::PropertyExpression( + interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)) + ); + } + + XCTAssertEqual(rawLayer->getCircleSortKey(), propertyValue, + @"Setting circleSortKey to a data expression should update circle-sort-key."); + NSExpression *pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(CAST(keyName, 'NSNumber'), 'linear', nil, %@)", @{@18: constantExpression}]; + XCTAssertEqualObjects(layer.circleSortKey, pedanticFunctionExpression, + @"circleSortKey should round-trip data expressions."); + + functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}]; + layer.circleSortKey = functionExpression; + + { + using namespace mbgl::style::expression::dsl; + propertyValue = mbgl::style::PropertyExpression( + interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))) + ); + } + + XCTAssertEqual(rawLayer->getCircleSortKey(), propertyValue, + @"Setting circleSortKey to a camera-data expression should update circle-sort-key."); + pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}]; + XCTAssertEqualObjects(layer.circleSortKey, pedanticFunctionExpression, + @"circleSortKey should round-trip camera-data expressions."); + + layer.circleSortKey = nil; + XCTAssertTrue(rawLayer->getCircleSortKey().isUndefined(), + @"Unsetting circleSortKey should return circle-sort-key to the default value."); + XCTAssertEqualObjects(layer.circleSortKey, defaultExpression, + @"circleSortKey should return the default value after being unset."); + } + // circle-blur { XCTAssertTrue(rawLayer->getCircleBlur().isUndefined(), @@ -779,6 +848,7 @@ - (void)testProperties { } - (void)testPropertyNames { + [self testPropertyName:@"circle-sort-key" isBoolean:NO]; [self testPropertyName:@"circle-blur" isBoolean:NO]; [self testPropertyName:@"circle-color" isBoolean:NO]; [self testPropertyName:@"circle-opacity" isBoolean:NO]; diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index ff34a959be..1274238951 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -2,6 +2,13 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started. +## 5.9.0 + +* Added the `MGLCircleStyleLayer.circleSortKey` property. ([mapbox/mapbox-gl-native#15875](https://github.com/mapbox/mapbox-gl-native/pull/15875)) +* Fixed a crash when calling the `-[MGLStyle removeImageForName:]` method with the name of a nonexistent image. ([mapbox/mapbox-gl-native#16391](https://github.com/mapbox/mapbox-gl-native/pull/16391)) +* Fixed a crash when encountering an invalid polyline. ([mapbox/mapbox-gl-native#16409](https://github.com/mapbox/mapbox-gl-native/pull/16409)) +* Certain logging statements no longer run on the main thread. ([mapbox/mapbox-gl-native#16325](https://github.com/mapbox/mapbox-gl-native/pull/16325)) + ## 5.8.0 ### Styles and rendering diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 873f382c18..d85f22ac4a 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog for Mapbox Maps SDK for macOS +## 0.16.0 + +* Added the `MGLCircleStyleLayer.circleSortKey` property. ([mapbox/mapbox-gl-native#15875](https://github.com/mapbox/mapbox-gl-native/pull/15875)) +* Fixed a crash when calling the `-[MGLStyle removeImageForName:]` method with the name of a nonexistent image. ([mapbox/mapbox-gl-native#16391](https://github.com/mapbox/mapbox-gl-native/pull/16391)) +* Fixed a crash when encountering an invalid polyline. ([mapbox/mapbox-gl-native#16409](https://github.com/mapbox/mapbox-gl-native/pull/16409)) +* Certain logging statements no longer run on the main thread. ([mapbox/mapbox-gl-native#16325](https://github.com/mapbox/mapbox-gl-native/pull/16325)) + ## 0.15.0 ### Styles and rendering diff --git a/scripts/style-spec.js b/scripts/style-spec.js index 374c3bcb6e..c0f03407b9 100644 --- a/scripts/style-spec.js +++ b/scripts/style-spec.js @@ -1,4 +1 @@ -var spec = module.exports = require('../vendor/mapbox-gl-native/mapbox-gl-js/src/style-spec/reference/v8'); - -// FIXME: https://github.com/mapbox/mapbox-gl-native/issues/15008 -delete spec.layout_circle["circle-sort-key"]; +module.exports = require('../vendor/mapbox-gl-native/mapbox-gl-js/src/style-spec/reference/v8'); diff --git a/vendor/mapbox-gl-native b/vendor/mapbox-gl-native index 77b883d80d..71ce52d35f 160000 --- a/vendor/mapbox-gl-native +++ b/vendor/mapbox-gl-native @@ -1 +1 @@ -Subproject commit 77b883d80d2dee6612e0e3621c32b90adbd85e3e +Subproject commit 71ce52d35f8421c89f6112b83061613937b2836c