[ios, macos] reversed MGLStyle.layers
This commit is contained in:
@@ -237,7 +237,7 @@ static const NSInteger MGLStyleDefaultVersion = 9;
|
||||
#pragma mark Managing Style Layers
|
||||
|
||||
/**
|
||||
The layers included in the style, arranged according to their front-to-back
|
||||
The layers included in the style, arranged according to their back-to-front
|
||||
ordering on the screen.
|
||||
*/
|
||||
@property (nonatomic, strong) NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *layers;
|
||||
|
||||
@@ -226,18 +226,18 @@ static NSURL *MGLStyleURL_emerald;
|
||||
{
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
NSMutableArray *styleLayers = [NSMutableArray arrayWithCapacity:layers.size()];
|
||||
for (auto layer = layers.rbegin(); layer != layers.rend(); ++layer) {
|
||||
MGLStyleLayer *styleLayer = [self layerFromMBGLLayer:*layer];
|
||||
for (auto layer : layers) {
|
||||
MGLStyleLayer *styleLayer = [self layerFromMBGLLayer:layer];
|
||||
[styleLayers addObject:styleLayer];
|
||||
}
|
||||
return styleLayers;
|
||||
}
|
||||
|
||||
- (void)setLayers:(NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *)layers {
|
||||
for (MGLStyleLayer *layer in self.layers.reverseObjectEnumerator) {
|
||||
for (MGLStyleLayer *layer in self.layers) {
|
||||
[self removeLayer:layer];
|
||||
}
|
||||
for (MGLStyleLayer *layer in layers.reverseObjectEnumerator) {
|
||||
for (MGLStyleLayer *layer in layers) {
|
||||
[self addLayer:layer];
|
||||
}
|
||||
}
|
||||
@@ -250,12 +250,12 @@ static NSURL *MGLStyleURL_emerald;
|
||||
- (MGLStyleLayer *)objectInLayersAtIndex:(NSUInteger)index
|
||||
{
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
if (index > layers.size() - 1) {
|
||||
if (index >= layers.size()) {
|
||||
[NSException raise:NSRangeException
|
||||
format:@"No style layer at index %lu.", (unsigned long)index];
|
||||
return nil;
|
||||
}
|
||||
auto layer = layers.at(layers.size() - 1 - index);
|
||||
auto layer = layers.at(index);
|
||||
return [self layerFromMBGLLayer:layer];
|
||||
}
|
||||
|
||||
@@ -287,13 +287,14 @@ static NSURL *MGLStyleURL_emerald;
|
||||
format:@"Cannot insert style layer at out-of-bounds index %lu.", (unsigned long)index];
|
||||
} else if (index == 0) {
|
||||
try {
|
||||
[styleLayer addToMapView:self.mapView belowLayer:nil];
|
||||
MGLStyleLayer *sibling = layers.size() ? [self layerFromMBGLLayer:layers.at(0)] : nil;
|
||||
[styleLayer addToMapView:self.mapView belowLayer:sibling];
|
||||
} catch (const std::runtime_error & err) {
|
||||
[NSException raise:@"MGLRedundantLayerIdentifierException" format:@"%s", err.what()];
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(layers.size() - index)];
|
||||
MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(index)];
|
||||
[styleLayer addToMapView:self.mapView belowLayer:sibling];
|
||||
} catch (std::runtime_error & err) {
|
||||
[NSException raise:@"MGLRedundantLayerIdentifierException" format:@"%s", err.what()];
|
||||
@@ -304,11 +305,11 @@ static NSURL *MGLStyleURL_emerald;
|
||||
- (void)removeObjectFromLayersAtIndex:(NSUInteger)index
|
||||
{
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
if (index > layers.size() - 1) {
|
||||
if (index >= layers.size()) {
|
||||
[NSException raise:NSRangeException
|
||||
format:@"Cannot remove style layer at out-of-bounds index %lu.", (unsigned long)index];
|
||||
}
|
||||
auto layer = layers.at(layers.size() - 1 - index);
|
||||
auto layer = layers.at(index);
|
||||
MGLStyleLayer *styleLayer = [self layerFromMBGLLayer:layer];
|
||||
[styleLayer removeFromMapView:self.mapView];
|
||||
}
|
||||
|
||||
@@ -217,4 +217,36 @@
|
||||
XCTAssertEqual(image.size.height, styleImage.size.height);
|
||||
}
|
||||
|
||||
- (void)testLayersOrder {
|
||||
[self.mapView setStyleURL:[MGLStyle streetsStyleURLWithVersion:8]];
|
||||
|
||||
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"];
|
||||
NSURL *url = [NSURL fileURLWithPath:filePath];
|
||||
MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil];
|
||||
[self.mapView.style addSource:source];
|
||||
|
||||
MGLCircleStyleLayer *layer1 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer1" source:source];
|
||||
[self.mapView.style addLayer:layer1];
|
||||
|
||||
MGLCircleStyleLayer *layer3 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer3" source:source];
|
||||
[self.mapView.style addLayer:layer3];
|
||||
|
||||
MGLCircleStyleLayer *layer2 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer2" source:source];
|
||||
[self.mapView.style insertLayer:layer2 aboveLayer:layer1];
|
||||
|
||||
MGLCircleStyleLayer *layer4 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer4" source:source];
|
||||
[self.mapView.style insertLayer:layer4 aboveLayer:layer3];
|
||||
|
||||
MGLCircleStyleLayer *layer0 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer0" source:source];
|
||||
[self.mapView.style insertLayer:layer0 belowLayer:layer1];
|
||||
|
||||
NSArray<MGLStyleLayer *> *layers = [self.mapView.style layers];
|
||||
|
||||
XCTAssert([[layers[0] identifier] isEqualToString:layer0.identifier]);
|
||||
XCTAssert([[layers[1] identifier] isEqualToString:layer1.identifier]);
|
||||
XCTAssert([[layers[2] identifier] isEqualToString:layer2.identifier]);
|
||||
XCTAssert([[layers[3] identifier] isEqualToString:layer3.identifier]);
|
||||
XCTAssert([[layers[4] identifier] isEqualToString:layer4.identifier]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user