diff options
author | Jesse Bounds <jesse@rebounds.net> | 2017-02-21 10:30:21 -0800 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2017-02-23 15:07:43 -0800 |
commit | 7d9018093a61d327fa7ca1312845d2a00d928380 (patch) | |
tree | 637838ca9eacda6338c9207c317d0942ed5b2fe4 /platform/darwin/src/MGLShapeSource.mm | |
parent | d1f444d63ed8048ec9b95e72ba4c72c3394e8379 (diff) | |
download | qtlocation-mapboxgl-7d9018093a61d327fa7ca1312845d2a00d928380.tar.gz |
[ios, macos] Make source removal consistent with layer removal
This refactors the source removal methods to make them consistent
with the way layers are removed. This makes removal of nonexistent
sources and removal of sources of a different type but same
identifier as a previously added source a no-ops.
As with layers, the check at the top of the method to ensure that the
raw pointer is the same as the one in mbgl for the same
identifier string should make it impossible to attempt to remove
a source of a different type than the one in mbgl for the same
identifier. However, for consistency with the layer implementation,
the reinterpret_cast has been replaced with a dynamic_cast and check
for nullptr.
Diffstat (limited to 'platform/darwin/src/MGLShapeSource.mm')
-rw-r--r-- | platform/darwin/src/MGLShapeSource.mm | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index d7d26ba36d..b37b01663f 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -86,12 +86,21 @@ const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLSh } - (void)removeFromMapView:(MGLMapView *)mapView { + if (self.rawSource != mapView.mbglMap->getSource(self.identifier.UTF8String)) { + return; + } + auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); - if (removedSource) { - _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::GeoJSONSource> &>(removedSource)); - self.rawSource = _pendingSource.get(); + mbgl::style::GeoJSONSource *source = dynamic_cast<mbgl::style::GeoJSONSource *>(removedSource.get()); + if (!source) { + return; } + + removedSource.release(); + + _pendingSource = std::unique_ptr<mbgl::style::GeoJSONSource>(source); + self.rawSource = _pendingSource.get(); } - (mbgl::style::GeoJSONSource *)rawSource { |