From de6c9b35f35f6ec0950529261b207d716c046beb Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 3 Apr 2017 14:25:37 -0700 Subject: [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. --- platform/darwin/src/MGLForegroundStyleLayer.mm | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 platform/darwin/src/MGLForegroundStyleLayer.mm (limited to 'platform/darwin/src/MGLForegroundStyleLayer.mm') diff --git a/platform/darwin/src/MGLForegroundStyleLayer.mm b/platform/darwin/src/MGLForegroundStyleLayer.mm new file mode 100644 index 0000000000..6926dfac1f --- /dev/null +++ b/platform/darwin/src/MGLForegroundStyleLayer.mm @@ -0,0 +1,29 @@ +#import "MGLForegroundStyleLayer.h" +#import "MGLForegroundStyleLayer_Private.h" +#import "MGLStyleLayer_Private.h" +#import "MGLSource.h" + +@implementation MGLForegroundStyleLayer + +- (instancetype)initWithRawLayer:(mbgl::style::Layer *)rawLayer source:(MGLSource *)source { + if (self = [super initWithRawLayer:rawLayer]) { + _sourceIdentifier = source.identifier; + } + return self; +} + +- (instancetype)initWithPendingLayer:(std::unique_ptr)pendingLayer source:(MGLSource *)source { + if (self = [super initWithPendingLayer:std::move(pendingLayer)]) { + _sourceIdentifier = source.identifier; + } + return self; +} + +- (NSString *)description { + return [NSString stringWithFormat: + @"<%@: %p; identifier = %@; sourceIdentifier = %@; visible = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier, + self.sourceIdentifier, self.visible ? @"YES" : @"NO"]; +} + +@end -- cgit v1.2.1