[ios, macos] handle duplicate source error
This commit is contained in:
committed by
Ivo van Dongen
parent
379bf08723
commit
d8cef78502
@@ -223,7 +223,11 @@ static NSURL *MGLStyleURL_emerald;
|
||||
source];
|
||||
}
|
||||
|
||||
[source addToMapView:self.mapView];
|
||||
try {
|
||||
[source addToMapView:self.mapView];
|
||||
} catch (std::runtime_error & err) {
|
||||
[NSException raise:@"Could not add source" format:@"%s", err.what()];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeSource:(MGLSource *)source
|
||||
|
||||
@@ -161,6 +161,7 @@
|
||||
7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; };
|
||||
7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; };
|
||||
7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; };
|
||||
92BE56771DEDD44500A4F2B6 /* MGLSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */; };
|
||||
DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; };
|
||||
DA17BE301CC4BAC300402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; };
|
||||
DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; };
|
||||
@@ -584,6 +585,7 @@
|
||||
7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = "<group>"; };
|
||||
7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = "<group>"; };
|
||||
7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = "<group>"; };
|
||||
92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLSourceTests.m; sourceTree = "<group>"; };
|
||||
DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = "<group>"; };
|
||||
DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Private.h; sourceTree = "<group>"; };
|
||||
DA1DC94A1CB6C1C2006E619F /* Mapbox GL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mapbox GL.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -890,6 +892,7 @@
|
||||
children = (
|
||||
3575798F1D513EF1000B822E /* Layers */,
|
||||
35B8E08B1D6C8B5100E768D2 /* MGLFilterTests.mm */,
|
||||
92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */,
|
||||
DA2207BE1DC0805F0002F84D /* MGLStyleValueTests.swift */,
|
||||
40CFA64E1D78754A008103BD /* Sources */,
|
||||
DA2207BD1DC0805F0002F84D /* test-Bridging-Header.h */,
|
||||
@@ -1899,6 +1902,7 @@
|
||||
357579831D502AE6000B822E /* MGLRasterStyleLayerTests.m in Sources */,
|
||||
353D23961D0B0DFE002BE09D /* MGLAnnotationViewTests.m in Sources */,
|
||||
35E208A71D24210F00EC9A46 /* MGLNSDataAdditionsTests.m in Sources */,
|
||||
92BE56771DEDD44500A4F2B6 /* MGLSourceTests.m in Sources */,
|
||||
DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
||||
24
platform/ios/test/MGLSourceTests.m
Normal file
24
platform/ios/test/MGLSourceTests.m
Normal file
@@ -0,0 +1,24 @@
|
||||
#import "MGLMapViewTests.h"
|
||||
|
||||
@interface MGLSourceTests : MGLMapViewTests
|
||||
|
||||
@end
|
||||
|
||||
@implementation MGLSourceTests
|
||||
|
||||
- (void)testDuplicateSources {
|
||||
MGLVectorSource *source1 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
|
||||
MGLVectorSource *source2 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
|
||||
|
||||
[self.mapView.style addSource: source1];
|
||||
|
||||
@try {
|
||||
[self.mapView.style addSource: source2];
|
||||
XCTFail(@"Should not have reached this point");
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
XCTAssertNotNil(e, @"Should have thrown an exception");
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user