summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLRasterSource.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLRasterSource.mm')
-rw-r--r--platform/darwin/src/MGLRasterSource.mm17
1 files changed, 14 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm
index fd36413fe0..c73a824ea8 100644
--- a/platform/darwin/src/MGLRasterSource.mm
+++ b/platform/darwin/src/MGLRasterSource.mm
@@ -50,7 +50,7 @@ static const CGFloat MGLRasterSourceRetinaTileSize = 512;
- (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates options:(nullable NS_DICTIONARY_OF(MGLTileSourceOption, id) *)options {
if (self = [super initWithIdentifier:identifier tileURLTemplates:tileURLTemplates options:options]) {
mbgl::Tileset tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, options);
-
+
uint16_t tileSize = MGLRasterSourceRetinaTileSize;
if (NSNumber *tileSizeNumber = options[MGLTileSourceOptionTileSize]) {
if (![tileSizeNumber isKindOfClass:[NSNumber class]]) {
@@ -59,7 +59,7 @@ static const CGFloat MGLRasterSourceRetinaTileSize = 512;
}
tileSize = static_cast<uint16_t>(round(tileSizeNumber.doubleValue));
}
-
+
auto source = std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String, tileSet, tileSize);
_pendingSource = std::move(source);
self.rawSource = _pendingSource.get();
@@ -82,9 +82,20 @@ static const CGFloat MGLRasterSourceRetinaTileSize = 512;
}
- (void)removeFromMapView:(MGLMapView *)mapView {
+ if (self.rawSource != mapView.mbglMap->getSource(self.identifier.UTF8String)) {
+ return;
+ }
+
auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String);
- _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::RasterSource> &>(removedSource));
+ mbgl::style::RasterSource *source = dynamic_cast<mbgl::style::RasterSource *>(removedSource.get());
+ if (!source) {
+ return;
+ }
+
+ removedSource.release();
+
+ _pendingSource = std::unique_ptr<mbgl::style::RasterSource>(source);
self.rawSource = _pendingSource.get();
}