-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Layer ownership refactor #6904
Layer ownership refactor #6904
Changes from 1 commit
4903b19
ec37fba
478f7a5
20c1ba8
8fba1ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. | ||
|
||
#import "MGLSource.h" | ||
#import "MGLMapView_Private.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes will eventually need to happen in all the style layer subclasses. We have a script (mentioned above) that automatically generates these headers. So when you're ready, update the templates that the script uses (the .ejs files in this directory) and run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated the script to import MGLMapView_Private.h |
||
#import "NSPredicate+MGLAdditions.h" | ||
#import "MGLStyleLayer_Private.h" | ||
#import "MGLStyleValue_Private.h" | ||
|
@@ -16,15 +17,25 @@ @interface MGLFillStyleLayer () | |
@end | ||
|
||
@implementation MGLFillStyleLayer | ||
{ | ||
std::unique_ptr<mbgl::style::FillLayer> _pendingLayer; | ||
} | ||
|
||
- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source | ||
{ | ||
if (self = [super initWithIdentifier:identifier source:source]) { | ||
_layer = new mbgl::style::FillLayer(identifier.UTF8String, source.identifier.UTF8String); | ||
[self commonInit:identifier source:source]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)commonInit:(NSString *)identifier source:(MGLSource *)source | ||
{ | ||
auto layer = std::make_unique<mbgl::style::FillLayer>(identifier.UTF8String, source.identifier.UTF8String); | ||
_pendingLayer = std::move(layer); | ||
self.layer = _pendingLayer.get(); | ||
} | ||
|
||
- (NSString *)sourceLayerIdentifier | ||
{ | ||
auto layerID = self.layer->getSourceLayer(); | ||
|
@@ -118,4 +129,11 @@ - (void)setFillPattern:(MGLStyleValue<NSString *> *)fillPattern { | |
return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); | ||
} | ||
|
||
#pragma mark - | ||
|
||
- (void)addToMapView:(MGLMapView *)mapView | ||
{ | ||
mapView.mbglMap->addLayer(std::move(_pendingLayer)); | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,20 @@ | |
|
||
#include <mbgl/style/layer.hpp> | ||
|
||
@class MGLMapView; | ||
|
||
@interface MGLStyleLayer (Private) | ||
|
||
@property (nonatomic, readwrite, copy) NSString *identifier; | ||
@property (nonatomic) mbgl::style::Layer *layer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For future reference, I think we should add documentation for this property like we did in |
||
|
||
/** | ||
Adds the mbgl style layer that this object represents to the mbgl map. | ||
|
||
Once a mbgl style layer is added, ownership of the object is transferred to the | ||
`mbgl::Map` and this object no longer has an active unique_ptr reference to the | ||
`mbgl::style::Layer`. | ||
*/ | ||
- (void)addToMapView:(MGLMapView *)mapView; | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method needs to be private. We want developers to continue to call
-[MGLStyle addLayer:]
or-[MGLStyle insertLayer:belowLayer:]
as appropriate. To avoid having to create a separate private header for each layer subclass, declare it in the private header for MGLStyle.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, I meant the private header for MGLStyleLayer, MGLStyleLayer_Private.h.