summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLFillStyleLayer.mm
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-09-06 22:10:07 -0700
committerJesse Bounds <jesse@rebounds.net>2016-09-08 09:17:35 -0700
commit4c8d61abf18fc5fde07c53b520eb0696d138106c (patch)
tree57889e733e6b7e8b4d26a271e62f083faa01ce08 /platform/darwin/src/MGLFillStyleLayer.mm
parentf3191dbbb48f6700419f193ff68cf86a50336190 (diff)
downloadqtlocation-mapboxgl-4c8d61abf18fc5fde07c53b520eb0696d138106c.tar.gz
[ios, macos] Put MGLStyleLayer inits in respective classes
Previously, we declared MGLStyleLayer initializers in the MGLStyleLayer protocol as optional methods. This made it easy to opt in and out of initializers that did or or did not make sense for the subclass. However, this approach was dangerous since it was easy for an application developer to initialize an MGLStyleLayer subclass with an init method that was actually not implemented in that class causing an exception at runtime. This commit moves the init methods that each subclass supports to each subclass so xcode (and the compiler) help the developer avoid the previously possible runtime exception. In addition, a new init method is added that takes the source layer and passes that on to `mbgl::style:Layer` (but only on classes where this is possible in core). This allows an application developer to style a specific source layer (i.e. the contour lines of the mapbox terrain vector source). Finally, this refactors MGLStyleLayer classes to use an MGLSource instead of a string identifier for the source when initializing the style.
Diffstat (limited to 'platform/darwin/src/MGLFillStyleLayer.mm')
-rw-r--r--platform/darwin/src/MGLFillStyleLayer.mm21
1 files changed, 18 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm
index 6867c50f16..d36375b126 100644
--- a/platform/darwin/src/MGLFillStyleLayer.mm
+++ b/platform/darwin/src/MGLFillStyleLayer.mm
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.
+#import "MGLSource.h"
#import "NSPredicate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleAttributeValue.h"
@@ -13,6 +14,7 @@
@property (nonatomic) mbgl::style::FillLayer *layer;
@property (nonatomic, readwrite) NSString *layerIdentifier;
@property (nonatomic, readwrite) NSString *sourceIdentifier;
+@property (nonatomic, readwrite) NSString *sourceLayerIdentifier;
@end
@@ -20,11 +22,24 @@
@synthesize mapView;
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier {
+
+- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
+{
+ if (self = [super init]) {
+ _layerIdentifier = layerIdentifier;
+ _sourceIdentifier = source.sourceIdentifier;
+ _layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
+ }
+ return self;
+}
+
+- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
+{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
- _sourceIdentifier = sourceIdentifier;
- _layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String);
+ _sourceIdentifier = source.sourceIdentifier;
+ _layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
+ _layer->setSourceLayer(sourceLayer.UTF8String);
}
return self;
}