summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLStyleLayer.mm.ejs
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-10-05 00:34:01 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-10-06 15:19:38 -0700
commit50d2c01d7d0bad1aa1dee1a028e06f49f33c9b4c (patch)
tree34804e3598d0d9a1fc0ffed866e6916228251165 /platform/darwin/src/MGLStyleLayer.mm.ejs
parent21d7ee11e1cc0cd129f40df5bea2e07bfcc2a9e4 (diff)
downloadqtlocation-mapboxgl-50d2c01d7d0bad1aa1dee1a028e06f49f33c9b4c.tar.gz
[ios, macos] Revamped MGLStyleLayer, MGLSource inheritance
Removed the MGLStyleLayer protocol, because almost none of its members was actually implemented in every class that adopted the protocol. Removed the unused mapView backpointer property with no replacement. Renamed MGLBaseStyleLayer to MGLStyleLayer. Created the intermediate abstract classes MGLForegroundStyleLayer and MGLVectorStyleLayer to cover subsets of style layer classes with like functionality. Moved each MGLBaseStyleLayer initializer and the corresponding properties down to an abstract subclass such that the initializer makes sense for all concrete subclasses. Moved more initializers and the predicate property up to MGLVectorStyleLayer to eliminate duplication among the concrete subclasses. Marked these initializers as designated initializers. Removed “source” or “layer” before identifier wherever the type of identifier is apparent. Removed extra MGLGeoJSONSource initializer variants in favor of nullable parameters. Added copious documentation comments for source and style layer classes, including several previously undocumented methods and properties. In particular, some preconditions and postconditions have been documented. Added pragma marks to break up the jazzy documentation pages into sections. Reformatted exceptions for consistency.
Diffstat (limited to 'platform/darwin/src/MGLStyleLayer.mm.ejs')
-rw-r--r--platform/darwin/src/MGLStyleLayer.mm.ejs42
1 files changed, 16 insertions, 26 deletions
diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs
index 233117fa91..8d3bba9958 100644
--- a/platform/darwin/src/MGLStyleLayer.mm.ejs
+++ b/platform/darwin/src/MGLStyleLayer.mm.ejs
@@ -17,51 +17,41 @@
@interface MGL<%- camelize(type) %>StyleLayer ()
@property (nonatomic) mbgl::style::<%- camelize(type) %>Layer *layer;
-@property (nonatomic, readwrite) NSString *layerIdentifier;
-@property (nonatomic, readwrite) NSString *sourceIdentifier;
-@property (nonatomic, readwrite) NSString *sourceLayerIdentifier;
@end
@implementation MGL<%- camelize(type) %>StyleLayer
-@synthesize mapView;
-
<% if (type == 'background') { -%>
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier
+- (instancetype)initWithIdentifier:(NSString *)identifier
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- <%- initLayerIdentifierOnly(type) %>
+ if (self = [super initWithIdentifier:identifier]) {
+ _layer = new mbgl::style::<%- camelize(type) %>Layer(identifier.UTF8String);
}
return self;
}
-<% } -%>
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
+<% } else { -%>
+- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- <%- initLayer(type) %>
+ if (self = [super initWithIdentifier:identifier source:source]) {
+ _layer = new mbgl::style::<%- camelize(type) %>Layer(identifier.UTF8String, source.identifier.UTF8String);
}
return self;
}
+<% } -%>
<% if (type !== 'background' && type !== 'raster') { -%>
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
+- (NSString *)sourceLayerIdentifier
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- <%- initLayerWithSourceLayer(type) %>
- <%- setSourceLayer() %>
- }
- return self;
+ auto layerID = self.layer->getSourceLayer();
+ return layerID.empty() ? nil : @(layerID.c_str());
+}
+
+- (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier
+{
+ self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: "");
}
-<% } -%>
-<% if (type !== 'background' && type !== 'raster') { -%>
- (void)setPredicate:(NSPredicate *)predicate
{
self.layer->setFilter(predicate.mgl_filter);