diff options
27 files changed, 215 insertions, 38 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 4a875f784a..e934b39da0 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -187,14 +187,26 @@ global.propertyType = function (property, _private) { return _private ? `id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>` : `id <MGLStyleAttributeValue>`; }; +global.initLayerIdentifierOnly = function (layerType) { + return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String);` +} + global.initLayer = function (layerType) { if (layerType == "background") { - return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String);` + return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String);` } else { - return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String);` + return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);` } } +global.initLayerWithSourceLayer = function(layerType) { + return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);` +} + +global.setSourceLayer = function() { + return `_layer->setSourceLayer(sourceLayer.UTF8String);` +} + global.setterImplementation = function(property, layerType) { let implementation = ''; switch (property.type) { diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.h b/platform/darwin/src/MGLBackgroundStyleLayer.h index 0d99b38b6a..a6eda28783 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.h +++ b/platform/darwin/src/MGLBackgroundStyleLayer.h @@ -8,6 +8,11 @@ NS_ASSUME_NONNULL_BEGIN @interface MGLBackgroundStyleLayer : MGLBaseStyleLayer <MGLStyleLayer> +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier; + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source; + + #pragma mark - Accessing the Paint Attributes #if TARGET_OS_IPHONE diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index adfa31e4ed..f15bc4ceed 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.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::BackgroundLayer *layer; @property (nonatomic, readwrite) NSString *layerIdentifier; @property (nonatomic, readwrite) NSString *sourceIdentifier; +@property (nonatomic, readwrite) NSString *sourceLayerIdentifier; @end @@ -20,15 +22,26 @@ @synthesize mapView; -- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier { +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier +{ if (self = [super init]) { _layerIdentifier = layerIdentifier; - _sourceIdentifier = sourceIdentifier; _layer = new mbgl::style::BackgroundLayer(layerIdentifier.UTF8String); } return self; } +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source +{ + if (self = [super init]) { + _layerIdentifier = layerIdentifier; + _sourceIdentifier = source.sourceIdentifier; + _layer = new mbgl::style::BackgroundLayer(layerIdentifier.UTF8String); + } + return self; +} + + #pragma mark - Accessing the Paint Attributes - (void)setBackgroundColor:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)backgroundColor { diff --git a/platform/darwin/src/MGLBaseStyleLayer.mm b/platform/darwin/src/MGLBaseStyleLayer.mm index a747467739..8aaabcc8a8 100644 --- a/platform/darwin/src/MGLBaseStyleLayer.mm +++ b/platform/darwin/src/MGLBaseStyleLayer.mm @@ -13,6 +13,32 @@ @synthesize layerIdentifier; @synthesize mapView; @synthesize layer; +@synthesize sourceIdentifier; +@synthesize sourceLayerIdentifier; + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier +{ + [[NSException exceptionWithName:@"MGLAbstractClassException" + reason:@"MGLBaseStyleLayer is an abstract class" + userInfo:nil] raise]; + return nil; +} + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier +{ + [[NSException exceptionWithName:@"MGLAbstractClassException" + reason:@"MGLBaseStyleLayer is an abstract class" + userInfo:nil] raise]; + return nil; +} + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier sourceLayer:(NSString *)sourceLayer +{ + [[NSException exceptionWithName:@"MGLAbstractClassException" + reason:@"MGLBaseStyleLayer is an abstract class" + userInfo:nil] raise]; + return nil; +} - (void)setVisible:(BOOL)visible { diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h index e4430044ad..bd51b8ede0 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.h +++ b/platform/darwin/src/MGLCircleStyleLayer.h @@ -18,6 +18,11 @@ typedef NS_ENUM(NSUInteger, MGLCircleStyleLayerCirclePitchScale) { @interface MGLCircleStyleLayer : MGLBaseStyleLayer <MGLStyleLayer> + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source; + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer; + /** A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>. diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index a906407486..1db7ef875e 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.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::CircleLayer *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::CircleLayer(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::CircleLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String); + _sourceIdentifier = source.sourceIdentifier; + _layer = new mbgl::style::CircleLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String); + _layer->setSourceLayer(sourceLayer.UTF8String); } return self; } diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h index 2d51f071e5..823c0574af 100644 --- a/platform/darwin/src/MGLFillStyleLayer.h +++ b/platform/darwin/src/MGLFillStyleLayer.h @@ -13,6 +13,11 @@ typedef NS_ENUM(NSUInteger, MGLFillStyleLayerFillTranslateAnchor) { @interface MGLFillStyleLayer : MGLBaseStyleLayer <MGLStyleLayer> + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source; + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer; + /** A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>. 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; } diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h index 5c2a3afc2e..34f8e74dfa 100644 --- a/platform/darwin/src/MGLLineStyleLayer.h +++ b/platform/darwin/src/MGLLineStyleLayer.h @@ -25,6 +25,11 @@ typedef NS_ENUM(NSUInteger, MGLLineStyleLayerLineTranslateAnchor) { @interface MGLLineStyleLayer : MGLBaseStyleLayer <MGLStyleLayer> + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source; + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer; + /** A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>. diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 8c5af877fe..b35d3921f5 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.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::LineLayer *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::LineLayer(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::LineLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String); + _sourceIdentifier = source.sourceIdentifier; + _layer = new mbgl::style::LineLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String); + _layer->setSourceLayer(sourceLayer.UTF8String); } return self; } diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h index 213619be04..b7f2cd7fda 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.h +++ b/platform/darwin/src/MGLRasterStyleLayer.h @@ -8,6 +8,10 @@ NS_ASSUME_NONNULL_BEGIN @interface MGLRasterStyleLayer : MGLBaseStyleLayer <MGLStyleLayer> + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source; + + #pragma mark - Accessing the Paint Attributes /** diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index dc70dfbde7..74cffc2ed2 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.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::RasterLayer *layer; @property (nonatomic, readwrite) NSString *layerIdentifier; @property (nonatomic, readwrite) NSString *sourceIdentifier; +@property (nonatomic, readwrite) NSString *sourceLayerIdentifier; @end @@ -20,15 +22,18 @@ @synthesize mapView; -- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier { + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source +{ if (self = [super init]) { _layerIdentifier = layerIdentifier; - _sourceIdentifier = sourceIdentifier; - _layer = new mbgl::style::RasterLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String); + _sourceIdentifier = source.sourceIdentifier; + _layer = new mbgl::style::RasterLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String); } return self; } + #pragma mark - Accessing the Paint Attributes - (void)setRasterOpacity:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)rasterOpacity { diff --git a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs index 9a3e59b7b6..0d0317cb65 100644 --- a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs +++ b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs @@ -17,7 +17,7 @@ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url]; - MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithLayerIdentifier:@"layerID" sourceIdentifier:@"sourceID"]; +MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source]; [self.mapView.style addSource:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/src/MGLStyleLayer.h b/platform/darwin/src/MGLStyleLayer.h index 30456331db..d4ed525a3f 100644 --- a/platform/darwin/src/MGLStyleLayer.h +++ b/platform/darwin/src/MGLStyleLayer.h @@ -6,12 +6,7 @@ @property (nonatomic, weak) MGLMapView *mapView; @property (nonatomic, copy, readonly) NSString *layerIdentifier; - -@optional - @property (nonatomic, readonly) NSString *sourceIdentifier; - -- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier; -- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier; +@property (nonatomic, readonly) NSString *sourceLayerIdentifier; @end diff --git a/platform/darwin/src/MGLStyleLayer.h.ejs b/platform/darwin/src/MGLStyleLayer.h.ejs index 8acda024c4..64a7e06b5f 100644 --- a/platform/darwin/src/MGLStyleLayer.h.ejs +++ b/platform/darwin/src/MGLStyleLayer.h.ejs @@ -35,6 +35,16 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(type) %>StyleLayer<%- camelize(prope <% } -%> @interface MGL<%- camelize(type) %>StyleLayer : MGLBaseStyleLayer <MGLStyleLayer> +<% if (type == 'background') { -%> +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier; +<% } -%> + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source; + +<% if (type !== 'background' && type !== 'raster') { -%> +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer; +<% } -%> + <% if (type !== 'background' && type !== 'raster') { -%> /** A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>. diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 4615aeeb9b..233117fa91 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -6,6 +6,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" @@ -18,6 +19,7 @@ @property (nonatomic) mbgl::style::<%- camelize(type) %>Layer *layer; @property (nonatomic, readwrite) NSString *layerIdentifier; @property (nonatomic, readwrite) NSString *sourceIdentifier; +@property (nonatomic, readwrite) NSString *sourceLayerIdentifier; @end @@ -25,16 +27,41 @@ @synthesize mapView; -- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier { +<% if (type == 'background') { -%> +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier +{ + if (self = [super init]) { + _layerIdentifier = layerIdentifier; + <%- initLayerIdentifierOnly(type) %> + } + return self; +} +<% } -%> + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source +{ if (self = [super init]) { _layerIdentifier = layerIdentifier; - _sourceIdentifier = sourceIdentifier; + _sourceIdentifier = source.sourceIdentifier; <%- initLayer(type) %> } return self; } <% if (type !== 'background' && type !== 'raster') { -%> +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer +{ + if (self = [super init]) { + _layerIdentifier = layerIdentifier; + _sourceIdentifier = source.sourceIdentifier; + <%- initLayerWithSourceLayer(type) %> + <%- setSourceLayer() %> + } + return self; +} +<% } -%> + +<% if (type !== 'background' && type !== 'raster') { -%> - (void)setPredicate:(NSPredicate *)predicate { self.layer->setFilter(predicate.mgl_filter); diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index eacd158dda..c900518b9b 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -69,6 +69,11 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextTranslateAnchor) { @interface MGLSymbolStyleLayer : MGLBaseStyleLayer <MGLStyleLayer> + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source; + +- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer; + /** A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>. diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 1fb3a0a587..4d9b20fbcb 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.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::SymbolLayer *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::SymbolLayer(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::SymbolLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String); + _sourceIdentifier = source.sourceIdentifier; + _layer = new mbgl::style::SymbolLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String); + _layer->setSourceLayer(sourceLayer.UTF8String); } return self; } diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.m b/platform/darwin/test/MGLBackgroundStyleLayerTests.m index 21d6a8832f..f4fdae61a4 100644 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.m +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.m @@ -12,7 +12,7 @@ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url]; - MGLBackgroundStyleLayer *layer = [[MGLBackgroundStyleLayer alloc] initWithLayerIdentifier:@"layerID" sourceIdentifier:@"sourceID"]; +MGLBackgroundStyleLayer *layer = [[MGLBackgroundStyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source]; [self.mapView.style addSource:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.m b/platform/darwin/test/MGLCircleStyleLayerTests.m index de0ebe81d8..0e70c3f836 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.m +++ b/platform/darwin/test/MGLCircleStyleLayerTests.m @@ -12,7 +12,7 @@ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url]; - MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithLayerIdentifier:@"layerID" sourceIdentifier:@"sourceID"]; +MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source]; [self.mapView.style addSource:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLFillStyleLayerTests.m b/platform/darwin/test/MGLFillStyleLayerTests.m index e926ef6335..7994d76517 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.m +++ b/platform/darwin/test/MGLFillStyleLayerTests.m @@ -12,7 +12,7 @@ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url]; - MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"layerID" sourceIdentifier:@"sourceID"]; +MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source]; [self.mapView.style addSource:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm index 5b102e2e86..513963ab7e 100644 --- a/platform/darwin/test/MGLFilterTests.mm +++ b/platform/darwin/test/MGLFilterTests.mm @@ -19,7 +19,7 @@ NSData *geoJSONData = [NSData dataWithContentsOfURL:url]; source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"test-source" geoJSONData:geoJSONData]; [self.mapView.style addSource:source]; - layer = [[MGLLineStyleLayer alloc] initWithLayerIdentifier:@"test-layer" sourceIdentifier:@"test-source"]; + layer = [[MGLLineStyleLayer alloc] initWithLayerIdentifier:@"test-layer" source:source]; } - (void)tearDown diff --git a/platform/darwin/test/MGLLineStyleLayerTests.m b/platform/darwin/test/MGLLineStyleLayerTests.m index 859e010579..ff607f2e2b 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.m +++ b/platform/darwin/test/MGLLineStyleLayerTests.m @@ -12,7 +12,7 @@ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url]; - MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithLayerIdentifier:@"layerID" sourceIdentifier:@"sourceID"]; +MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source]; [self.mapView.style addSource:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.m b/platform/darwin/test/MGLRasterStyleLayerTests.m index 75e900c4c6..7158c9aef2 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.m +++ b/platform/darwin/test/MGLRasterStyleLayerTests.m @@ -12,7 +12,7 @@ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url]; - MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithLayerIdentifier:@"layerID" sourceIdentifier:@"sourceID"]; +MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source]; [self.mapView.style addSource:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.m b/platform/darwin/test/MGLSymbolStyleLayerTests.m index a32af96828..dbd8f50482 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.m +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.m @@ -12,7 +12,7 @@ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url]; - MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifier:@"layerID" sourceIdentifier:@"sourceID"]; +MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source]; [self.mapView.style addSource:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 605d6b2da8..0f81643f73 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -484,7 +484,7 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"ams" URL:geoJSONURL]; [self.mapView.style addSource:source]; - MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"test" sourceIdentifier:@"ams"]; + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"test" source:source]; fillLayer.fillColor = [UIColor purpleColor]; [self.mapView.style addLayer:fillLayer]; } @@ -495,7 +495,7 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithSourceIdentifier:@"my-raster-source" URL:rasterURL tileSize:512]; [self.mapView.style addSource:rasterSource]; - MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithLayerIdentifier:@"my-raster-layer" sourceIdentifier:@"my-raster-source"]; + MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithLayerIdentifier:@"my-raster-layer" source:rasterSource]; MGLStyleAttributeFunction *opacityFunction = [[MGLStyleAttributeFunction alloc] init]; opacityFunction.stops = @{@20.0f: @1.0f, @5.0f: @0.0f}; diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 8d24b35b6a..42398ff0a6 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -507,7 +507,7 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"ams" URL:geoJSONURL]; [self.mapView.style addSource:source]; - MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"test" sourceIdentifier:@"ams"]; + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"test" source:source]; fillLayer.fillColor = [NSColor greenColor]; fillLayer.predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"type", @"park"]; [self.mapView.style addLayer:fillLayer]; |