summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2016-12-06 11:48:36 +0100
committerJesse Bounds <jesse@rebounds.net>2016-12-13 10:03:05 -0800
commitd3895b47efc28aa63b941de4341c4cb6fd6fb477 (patch)
tree785d499889b4d7439f30948296b76ac40a2462d0 /platform
parentbb6973ae90d91134de168dc75f0d51e3e28c8ae4 (diff)
downloadqtlocation-mapboxgl-d3895b47efc28aa63b941de4341c4cb6fd6fb477.tar.gz
[ios, macos] handle duplicate layer error
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/src/MGLStyle.mm38
-rw-r--r--platform/darwin/test/MGLStyleTests.mm18
2 files changed, 49 insertions, 7 deletions
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index c84782dba9..1e60b956c7 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -287,10 +287,18 @@ static NSURL *MGLStyleURL_emerald;
[NSException raise:NSRangeException
format:@"Cannot insert style layer at out-of-bounds index %lu.", (unsigned long)index];
} else if (index == 0) {
- [styleLayer addToMapView:self.mapView belowLayer:nil];
+ try {
+ [styleLayer addToMapView:self.mapView belowLayer:nil];
+ } catch (const std::runtime_error & err) {
+ [NSException raise:@"MGLRedundantLayerIdentifierException" format:@"%s", err.what()];
+ }
} else {
- MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(layers.size() - index)];
- [styleLayer addToMapView:self.mapView belowLayer:sibling];
+ try {
+ MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(layers.size() - index)];
+ [styleLayer addToMapView:self.mapView belowLayer:sibling];
+ } catch (std::runtime_error & err) {
+ [NSException raise:@"MGLRedundantLayerIdentifierException" format:@"%s", err.what()];
+ }
}
}
@@ -374,7 +382,11 @@ static NSURL *MGLStyleURL_emerald;
layer];
}
[self willChangeValueForKey:@"layers"];
- [layer addToMapView:self.mapView belowLayer:nil];
+ try {
+ [layer addToMapView:self.mapView belowLayer:nil];
+ } catch (std::runtime_error & err) {
+ [NSException raise:@"MGLRedundantLayerIdentifierException" format:@"%s", err.what()];
+ }
[self didChangeValueForKey:@"layers"];
}
@@ -399,7 +411,11 @@ static NSURL *MGLStyleURL_emerald;
sibling];
}
[self willChangeValueForKey:@"layers"];
- [layer addToMapView:self.mapView belowLayer:sibling];
+ try {
+ [layer addToMapView:self.mapView belowLayer:sibling];
+ } catch (std::runtime_error & err) {
+ [NSException raise:@"MGLRedundantLayerIdentifierException" format:@"%s", err.what()];
+ }
[self didChangeValueForKey:@"layers"];
}
@@ -437,10 +453,18 @@ static NSURL *MGLStyleURL_emerald;
@"Make sure sibling was obtained using -[MGLStyle layerWithIdentifier:].",
sibling];
} else if (index + 1 == layers.size()) {
- [layer addToMapView:self.mapView belowLayer:nil];
+ try {
+ [layer addToMapView:self.mapView belowLayer:nil];
+ } catch (std::runtime_error & err) {
+ [NSException raise:@"MGLRedundantLayerIdentifierException" format:@"%s", err.what()];
+ }
} else {
MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(index + 1)];
- [layer addToMapView:self.mapView belowLayer:sibling];
+ try {
+ [layer addToMapView:self.mapView belowLayer:sibling];
+ } catch (std::runtime_error & err) {
+ [NSException raise:@"MGLRedundantLayerIdentifierException" format:@"%s", err.what()];
+ }
}
[self didChangeValueForKey:@"layers"];
}
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index 0dd6e98c5d..7abc88eebc 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -1,5 +1,6 @@
#import "MGLMapView.h"
#import "MGLStyle_Private.h"
+#import "MGLOpenGLStyleLayer.h"
#import "MGLShapeSource.h"
#import "MGLRasterSource.h"
@@ -170,6 +171,23 @@
XCTAssertThrowsSpecificNamed([self.style addLayer:symbolLayer], NSException, @"MGLRedundantLayerException");
}
+- (void)testAddingLayersWithDuplicateIdentifiers {
+ //Just some source
+ MGLVectorSource *source = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
+ [self.mapView.style addSource: source];
+
+ //Add initial layer
+ MGLFillStyleLayer *initial = [[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source];
+ [self.mapView.style addLayer:initial];
+
+ //Try to add the duplicate
+ XCTAssertThrowsSpecificNamed([self.mapView.style addLayer:[[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source]], NSException, @"MGLRedundantLayerIdentifierException");
+ XCTAssertThrowsSpecificNamed([self.mapView.style insertLayer:[[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source] belowLayer:initial],NSException, @"MGLRedundantLayerIdentifierException");
+ XCTAssertThrowsSpecificNamed([self.mapView.style insertLayer:[[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source] aboveLayer:initial], NSException, @"MGLRedundantLayerIdentifierException");
+ XCTAssertThrowsSpecificNamed([self.mapView.style insertLayer:[[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source] atIndex:0], NSException, @"MGLRedundantLayerIdentifierException");
+ XCTAssertThrowsSpecificNamed([self.mapView.style insertLayer:[[MGLOpenGLStyleLayer alloc] initWithIdentifier:@"my-layer"] atIndex:0], NSException, @"MGLRedundantLayerIdentifierException");
+}
+
- (NSString *)stringWithContentsOfStyleHeader {
NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL
URLByAppendingPathComponent:@"Headers" isDirectory:YES]