Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLBackgroundStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ - (instancetype)initWithIdentifier:(NSString *)identifier

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingLayer == nullptr) {
[NSException raise:@"MGLRedundantLayerException"
format:@"This instance %@ was already added to %@. Adding the same layer instance " \
"to the style more than once is invalid.", self, mapView.style];
}

[self addToMapView:mapView belowLayer:nil];
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLCircleStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ - (NSPredicate *)predicate

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingLayer == nullptr) {
[NSException raise:@"MGLRedundantLayerException"
format:@"This instance %@ was already added to %@. Adding the same layer instance " \
"to the style more than once is invalid.", self, mapView.style];
}

[self addToMapView:mapView belowLayer:nil];
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLFillStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ - (NSPredicate *)predicate

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingLayer == nullptr) {
[NSException raise:@"MGLRedundantLayerException"
format:@"This instance %@ was already added to %@. Adding the same layer instance " \
"to the style more than once is invalid.", self, mapView.style];
}

[self addToMapView:mapView belowLayer:nil];
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLGeoJSONSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ - (instancetype)initWithIdentifier:(NSString *)identifier features:(NSArray<id<M

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingSource == nullptr) {
[NSException raise:@"MGLRedundantSourceException"
format:@"This instance %@ was already added to %@. Adding the same source instance " \
"to the style more than once is invalid.", self, mapView.style];
}

mapView.mbglMap->addSource(std::move(_pendingSource));
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLLineStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ - (NSPredicate *)predicate

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingLayer == nullptr) {
[NSException raise:@"MGLRedundantLayerException"
format:@"This instance %@ was already added to %@. Adding the same layer instance " \
"to the style more than once is invalid.", self, mapView.style];
}

[self addToMapView:mapView belowLayer:nil];
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLRasterSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ - (void)commonInit

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingSource == nullptr) {
[NSException raise:@"MGLRedundantSourceException"
format:@"This instance %@ was already added to %@. Adding the same source instance " \
"to the style more than once is invalid.", self, mapView.style];
}

mapView.mbglMap->addSource(std::move(_pendingSource));
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLRasterStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingLayer == nullptr) {
[NSException raise:@"MGLRedundantLayerException"
format:@"This instance %@ was already added to %@. Adding the same layer instance " \
"to the style more than once is invalid.", self, mapView.style];
}

[self addToMapView:mapView belowLayer:nil];
}

Expand Down
21 changes: 21 additions & 0 deletions platform/darwin/src/MGLStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ static const NSInteger MGLStyleDefaultVersion = 9;

