diff options
author | Jesse Bounds <jesse@rebounds.net> | 2017-02-20 15:06:46 -0800 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2017-02-23 15:07:43 -0800 |
commit | c0718a863d0a915641857bc9cd4ff51cd508f222 (patch) | |
tree | 0d63485afba44e45d4dbb21492d25a36591f7089 /platform | |
parent | e860fa6f0a71805dafd03a1ac02980369b799f9e (diff) | |
download | qtlocation-mapboxgl-c0718a863d0a915641857bc9cd4ff51cd508f222.tar.gz |
[core, ios, macos] Return null when removing nonexistent source
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/src/MGLRasterSource.mm | 6 | ||||
-rw-r--r-- | platform/darwin/src/MGLShapeSource.mm | 6 | ||||
-rw-r--r-- | platform/darwin/src/MGLVectorSource.mm | 6 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleTests.mm | 17 |
4 files changed, 29 insertions, 6 deletions
diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm index ccd5212b2a..9f1d035994 100644 --- a/platform/darwin/src/MGLRasterSource.mm +++ b/platform/darwin/src/MGLRasterSource.mm @@ -84,8 +84,10 @@ static const CGFloat MGLRasterSourceRetinaTileSize = 512; - (void)removeFromMapView:(MGLMapView *)mapView { auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); - _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::RasterSource> &>(removedSource)); - self.rawSource = _pendingSource.get(); + if (removedSource) { + _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::RasterSource> &>(removedSource)); + self.rawSource = _pendingSource.get(); + } } - (mbgl::style::RasterSource *)rawSource { diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index 07033d8d45..d7d26ba36d 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -88,8 +88,10 @@ const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLSh - (void)removeFromMapView:(MGLMapView *)mapView { auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); - _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::GeoJSONSource> &>(removedSource)); - self.rawSource = _pendingSource.get(); + if (removedSource) { + _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::GeoJSONSource> &>(removedSource)); + self.rawSource = _pendingSource.get(); + } } - (mbgl::style::GeoJSONSource *)rawSource { diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index a16cfa6d81..840382913d 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -58,8 +58,10 @@ - (void)removeFromMapView:(MGLMapView *)mapView { auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); - _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::VectorSource> &>(removedSource)); - self.rawSource = _pendingSource.get(); + if (removedSource) { + _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::VectorSource> &>(removedSource)); + self.rawSource = _pendingSource.get(); + } } - (mbgl::style::VectorSource *)rawSource { diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 7939db576e..86cf11d4aa 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -174,6 +174,23 @@ XCTAssertThrowsSpecificNamed([self.style addSource: source2], NSException, @"MGLRedundantSourceIdentifierException"); } +- (void)testRemovingSourcesBeforeAddingThem { + MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"raster-source" tileURLTemplates:@[] options:nil]; + [self.style removeSource:rasterSource]; + [self.style addSource:rasterSource]; + XCTAssertNotNil([self.style sourceWithIdentifier:rasterSource.identifier]); + + MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source" shape:nil options:nil]; + [self.style removeSource:shapeSource]; + [self.style addSource:shapeSource]; + XCTAssertNotNil([self.style sourceWithIdentifier:shapeSource.identifier]); + + MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vector-source" tileURLTemplates:@[] options:nil]; + [self.style removeSource:vectorSource]; + [self.style addSource:vectorSource]; + XCTAssertNotNil([self.style sourceWithIdentifier:vectorSource.identifier]); +} + - (void)testLayers { NSArray<MGLStyleLayer *> *initialLayers = self.style.layers; if ([initialLayers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) { |