summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLBackgroundStyleLayer.mm
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-04-03 14:25:37 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-04-13 10:33:18 -0700
commitde6c9b35f35f6ec0950529261b207d716c046beb (patch)
treef022e3e09b4f8ffbe7646341f91aa76b8081ff62 /platform/darwin/src/MGLBackgroundStyleLayer.mm
parent98d005792b68d0b299f123c1d31e50c72ba91ba8 (diff)
downloadqtlocation-mapboxgl-de6c9b35f35f6ec0950529261b207d716c046beb.tar.gz
[darwin] Simplify MGLStyleLayer initialization and pointer management
Similarly to the previous commit, introduce `-[MGLStyleLayer initWithPendingLayer:]`, allowing the base class to track the owned `_pendingSource` pointer and implement `-addToMapView:` and `-removeFromMapView:` without any casts. Fixes an issue where `-[MGLStyle layerFromMBGLLayer:]` would wind up creating layers whose `_rawLayer` and `_pendingLayer` held different values.
Diffstat (limited to 'platform/darwin/src/MGLBackgroundStyleLayer.mm')
-rw-r--r--platform/darwin/src/MGLBackgroundStyleLayer.mm62
1 files changed, 5 insertions, 57 deletions
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm
index 8f416a0ea2..151d4cadaa 100644
--- a/platform/darwin/src/MGLBackgroundStyleLayer.mm
+++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm
@@ -2,35 +2,28 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "MGLMapView_Private.h"
#import "NSPredicate+MGLAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
+#import "MGLForegroundStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
#import "MGLBackgroundStyleLayer.h"
-#include <mbgl/map/map.hpp>
+#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/layers/background_layer.hpp>
@interface MGLBackgroundStyleLayer ()
-@property (nonatomic) mbgl::style::BackgroundLayer *rawLayer;
+@property (nonatomic, readonly) mbgl::style::BackgroundLayer *rawLayer;
@end
@implementation MGLBackgroundStyleLayer
-{
- std::unique_ptr<mbgl::style::BackgroundLayer> _pendingLayer;
-}
- (instancetype)initWithIdentifier:(NSString *)identifier
{
- if (self = [super initWithIdentifier:identifier]) {
- auto layer = std::make_unique<mbgl::style::BackgroundLayer>(identifier.UTF8String);
- _pendingLayer = std::move(layer);
- self.rawLayer = _pendingLayer.get();
- }
- return self;
+ auto layer = std::make_unique<mbgl::style::BackgroundLayer>(identifier.UTF8String);
+ return self = [super initWithPendingLayer:std::move(layer)];
}
- (mbgl::style::BackgroundLayer *)rawLayer
@@ -38,51 +31,6 @@
return (mbgl::style::BackgroundLayer *)super.rawLayer;
}
-- (void)setRawLayer:(mbgl::style::BackgroundLayer *)rawLayer
-{
- super.rawLayer = rawLayer;
-}
-
-#pragma mark - Adding to and removing from a map view
-
-- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer
-{
- if (_pendingLayer == nullptr) {
- [NSException raise:@"MGLRedundantLayerException"
- format:@"This instance %@ was already added to %@. Adding the same layer instance " \
- "to the style more than once is invalid.", self, mapView.style];
- }
-
- 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
-{
- if (self.rawLayer != mapView.mbglMap->getLayer(self.identifier.UTF8String)) {
- return;
- }
-
- auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
- if (!removedLayer) {
- return;
- }
-
- mbgl::style::BackgroundLayer *layer = dynamic_cast<mbgl::style::BackgroundLayer *>(removedLayer.get());
- if (!layer) {
- return;
- }
-
- removedLayer.release();
-
- _pendingLayer = std::unique_ptr<mbgl::style::BackgroundLayer>(layer);
- self.rawLayer = _pendingLayer.get();
-}
-
#pragma mark - Accessing the Paint Attributes
- (void)setBackgroundColor:(MGLStyleValue<MGLColor *> *)backgroundColor {