diff options
author | Jesse Bounds <jesse@rebounds.net> | 2017-02-14 13:09:49 -0800 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2017-02-23 15:07:43 -0800 |
commit | e860fa6f0a71805dafd03a1ac02980369b799f9e (patch) | |
tree | 812de69002c34a728a6b4a2beddcff5a28542702 /platform | |
parent | 76b3825360843f3270549a02aca96f9f11892aa1 (diff) | |
download | qtlocation-mapboxgl-e860fa6f0a71805dafd03a1ac02980369b799f9e.tar.gz |
[ios, macos] Recreate pending and raw layer ref when layer is removed
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/src/MGLBackgroundStyleLayer.mm | 6 | ||||
-rw-r--r-- | platform/darwin/src/MGLCircleStyleLayer.mm | 7 | ||||
-rw-r--r-- | platform/darwin/src/MGLFillStyleLayer.mm | 7 | ||||
-rw-r--r-- | platform/darwin/src/MGLLineStyleLayer.mm | 7 | ||||
-rw-r--r-- | platform/darwin/src/MGLRasterStyleLayer.mm | 7 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayer.mm.ejs | 10 | ||||
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer.mm | 7 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleTests.mm | 38 |
8 files changed, 68 insertions, 21 deletions
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 166c5926f5..f6a6973363 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -62,13 +62,13 @@ - (void)removeFromMapView:(MGLMapView *)mapView { - _pendingLayer = nullptr; - self.rawLayer = nullptr; - auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } + auto originalLayer = std::make_unique<mbgl::style::BackgroundLayer>(self.identifier.UTF8String); + _pendingLayer = std::move(originalLayer); + self.rawLayer = _pendingLayer.get(); mbgl::style::BackgroundLayer *layer = dynamic_cast<mbgl::style::BackgroundLayer *>(removedLayer.get()); if (!layer) { diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index fc8e3a40c7..ad087c5d02 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -112,13 +112,14 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { - _pendingLayer = nullptr; - self.rawLayer = nullptr; - auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } + + auto originalLayer = std::make_unique<mbgl::style::CircleLayer>(self.identifier.UTF8String, self.sourceIdentifier.UTF8String); + _pendingLayer = std::move(originalLayer); + self.rawLayer = _pendingLayer.get(); mbgl::style::CircleLayer *layer = dynamic_cast<mbgl::style::CircleLayer *>(removedLayer.get()); if (!layer) { diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 6212bce410..ffd55884c4 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -107,13 +107,14 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { - _pendingLayer = nullptr; - self.rawLayer = nullptr; - auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } + + auto originalLayer = std::make_unique<mbgl::style::FillLayer>(self.identifier.UTF8String, self.sourceIdentifier.UTF8String); + _pendingLayer = std::move(originalLayer); + self.rawLayer = _pendingLayer.get(); mbgl::style::FillLayer *layer = dynamic_cast<mbgl::style::FillLayer *>(removedLayer.get()); if (!layer) { diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 6f1d2ee249..fc220650f4 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -119,13 +119,14 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { - _pendingLayer = nullptr; - self.rawLayer = nullptr; - auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } + + auto originalLayer = std::make_unique<mbgl::style::LineLayer>(self.identifier.UTF8String, self.sourceIdentifier.UTF8String); + _pendingLayer = std::move(originalLayer); + self.rawLayer = _pendingLayer.get(); mbgl::style::LineLayer *layer = dynamic_cast<mbgl::style::LineLayer *>(removedLayer.get()); if (!layer) { diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index d633bec435..0ddb6baf0e 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -69,13 +69,14 @@ - (void)removeFromMapView:(MGLMapView *)mapView { - _pendingLayer = nullptr; - self.rawLayer = nullptr; - auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } + + auto originalLayer = std::make_unique<mbgl::style::RasterLayer>(self.identifier.UTF8String, self.sourceIdentifier.UTF8String); + _pendingLayer = std::move(originalLayer); + self.rawLayer = _pendingLayer.get(); mbgl::style::RasterLayer *layer = dynamic_cast<mbgl::style::RasterLayer *>(removedLayer.get()); if (!layer) { diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 4cdec72aa4..7f44a7b4ae 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -150,13 +150,17 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { - _pendingLayer = nullptr; - self.rawLayer = nullptr; - auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } +<% if (type == 'background') { -%> + auto originalLayer = std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(self.identifier.UTF8String); +<% } else { -%> + auto originalLayer = std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(self.identifier.UTF8String, self.sourceIdentifier.UTF8String); +<% } -%> + _pendingLayer = std::move(originalLayer); + self.rawLayer = _pendingLayer.get(); mbgl::style::<%- camelize(type) %>Layer *layer = dynamic_cast<mbgl::style::<%- camelize(type) %>Layer *>(removedLayer.get()); if (!layer) { diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 066a0190fb..ae0ac2d6fa 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -166,13 +166,14 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { - _pendingLayer = nullptr; - self.rawLayer = nullptr; - auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } + + auto originalLayer = std::make_unique<mbgl::style::SymbolLayer>(self.identifier.UTF8String, self.sourceIdentifier.UTF8String); + _pendingLayer = std::move(originalLayer); + self.rawLayer = _pendingLayer.get(); mbgl::style::SymbolLayer *layer = dynamic_cast<mbgl::style::SymbolLayer *>(removedLayer.get()); if (!layer) { diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index c50330d488..7939db576e 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -235,6 +235,44 @@ XCTAssertThrowsSpecificNamed([self.style insertLayer:[[MGLOpenGLStyleLayer alloc] initWithIdentifier:@"my-layer"] atIndex:0], NSException, @"MGLRedundantLayerIdentifierException"); } + +- (void)testRemovingLayerBeforeAddingSameLayer { + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-removing-before-adding" shape:nil options:nil]; + + // Attempting to find a layer with identifier will trigger an exception if the source associated with the layer is not added + [self.style addSource:source]; + + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fill-layer" source:source]; + [self.style removeLayer:fillLayer]; + [self.style addLayer:fillLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:fillLayer.identifier]); + + MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"raster-layer" source:source]; + [self.style removeLayer:rasterLayer]; + [self.style addLayer:rasterLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:rasterLayer.identifier]); + + MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbol-layer" source:source]; + [self.style removeLayer:symbolLayer]; + [self.style addLayer:symbolLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:symbolLayer.identifier]); + + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"line-layer" source:source]; + [self.style removeLayer:lineLayer]; + [self.style addLayer:lineLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:lineLayer.identifier]); + + MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circle-layer" source:source]; + [self.style removeLayer:circleLayer]; + [self.style addLayer:circleLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:circleLayer.identifier]); + + MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"circle-layer"]; + [self.style removeLayer:backgroundLayer]; + [self.style addLayer:backgroundLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:backgroundLayer.identifier]); +} + - (NSString *)stringWithContentsOfStyleHeader { NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL URLByAppendingPathComponent:@"Headers" isDirectory:YES] |