summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLStyle.mm
diff options
context:
space:
mode:
authorfabian-guerra <fabian.guerra@gmail.com>2016-11-04 15:20:01 -0700
committerGitHub <noreply@github.com>2016-11-04 15:20:01 -0700
commit373904e822bfb13acc8015987497d43507eb5b2a (patch)
tree962848d03ea1bb4a50df20333cf40d2cac0030ca /platform/darwin/src/MGLStyle.mm
parent4e8121aaf1037f2e927ba80d4da85ebe3eef5060 (diff)
downloadqtlocation-mapboxgl-373904e822bfb13acc8015987497d43507eb5b2a.tar.gz
[ios, macos] Layer ownership refactor (#6904)
`MGLStyleLayer` was updated to support a raw pointer to the mbgl object, which is always initialized, either to the value returned by `mbgl::Map getLayer`, or for independently created objects, to the pointer value held in `pendingLayer`. In the latter case, this raw pointer value stays even after ownership of the object is transferred via `mbgl::Map addLayer`.
Diffstat (limited to 'platform/darwin/src/MGLStyle.mm')
-rw-r--r--platform/darwin/src/MGLStyle.mm14
1 files changed, 6 insertions, 8 deletions
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index a17b7d6b74..d59194725b 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -134,7 +134,7 @@ static NSURL *MGLStyleURL_emerald;
return nil;
}
- styleLayer.layer = mbglLayer;
+ styleLayer.rawLayer = mbglLayer;
return styleLayer;
}
@@ -173,26 +173,25 @@ static NSURL *MGLStyleURL_emerald;
- (void)addLayer:(MGLStyleLayer *)layer
{
- if (!layer.layer) {
+ if (!layer.rawLayer) {
[NSException raise:NSInvalidArgumentException format:
@"The style layer %@ cannot be added to the style. "
@"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
layer];
}
-
- self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer));
+ [layer addToMapView:self.mapView];
}
- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer
{
- if (!layer.layer) {
+ if (!layer.rawLayer) {
[NSException raise:NSInvalidArgumentException
format:
@"The style layer %@ cannot be added to the style. "
@"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
layer];
}
- if (!otherLayer.layer) {
+ if (!otherLayer.rawLayer) {
[NSException raise:NSInvalidArgumentException
format:
@"A style layer cannot be placed before %@ in the style. "
@@ -200,8 +199,7 @@ static NSURL *MGLStyleURL_emerald;
otherLayer];
}
- const mbgl::optional<std::string> belowLayerId{otherLayer.identifier.UTF8String};
- self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer), belowLayerId);
+ [layer addToMapView:self.mapView belowLayer:otherLayer];
}
- (void)addSource:(MGLSource *)source