[core, ios, macos] Return null when removing nonexistent source
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"]) {
|
||||
|
||||
@@ -159,7 +159,7 @@ std::unique_ptr<Source> Style::removeSource(const std::string& id) {
|
||||
});
|
||||
|
||||
if (it == sources.end()) {
|
||||
throw std::runtime_error("no such source");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto source = std::move(*it);
|
||||
|
||||
Reference in New Issue
Block a user