summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLFillStyleLayer.mm
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-11-14 15:50:33 -0800
committerGitHub <noreply@github.com>2016-11-14 15:50:33 -0800
commit1c9d314236736bf47e33fb95d2b457a5650fc519 (patch)
tree48b610e5bc18be13de161707488d1cb43b950c9d /platform/darwin/src/MGLFillStyleLayer.mm
parent56c2272b7dc261f988c70e0f8cb90ff853932011 (diff)
downloadqtlocation-mapboxgl-1c9d314236736bf47e33fb95d2b457a5650fc519.tar.gz
[ios, macos] Take back source and layer ownership on removal (#7048)
If a source or layer is removed from the style, recapture the unique pointer ownership. This makes it safe to add back sources and layers after they have been removed.
Diffstat (limited to 'platform/darwin/src/MGLFillStyleLayer.mm')
-rw-r--r--platform/darwin/src/MGLFillStyleLayer.mm42
1 files changed, 25 insertions, 17 deletions
diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm
index 1f8b7402d8..5aed779c86 100644
--- a/platform/darwin/src/MGLFillStyleLayer.mm
+++ b/platform/darwin/src/MGLFillStyleLayer.mm
@@ -53,6 +53,31 @@
return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()];
}
+
+#pragma mark - Adding to and removing from a map view
+
+- (void)addToMapView:(MGLMapView *)mapView
+{
+ [self addToMapView:mapView belowLayer:nil];
+}
+
+- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer
+{
+ if (otherLayer) {
+ const mbgl::optional<std::string> belowLayerId{otherLayer.identifier.UTF8String};
+ mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId);
+ } else {
+ mapView.mbglMap->addLayer(std::move(_pendingLayer));
+ }
+}
+
+- (void)removeFromMapView:(MGLMapView *)mapView
+{
+ auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
+ _pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::FillLayer> &>(removedLayer));
+ self.rawLayer = _pendingLayer.get();
+}
+
#pragma mark - Accessing the Paint Attributes
- (void)setFillAntialias:(MGLStyleValue<NSNumber *> *)fillAntialias {
@@ -126,21 +151,4 @@
}
-#pragma mark - Add style layer to map
-
-- (void)addToMapView:(MGLMapView *)mapView
-{
- [self addToMapView:mapView belowLayer:nil];
-}
-
-- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer
-{
- if (otherLayer) {
- const mbgl::optional<std::string> belowLayerId{otherLayer.identifier.UTF8String};
- mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId);
- } else {
- mapView.mbglMap->addLayer(std::move(_pendingLayer));
- }
-}
-
@end