/**
Adds a new source to the current style.

@note Adding the same source instance more than once will result in a
`MGLRedundantSourceException`. Reusing the same source identifier, even with
different source instances, will result in a
`MGLRedundantSourceIdentiferException`.

@param source The source to add to the current style.
*/
Expand Down Expand Up @@ -247,6 +252,10 @@ static const NSInteger MGLStyleDefaultVersion = 9;
/**
Adds a new layer on top of existing layers.

@note Adding the same layer instance more than once will result in a
`MGLRedundantLayerException`. Reusing the same layer identifer, even with
different layer instances, will also result in an exception.

@param layer The layer object to add to the map view. This object must be an
instance of a concrete subclass of `MGLStyleLayer`.
*/
Expand All @@ -255,6 +264,10 @@ static const NSInteger MGLStyleDefaultVersion = 9;
/**
Inserts a new layer into the style at the given index.

@note Adding the same layer instance more than once will result in a
`MGLRedundantLayerException`. Reusing the same layer identifer, even with
different layer instances, will also result in an exception.

@param layer The layer to insert.
@param index The index at which to insert the layer. An index of 0 would send
the layer to the back; an index equal to the number of objects in the
Expand All @@ -272,6 +285,10 @@ static const NSInteger MGLStyleDefaultVersion = 9;
inspectable in Interface Builder, or a manually constructed `NSURL`. This
approach also avoids layer identifer name changes that will occur in the default
style’s layers over time.

Inserting the same layer instance more than once will result in a
`MGLRedundantLayerException`. Reusing the same layer identifer, even with
different layer instances, will also result in an exception.

@param layer The layer to insert.
@param sibling An existing layer in the style.
Expand All @@ -288,6 +305,10 @@ static const NSInteger MGLStyleDefaultVersion = 9;
inspectable in Interface Builder, or a manually constructed `NSURL`. This
approach also avoids layer identifer name changes that will occur in the default
style’s layers over time.

Inserting the same layer instance more than once will result in a
`MGLRedundantLayerException`. Reusing the same layer identifer, even with
different layer instances, will also result in an exception.

@param layer The layer to insert.
@param sibling An existing layer in the style.
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ - (void)addSource:(MGLSource *)source
try {
[source addToMapView:self.mapView];
} catch (std::runtime_error & err) {
[NSException raise:@"Could not add source" format:@"%s", err.what()];
[NSException raise:@"MGLRedundantSourceIdentiferException" format:@"%s", err.what()];
}
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLStyleLayer.mm.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ namespace mbgl {

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingLayer == nullptr) {
[NSException raise:@"MGLRedundantLayerException"
format:@"This instance %@ was already added to %@. Adding the same layer instance " \
"to the style more than once is invalid.", self, mapView.style];
}

[self addToMapView:mapView belowLayer:nil];
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLSymbolStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ - (NSPredicate *)predicate

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingLayer == nullptr) {
[NSException raise:@"MGLRedundantLayerException"
format:@"This instance %@ was already added to %@. Adding the same layer instance " \
"to the style more than once is invalid.", self, mapView.style];
}

[self addToMapView:mapView belowLayer:nil];
}

Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLVectorSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ - (void)commonInit

- (void)addToMapView:(MGLMapView *)mapView
{
if (_pendingSource == nullptr) {
[NSException raise:@"MGLRedundantSourceException"
format:@"This instance %@ was already added to %@. Adding the same source instance " \
"to the style more than once is invalid.", self, mapView.style];
}

mapView.mbglMap->addSource(std::move(_pendingSource));
}

Expand Down
75 changes: 74 additions & 1 deletion platform/darwin/test/MGLStyleTests.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#import "MGLStyle.h"
#import "MGLMapView.h"
#import "MGLStyle_Private.h"

#import "MGLGeoJSONSource.h"
#import "MGLRasterSource.h"
#import "MGLVectorSource.h"

#import "MGLBackgroundStyleLayer.h"
#import "MGLCircleStyleLayer.h"
#import "MGLFillStyleLayer.h"
#import "MGLLineStyleLayer.h"
#import "MGLRasterStyleLayer.h"
#import "MGLSymbolStyleLayer.h"

#import "NSBundle+MGLAdditions.h"

Expand All @@ -8,10 +20,21 @@
#import <objc/runtime.h>

@interface MGLStyleTests : XCTestCase

@property (nonatomic) MGLMapView *mapView;
@property (nonatomic) MGLStyle *style;

@end

@implementation MGLStyleTests

- (void)setUp {
[super setUp];

self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
self.style = [[MGLStyle alloc] initWithMapView:self.mapView];
}

- (void)testUnversionedStyleURLs {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Expand Down Expand Up @@ -92,6 +115,56 @@ - (void)testStyleURLDeclarations {
}];
}

- (void)testAddingSourcesTwice {
MGLGeoJSONSource *geoJSONSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil];
[self.style addSource:geoJSONSource];
XCTAssertThrowsSpecificNamed([self.style addSource:geoJSONSource], NSException, @"MGLRedundantSourceException");

MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"rasterSource" URL:[NSURL new] tileSize:42];
[self.style addSource:rasterSource];
XCTAssertThrowsSpecificNamed([self.style addSource:rasterSource], NSException, @"MGLRedundantSourceException");

MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vectorSource" URL:[NSURL new]];
[self.style addSource:vectorSource];
XCTAssertThrowsSpecificNamed([self.style addSource:vectorSource], NSException, @"MGLRedundantSourceException");
}

- (void)testAddingSourcesWithDuplicateIdentifiers {
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.style addSource: source1];
XCTAssertThrowsSpecificNamed([self.style addSource: source2], NSException, @"MGLRedundantSourceIdentiferException");
}

- (void)testAddingLayersTwice {
MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil];

MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"backgroundLayer"];
[self.style addLayer:backgroundLayer];
XCTAssertThrowsSpecificNamed([self.style addLayer:backgroundLayer], NSException, @"MGLRedundantLayerException");

MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circleLayer" source:source];
[self.style addLayer:circleLayer];
XCTAssertThrowsSpecificNamed([self.style addLayer:circleLayer], NSException, @"MGLRedundantLayerException");

MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fillLayer" source:source];
[self.style addLayer:fillLayer];
XCTAssertThrowsSpecificNamed([self.style addLayer:fillLayer], NSException, @"MGLRedundantLayerException");

MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"lineLayer" source:source];
[self.style addLayer:lineLayer];
XCTAssertThrowsSpecificNamed([self.style addLayer:lineLayer], NSException, @"MGLRedundantLayerException");

MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"rasterLayer" source:source];
[self.style addLayer:rasterLayer];
XCTAssertThrowsSpecificNamed([self.style addLayer:rasterLayer], NSException, @"MGLRedundantLayerException");

MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbolLayer" source:source];
[self.style addLayer:symbolLayer];
XCTAssertThrowsSpecificNamed([self.style addLayer:symbolLayer], NSException, @"MGLRedundantLayerException");
}

- (NSString *)stringWithContentsOfStyleHeader {
NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL
URLByAppendingPathComponent:@"Headers" isDirectory:YES]
Expand Down
4 changes: 0 additions & 4 deletions platform/ios/ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
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 */; };
Expand Down Expand Up @@ -596,7 +595,6 @@
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; };
Expand Down Expand Up @@ -902,7 +900,6 @@
children = (
3575798F1D513EF1000B822E /* Layers */,
35B8E08B1D6C8B5100E768D2 /* MGLFilterTests.mm */,
92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */,
DA2207BE1DC0805F0002F84D /* MGLStyleValueTests.swift */,
40CFA64E1D78754A008103BD /* Sources */,
DA2207BD1DC0805F0002F84D /* test-Bridging-Header.h */,
Expand Down Expand Up @@ -1916,7 +1913,6 @@
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;
Expand Down
24 changes: 0 additions & 24 deletions platform/ios/test/MGLSourceTests.m

This file was deleted.