summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/darwin/scripts/generate-style-code.js12
-rw-r--r--platform/darwin/src/MGLBackgroundStyleLayer.h7
-rw-r--r--platform/darwin/src/MGLBackgroundStyleLayer.mm23
-rw-r--r--platform/darwin/src/MGLBaseStyleLayer.h44
-rw-r--r--platform/darwin/src/MGLBaseStyleLayer.mm37
-rw-r--r--platform/darwin/src/MGLCircleStyleLayer.h14
-rw-r--r--platform/darwin/src/MGLCircleStyleLayer.mm30
-rw-r--r--platform/darwin/src/MGLFillStyleLayer.h14
-rw-r--r--platform/darwin/src/MGLFillStyleLayer.mm30
-rw-r--r--platform/darwin/src/MGLGeoJSONSource.h90
-rw-r--r--platform/darwin/src/MGLGeoJSONSource.mm28
-rw-r--r--platform/darwin/src/MGLLineStyleLayer.h14
-rw-r--r--platform/darwin/src/MGLLineStyleLayer.mm30
-rw-r--r--platform/darwin/src/MGLRasterSource.h72
-rw-r--r--platform/darwin/src/MGLRasterSource.mm12
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.h5
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.mm15
-rw-r--r--platform/darwin/src/MGLRuntimeStylingTests.m.ejs11
-rw-r--r--platform/darwin/src/MGLSource.h21
-rw-r--r--platform/darwin/src/MGLSource.mm17
-rw-r--r--platform/darwin/src/MGLStyle.h23
-rw-r--r--platform/darwin/src/MGLStyle.mm134
-rw-r--r--platform/darwin/src/MGLStyleLayer.h74
-rw-r--r--platform/darwin/src/MGLStyleLayer.h.ejs26
-rw-r--r--platform/darwin/src/MGLStyleLayer.mm30
-rw-r--r--platform/darwin/src/MGLStyleLayer.mm.ejs42
-rw-r--r--platform/darwin/src/MGLStyleLayer_Private.h7
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.h14
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.mm30
-rw-r--r--platform/darwin/src/MGLVectorSource.h53
-rw-r--r--platform/darwin/src/MGLVectorSource.mm12
-rw-r--r--platform/darwin/test/MGLBackgroundStyleLayerTests.m9
-rw-r--r--platform/darwin/test/MGLCircleStyleLayerTests.m7
-rw-r--r--platform/darwin/test/MGLFillStyleLayerTests.m7
-rw-r--r--platform/darwin/test/MGLFilterTests.mm4
-rw-r--r--platform/darwin/test/MGLLineStyleLayerTests.m7
-rw-r--r--platform/darwin/test/MGLRasterStyleLayerTests.m7
-rw-r--r--platform/darwin/test/MGLSymbolStyleLayerTests.m7
-rw-r--r--platform/ios/app/MBXViewController.m8
-rw-r--r--platform/ios/jazzy.yml5
-rw-r--r--platform/ios/test/MGLGeoJSONSourceTests.mm4
-rw-r--r--platform/macos/app/MapDocument.m4
-rw-r--r--platform/macos/jazzy.yml5
43 files changed, 530 insertions, 515 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index a801145dec..728a2902e9 100644
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -211,22 +211,14 @@ 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(identifier.UTF8String);`
} else {
- return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);`
+ return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String, source.identifier.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);`
}
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.h b/platform/darwin/src/MGLBackgroundStyleLayer.h
index 386b68feda..d464eb49f2 100644
--- a/platform/darwin/src/MGLBackgroundStyleLayer.h
+++ b/platform/darwin/src/MGLBackgroundStyleLayer.h
@@ -12,12 +12,9 @@ NS_ASSUME_NONNULL_BEGIN
`style` and obtain the background layer using the `-[MGLStyle layerWithIdentifier:]`
method and passing `background` for the identifier.
*/
-@interface MGLBackgroundStyleLayer : MGLBaseStyleLayer <MGLStyleLayer>
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier;
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source;
+@interface MGLBackgroundStyleLayer : MGLStyleLayer
+- (instancetype)initWithIdentifier:(NSString *)identifier NS_DESIGNATED_INITIALIZER;
#pragma mark - Accessing the Paint Attributes
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm
index f15bc4ceed..032aa196ee 100644
--- a/platform/darwin/src/MGLBackgroundStyleLayer.mm
+++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm
@@ -12,36 +12,19 @@
@interface MGLBackgroundStyleLayer ()
@property (nonatomic) mbgl::style::BackgroundLayer *layer;
-@property (nonatomic, readwrite) NSString *layerIdentifier;
-@property (nonatomic, readwrite) NSString *sourceIdentifier;
-@property (nonatomic, readwrite) NSString *sourceLayerIdentifier;
@end
@implementation MGLBackgroundStyleLayer
-@synthesize mapView;
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier
+- (instancetype)initWithIdentifier:(NSString *)identifier
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _layer = new mbgl::style::BackgroundLayer(layerIdentifier.UTF8String);
+ if (self = [super initWithIdentifier:identifier]) {
+ _layer = new mbgl::style::BackgroundLayer(identifier.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.h b/platform/darwin/src/MGLBaseStyleLayer.h
index fee7707c64..cfdc03962f 100644
--- a/platform/darwin/src/MGLBaseStyleLayer.h
+++ b/platform/darwin/src/MGLBaseStyleLayer.h
@@ -5,15 +5,45 @@
NS_ASSUME_NONNULL_BEGIN
/**
- The base style layer class from which all other style layer classes
- inherit. Style layers allow runtime customization of all map styling
- properties.
+ `MGLStyleLayer` is an abstract base class for style layers. A style layer
+ manages the layout and appearance of content at a specific z-index in a style.
+ An `MGLStyle` object consists of one or more `MGLStyleLayer` objects.
- You should use the concrete subclasses of `MGLBaseStyleLayer` (which
- conform to `MGLStyleLayer`) to style fill, line, symbol, and other layer
- types.
+ Each style layer defined by the style JSON file is represented at runtime by an
+ `MGLStyleLayer` object, which you can use to refine the map’s appearance. You
+ can also add and remove style layers dynamically.
+
+ Do not create instances of this class directly, and do not create your own
+ subclasses of this class. Instead, create instances of
+ `MGLBackgroundStyleLayer` and the concrete subclasses of
+ `MGLForegroundStyleLayer`.
+ */
+@interface MGLStyleLayer : NSObject
+
+#pragma mark Initializing a Style Layer
+
+/**
+ Returns a style layer object initialized with the given identifier.
+
+ After initializing and configuring the style layer, add it to a map view’s
+ style using the `-[MGLStyle addLayer:]` or
+ `-[MGLStyle insertLayer:belowLayer:]` method.
+
+ @param identifier A string that uniquely identifies the layer in the style to
+ which it is added.
+ @return An initialized style layer.
+ */
+- (instancetype)initWithIdentifier:(NSString *)identifier;
+
+#pragma mark Identifying a Style Layer
+
+/**
+ A string that uniquely identifies the style layer in the style to which it is
+ added.
*/
-@interface MGLBaseStyleLayer : NSObject
+@property (nonatomic, copy, readonly) NSString *identifier;
+
+#pragma mark Configuring a Style Layer’s Visibility
/**
Whether this layer is displayed. A value of `NO` hides the layer.
diff --git a/platform/darwin/src/MGLBaseStyleLayer.mm b/platform/darwin/src/MGLBaseStyleLayer.mm
index 8aaabcc8a8..8a599e67c7 100644
--- a/platform/darwin/src/MGLBaseStyleLayer.mm
+++ b/platform/darwin/src/MGLBaseStyleLayer.mm
@@ -5,39 +5,14 @@
#include <mbgl/style/layer.hpp>
-@interface MGLBaseStyleLayer() <MGLStyleLayer_Private>
-@end
-
-@implementation MGLBaseStyleLayer
-
-@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;
-}
+@implementation MGLStyleLayer
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier sourceLayer:(NSString *)sourceLayer
+- (instancetype)initWithIdentifier:(NSString *)identifier
{
- [[NSException exceptionWithName:@"MGLAbstractClassException"
- reason:@"MGLBaseStyleLayer is an abstract class"
- userInfo:nil] raise];
- return nil;
+ if (self = [super init]) {
+ _identifier = identifier;
+ }
+ return self;
}
- (void)setVisible:(BOOL)visible
diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h
index 9e620eeeec..bddc6bf525 100644
--- a/platform/darwin/src/MGLCircleStyleLayer.h
+++ b/platform/darwin/src/MGLCircleStyleLayer.h
@@ -40,19 +40,7 @@ typedef NS_ENUM(NSUInteger, MGLCircleStyleLayerCirclePitchScale) {
`MGLMapView` for its `style` and obtain existing layers using the
`-[MGLStyle layerWithIdentifier:]` method.
*/
-@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>.
-
- The predicate's left expression must be a string that identifies a feature
- property, or one of the special keys.
- */
-@property (nonatomic, nullable) NSPredicate *predicate;
+@interface MGLCircleStyleLayer : MGLVectorStyleLayer
#pragma mark - Accessing the Paint Attributes
diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm
index 1db7ef875e..6e805a994c 100644
--- a/platform/darwin/src/MGLCircleStyleLayer.mm
+++ b/platform/darwin/src/MGLCircleStyleLayer.mm
@@ -12,36 +12,28 @@
@interface MGLCircleStyleLayer ()
@property (nonatomic) mbgl::style::CircleLayer *layer;
-@property (nonatomic, readwrite) NSString *layerIdentifier;
-@property (nonatomic, readwrite) NSString *sourceIdentifier;
-@property (nonatomic, readwrite) NSString *sourceLayerIdentifier;
@end
@implementation MGLCircleStyleLayer
-@synthesize mapView;
-
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
+- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::CircleLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
+ if (self = [super initWithIdentifier:identifier source:source]) {
+ _layer = new mbgl::style::CircleLayer(identifier.UTF8String, source.identifier.UTF8String);
}
return self;
}
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
+- (NSString *)sourceLayerIdentifier
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::CircleLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
- _layer->setSourceLayer(sourceLayer.UTF8String);
- }
- return self;
+ auto layerID = self.layer->getSourceLayer();
+ return layerID.empty() ? nil : @(layerID.c_str());
+}
+
+- (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier
+{
+ self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: "");
}
- (void)setPredicate:(NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h
index 9adfd7c432..ff1edddd5a 100644
--- a/platform/darwin/src/MGLFillStyleLayer.h
+++ b/platform/darwin/src/MGLFillStyleLayer.h
@@ -26,19 +26,7 @@ typedef NS_ENUM(NSUInteger, MGLFillStyleLayerFillTranslateAnchor) {
`MGLMapView` for its `style` and obtain existing layers using the
`-[MGLStyle layerWithIdentifier:]` method.
*/
-@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>.
-
- The predicate's left expression must be a string that identifies a feature
- property, or one of the special keys.
- */
-@property (nonatomic, nullable) NSPredicate *predicate;
+@interface MGLFillStyleLayer : MGLVectorStyleLayer
#pragma mark - Accessing the Paint Attributes
diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm
index d36375b126..4810f4fefa 100644
--- a/platform/darwin/src/MGLFillStyleLayer.mm
+++ b/platform/darwin/src/MGLFillStyleLayer.mm
@@ -12,36 +12,28 @@
@interface MGLFillStyleLayer ()
@property (nonatomic) mbgl::style::FillLayer *layer;
-@property (nonatomic, readwrite) NSString *layerIdentifier;
-@property (nonatomic, readwrite) NSString *sourceIdentifier;
-@property (nonatomic, readwrite) NSString *sourceLayerIdentifier;
@end
@implementation MGLFillStyleLayer
-@synthesize mapView;
-
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
+- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
+ if (self = [super initWithIdentifier:identifier source:source]) {
+ _layer = new mbgl::style::FillLayer(identifier.UTF8String, source.identifier.UTF8String);
}
return self;
}
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
+- (NSString *)sourceLayerIdentifier
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
- _layer->setSourceLayer(sourceLayer.UTF8String);
- }
- return self;
+ auto layerID = self.layer->getSourceLayer();
+ return layerID.empty() ? nil : @(layerID.c_str());
+}
+
+- (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier
+{
+ self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: "");
}
- (void)setPredicate:(NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLGeoJSONSource.h b/platform/darwin/src/MGLGeoJSONSource.h
index da772108f1..0b25f1a9d4 100644
--- a/platform/darwin/src/MGLGeoJSONSource.h
+++ b/platform/darwin/src/MGLGeoJSONSource.h
@@ -50,7 +50,6 @@ extern NSString * const MGLGeoJSONBufferOption;
*/
extern NSString * const MGLGeoJSONToleranceOption;
-
/**
A GeoJSON source.
@@ -59,77 +58,66 @@ extern NSString * const MGLGeoJSONToleranceOption;
*/
@interface MGLGeoJSONSource : MGLSource
-/**
- The contents of the source.
-
- If the receiver was initialized using `-initWithSourceIdentifier:URL:`, this
- property is set to `nil`. This property is unavailable until the receiver is
- passed into `-[MGLStyle addSource]`.
- */
-@property (nonatomic, readonly, nullable) NS_ARRAY_OF(id <MGLFeature>) *features;
+#pragma mark Initializing a Source
/**
- A GeoJSON representation of the contents of the source.
+ Returns a GeoJSON source initialized with an identifier, GeoJSON data, and a
+ dictionary of options for the source according to the
+ <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">style
+ specification</a>.
- Use the `features` property instead to get an object representation of the
- contents. Alternatively, use NSJSONSerialization with the value of this
- property to transform it into Foundation types.
-
- If the receiver was initialized using `-initWithSourceIdentifier:URL:`, this
- property is set to `nil`. This property is unavailable until the receiver is
- passed into `-[MGLStyle addSource]`.
+ @param identifier A string that uniquely identifies the source.
+ @param geoJSONData An `NSData` object representing GeoJSON source code.
+ @param options An `NSDictionary` of options for this source.
+ @return An initialized GeoJSON source.
*/
-@property (nonatomic, readonly, nullable, copy) NSData *geoJSONData;
+- (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *)data options:(nullable NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER;
/**
- The URL to the GeoJSON document that specifies the contents of the source.
+ Returns a GeoJSON source with an identifier, URL, and dictionary of options for
+ the source according to the
+ <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">style
+ specification</a>.
- If the receiver was initialized using `-initWithSourceIdentifier:geoJSONData:`,
- this property is set to `nil`.
+ @param identifier A string that uniquely identifies the source.
+ @param URL An HTTP(S) URL, absolute file URL, or local file URL relative to the
+ current application’s resource bundle.
+ @param options An `NSDictionary` of options for this source.
+ @return An initialized GeoJSON source.
*/
-@property (nonatomic, readonly, nullable) NSURL *URL;
+- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(nullable NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER;
-/**
- Initializes a source with the given identifier and GeoJSON data.
-
- @param sourceIdentifier A string that uniquely identifies the source.
- @param geoJSONData An NSData object representing GeoJSON source code.
- */
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier geoJSONData:(NSData *)data NS_DESIGNATED_INITIALIZER;
+#pragma mark Accessing a Source’s Content
/**
- Initializes a source with the given identifier, GeoJSON data, and a dictionary
- of options for the source as specified by the
- <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">the
- style specification</a>.
+ The contents of the source.
- @param sourceIdentifier A string that uniquely identifies the source.
- @param geoJSONData An NSData object representing GeoJSON source code.
- @param options An NSDictionary of attributes for this source.
+ If the receiver was initialized using `-initWithIdentifier:URL:`, this property
+ is set to `nil`. This property is unavailable until the receiver is passed into
+ `-[MGLStyle addSource]`.
*/
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier geoJSONData:(NSData *)data options:(NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER;
+@property (nonatomic, readonly, nullable) NS_ARRAY_OF(id <MGLFeature>) *features;
/**
- Initializes a source with the given identifier and URL.
+ A GeoJSON representation of the contents of the source.
- @param sourceIdentifier A string that uniquely identifies the source.
- @param URL An HTTP(S) URL, absolute file URL, or local file URL relative to the
- current application’s resource bundle.
+ Use the `features` property instead to get an object representation of the
+ contents. Alternatively, use NSJSONSerialization with the value of this
+ property to transform it into Foundation types.
+
+ If the receiver was initialized using `-initWithIdentifier:URL:`, this property
+ is set to `nil`. This property is unavailable until the receiver is passed into
+ `-[MGLStyle addSource]`.
*/
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url NS_DESIGNATED_INITIALIZER;
+@property (nonatomic, readonly, nullable, copy) NSData *geoJSONData;
/**
- Initializes a source with the given identifier, a URL, and a dictionary of
- options for the source as specified by the
- <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">the
- style specification</a>.
+ The URL to the GeoJSON document that specifies the contents of the source.
- @param sourceIdentifier A string that uniquely identifies the source.
- @param URL An HTTP(S) URL, absolute file URL, or local file URL relative to the
- current application’s resource bundle.
- @param options An NSDictionary of attributes for this source.
+ If the receiver was initialized using `-initWithIdentifier:geoJSONData:`, this
+ property is set to `nil`.
*/
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER;
+@property (nonatomic, readonly, nullable) NSURL *URL;
@end
diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm
index 652644be47..458f062ad3 100644
--- a/platform/darwin/src/MGLGeoJSONSource.mm
+++ b/platform/darwin/src/MGLGeoJSONSource.mm
@@ -22,18 +22,9 @@ NSString * const MGLGeoJSONToleranceOption = @"MGLGeoJSONOptionsClusterTolerance
@implementation MGLGeoJSONSource
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier geoJSONData:(NSData *)data
+- (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *)data options:(NS_DICTIONARY_OF(NSString *, id) *)options
{
- if (self = [super initWithSourceIdentifier:sourceIdentifier])
- {
- _geoJSONData = data;
- }
- return self;
-}
-
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier geoJSONData:(NSData *)data options:(NS_DICTIONARY_OF(NSString *, id) *)options
-{
- if (self = [super initWithSourceIdentifier:sourceIdentifier])
+ if (self = [super initWithIdentifier:identifier])
{
_geoJSONData = data;
_options = options;
@@ -41,18 +32,9 @@ NSString * const MGLGeoJSONToleranceOption = @"MGLGeoJSONOptionsClusterTolerance
return self;
}
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url
-{
- if (self = [super initWithSourceIdentifier:sourceIdentifier])
- {
- _URL = url;
- }
- return self;
-}
-
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options
+- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options
{
- if (self = [super initWithSourceIdentifier:sourceIdentifier])
+ if (self = [super initWithIdentifier:identifier])
{
_URL = url;
_options = options;
@@ -113,7 +95,7 @@ NSString * const MGLGeoJSONToleranceOption = @"MGLGeoJSONOptionsClusterTolerance
- (std::unique_ptr<mbgl::style::Source>)mbglSource
{
- auto source = std::make_unique<mbgl::style::GeoJSONSource>(self.sourceIdentifier.UTF8String, [self geoJSONOptions]);
+ auto source = std::make_unique<mbgl::style::GeoJSONSource>(self.identifier.UTF8String, self.geoJSONOptions);
if (self.URL) {
NSURL *url = self.URL.mgl_URLByStandardizingScheme;
diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h
index d0a341d024..f8a9970f31 100644
--- a/platform/darwin/src/MGLLineStyleLayer.h
+++ b/platform/darwin/src/MGLLineStyleLayer.h
@@ -62,19 +62,7 @@ typedef NS_ENUM(NSUInteger, MGLLineStyleLayerLineTranslateAnchor) {
`MGLMapView` for its `style` and obtain existing layers using the
`-[MGLStyle layerWithIdentifier:]` method.
*/
-@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>.
-
- The predicate's left expression must be a string that identifies a feature
- property, or one of the special keys.
- */
-@property (nonatomic, nullable) NSPredicate *predicate;
+@interface MGLLineStyleLayer : MGLVectorStyleLayer
#pragma mark - Accessing the Layout Attributes
diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm
index b35d3921f5..6b58edcd61 100644
--- a/platform/darwin/src/MGLLineStyleLayer.mm
+++ b/platform/darwin/src/MGLLineStyleLayer.mm
@@ -12,36 +12,28 @@
@interface MGLLineStyleLayer ()
@property (nonatomic) mbgl::style::LineLayer *layer;
-@property (nonatomic, readwrite) NSString *layerIdentifier;
-@property (nonatomic, readwrite) NSString *sourceIdentifier;
-@property (nonatomic, readwrite) NSString *sourceLayerIdentifier;
@end
@implementation MGLLineStyleLayer
-@synthesize mapView;
-
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
+- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::LineLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
+ if (self = [super initWithIdentifier:identifier source:source]) {
+ _layer = new mbgl::style::LineLayer(identifier.UTF8String, source.identifier.UTF8String);
}
return self;
}
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
+- (NSString *)sourceLayerIdentifier
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::LineLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
- _layer->setSourceLayer(sourceLayer.UTF8String);
- }
- return self;
+ auto layerID = self.layer->getSourceLayer();
+ return layerID.empty() ? nil : @(layerID.c_str());
+}
+
+- (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier
+{
+ self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: "");
}
- (void)setPredicate:(NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLRasterSource.h b/platform/darwin/src/MGLRasterSource.h
index bf561df8da..78f5af8a6a 100644
--- a/platform/darwin/src/MGLRasterSource.h
+++ b/platform/darwin/src/MGLRasterSource.h
@@ -15,9 +15,49 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface MGLRasterSource : MGLSource
+#pragma mark Initializing a Source
+
+/**
+ Returns a raster source initialized with an identifier, TileJSON configuration
+ URL, and tile size.
+
+ After initializing and configuring the source, add it to a map view’s style
+ using the `-[MGLStyle addSource:]` method.
+
+ @param identifier A string that uniquely identifies the source in the style to
+ which it is added.
+ @param url A URL to a TileJSON configuration file describing the source’s
+ contents and other metadata.
+ @param tileSize The height and width (measured in points) at which to display
+ each tile in this source when the map’s zoom level is an integer.
+ @return An initialized raster source.
+ */
+- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url tileSize:(CGFloat)tileSize NS_DESIGNATED_INITIALIZER;
+
+/**
+ Returns a raster source initialized with the given identifier, tile size, and
+ tile set.
+
+ After initializing and configuring the source, add it to a map view’s style
+ using the `-[MGLStyle addSource:]` method.
+
+ @param identifier A string that uniquely identifies the source in the style to
+ which it is added.
+ @param tileSet A tile set describing the source’s contents and other metadata.
+ @param tileSize The height and width (measured in points) at which to display
+ each tile in this source when the map’s zoom level is an integer.
+ @return An initialized raster source.
+ */
+- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet tileSize:(CGFloat)tileSize NS_DESIGNATED_INITIALIZER;
+
+#pragma mark Accessing a Source’s Content
+
/**
- A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and
- `mapbox://<mapid>`.
+ A URL to a TileJSON configuration file describing the source’s contents and
+ other metadata.
+
+ The URL may be a full HTTP or HTTPS URL or a Mapbox URL indicating the tile
+ set’s map ID (`mapbox://<mapid>`).
@see <a href="https://www.mapbox.com/help/an-open-platform/#tilejson">The
TileJSON specification.</a>
@@ -25,8 +65,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly, copy) NSURL *URL;
/**
- The minimum visual size to display tiles for this source. Units in pixels.
- Defaults to `512` on each tile side.
+ The height and width (measured in points) at which to display each tile in this
+ source when the map’s zoom level is an integer.
+
+ A tile may be scaled up or down when the zoom level is between two integers.
+
+ The default value of this property is 512 points.
*/
@property (nonatomic, readonly, assign) NSUInteger tileSize;
@@ -40,26 +84,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, nullable) MGLTileSet *tileSet;
-/**
- Initializes a source with the given identifier, TileJSON configuration
- URL, and tile size.
-
- @param sourceIdentifier A string that uniquely identifies the source.
- @param url A URL to a TileJSON resource.
- @param tileSize The minimum visual size to display tiles for the source.
- */
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url tileSize:(CGFloat)tileSize;
-
-/**
- Initializes a source with the given identifier, tile size, and tile
- URL template set.
-
- @param sourceIdentifier A string that uniquely identifies the source.
- @param tileSet A tile set describing where to download tiles.
- @param tileSize The minimum visual size to display tiles for the source.
- */
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSet:(MGLTileSet *)tileSet tileSize:(CGFloat)tileSize;
-
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm
index 3d8a11101e..41b9a5b043 100644
--- a/platform/darwin/src/MGLRasterSource.mm
+++ b/platform/darwin/src/MGLRasterSource.mm
@@ -8,18 +8,18 @@
@implementation MGLRasterSource
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url tileSize:(CGFloat)tileSize
+- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url tileSize:(CGFloat)tileSize
{
- if (self = [super initWithSourceIdentifier:sourceIdentifier]) {
+ if (self = [super initWithIdentifier:identifier]) {
_URL = url;
_tileSize = tileSize;
}
return self;
}
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSet:(MGLTileSet *)tileSet tileSize:(CGFloat)tileSize;
+- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet tileSize:(CGFloat)tileSize;
{
- if (self = [super initWithSourceIdentifier:sourceIdentifier])
+ if (self = [super initWithIdentifier:identifier])
{
_tileSet = tileSet;
_tileSize = tileSize;
@@ -33,13 +33,13 @@
if (self.URL)
{
- source = std::make_unique<mbgl::style::RasterSource>(self.sourceIdentifier.UTF8String,
+ source = std::make_unique<mbgl::style::RasterSource>(self.identifier.UTF8String,
self.URL.mgl_URLByStandardizingScheme.absoluteString.UTF8String,
uint16_t(self.tileSize));
}
else
{
- source = std::make_unique<mbgl::style::RasterSource>(self.sourceIdentifier.UTF8String,
+ source = std::make_unique<mbgl::style::RasterSource>(self.identifier.UTF8String,
self.tileSet.mbglTileset,
uint16_t(self.tileSize));
diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h
index 7fdfb04c99..d0a08c8223 100644
--- a/platform/darwin/src/MGLRasterStyleLayer.h
+++ b/platform/darwin/src/MGLRasterStyleLayer.h
@@ -12,10 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
`MGLMapView` for its `style` and obtain existing layers using the
`-[MGLStyle layerWithIdentifier:]` method.
*/
-@interface MGLRasterStyleLayer : MGLBaseStyleLayer <MGLStyleLayer>
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source;
-
+@interface MGLRasterStyleLayer : MGLForegroundStyleLayer
#pragma mark - Accessing the Paint Attributes
diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm
index 74cffc2ed2..01d3bf2bca 100644
--- a/platform/darwin/src/MGLRasterStyleLayer.mm
+++ b/platform/darwin/src/MGLRasterStyleLayer.mm
@@ -12,28 +12,19 @@
@interface MGLRasterStyleLayer ()
@property (nonatomic) mbgl::style::RasterLayer *layer;
-@property (nonatomic, readwrite) NSString *layerIdentifier;
-@property (nonatomic, readwrite) NSString *sourceIdentifier;
-@property (nonatomic, readwrite) NSString *sourceLayerIdentifier;
@end
@implementation MGLRasterStyleLayer
-@synthesize mapView;
-
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
+- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::RasterLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
+ if (self = [super initWithIdentifier:identifier source:source]) {
+ _layer = new mbgl::style::RasterLayer(identifier.UTF8String, source.identifier.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 0d0317cb65..720ee4547e 100644
--- a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs
+++ b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs
@@ -14,11 +14,15 @@
@implementation MGL<%- camelize(type) %>LayerTests
- (void)test<%- camelize(type) %>Layer {
+<% if (type === 'background') { -%>
+ MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithIdentifier:@"layerID"];
+<% } else { -%>
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" source:source];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil];
[self.mapView.style addSource:source];
+ MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithIdentifier:@"layerID" source:source];
+<% } -%>
[self.mapView.style addLayer:layer];
<% for (const property of layoutProperties) { -%>
@@ -28,7 +32,8 @@ MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer
<%- testImplementation(property, type) %>
<% } -%>
- MGL<%- camelize(type) %>StyleLayer *gLayer = [self.mapView.style layerWithIdentifier:@"layerID"];
+ MGL<%- camelize(type) %>StyleLayer *gLayer = (MGL<%- camelize(type) %>StyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"];
+ XCTAssertTrue([gLayer isKindOfClass:[MGL<%- camelize(type) %>StyleLayer class]]);
<% for (const property of layoutProperties) { -%>
<%- testGetterImplementation(property, type) %>
<% } -%>
diff --git a/platform/darwin/src/MGLSource.h b/platform/darwin/src/MGLSource.h
index bb8f990828..79f6ce491f 100644
--- a/platform/darwin/src/MGLSource.h
+++ b/platform/darwin/src/MGLSource.h
@@ -10,16 +10,25 @@
*/
@interface MGLSource : NSObject
+#pragma mark Initializing a Source
+
/**
- A string that uniquely identifies the source.
+ Returns a source initialized with an identifier.
+
+ After initializing and configuring the source, add it to a map view’s style
+ using the `-[MGLStyle addSource:]` method.
+
+ @param identifier A string that uniquely identifies the source in the style to
+ which it is added.
+ @return An initialized source.
*/
-@property (nonatomic, copy) NSString *sourceIdentifier;
+- (instancetype)initWithIdentifier:(NSString *)identifier;
-/**
- Initializes a source with the given identifier.
+#pragma mark Identifying a Source
- @param sourceIdentifier A string that uniquely identifies the source.
+/**
+ A string that uniquely identifies the source in the style to which it is added.
*/
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier;
+@property (nonatomic, copy) NSString *identifier;
@end
diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm
index cdf003cb00..85bbc06342 100644
--- a/platform/darwin/src/MGLSource.mm
+++ b/platform/darwin/src/MGLSource.mm
@@ -1,18 +1,27 @@
-#import "MGLSource.h"
+#import "MGLSource_Private.h"
#include <mbgl/style/source.hpp>
+@interface MGLSource ()
+
+@property (nonatomic) mbgl::style::Source *source;
+
+@end
+
@implementation MGLSource
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier {
+- (instancetype)initWithIdentifier:(NSString *)identifier {
if (self = [super init]) {
- _sourceIdentifier = sourceIdentifier;
+ _identifier = identifier;
}
return self;
}
- (std::unique_ptr<mbgl::style::Source>)mbglSource {
- [NSException raise:@"Subclasses must override this method" format:@""];
+ [NSException raise:@"MGLAbstractClassException" format:
+ @"The source %@ cannot be added to the style. "
+ @"Make sure the source was created as a member of a concrete subclass of MGLSource.",
+ NSStringFromClass(self)];
return nil;
}
diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h
index d4972a3d31..d4868681e1 100644
--- a/platform/darwin/src/MGLStyle.h
+++ b/platform/darwin/src/MGLStyle.h
@@ -178,42 +178,43 @@ static const NSInteger MGLStyleDefaultVersion = 9;
Returns a layer that conforms to `MGLStyleLayer` if any layer with the given
identifier was found.
- @return layer A layer instance of the corresponding type.
+ @return An instance of a concrete subclass of `MGLStyleLayer` associated with
+ the given identifier.
*/
-- (nullable id <MGLStyleLayer>)layerWithIdentifier:(NSString *)identifier;
+- (nullable MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier;
/**
Returns a source if any source with the given identifier was found.
- @return source An instance of an `MGLSource` subclass.
+ @return An instance of a concrete subclass of `MGLSource` associated with the
+ given identifier.
*/
- (nullable MGLSource *)sourceWithIdentifier:(NSString *)identifier;
/**
Adds a new layer on top of existing layers.
- @param styleLayer The layer object to add to the map view. This object
- must conform to the `MGLStyleLayer` protocol.
+ @param layer The layer object to add to the map view. This object must be an
+ instance of a concrete subclass of `MGLStyleLayer`.
*/
-- (void)addLayer:(id <MGLStyleLayer>)styleLayer;
+- (void)addLayer:(MGLStyleLayer *)layer;
/**
Inserts a new layer below another layer.
- @param styleLayer Layer to be inserted.
+ @param layer Layer to be inserted.
@param belowLayer A layer that's already on the map view.
*/
-- (void)insertLayer:(id <MGLStyleLayer>)styleLayer
- belowLayer:(id <MGLStyleLayer>)belowLayer;
+- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer;
/**
Removes a layer from the map view.
- @param styleLayer The layer object to remove from the map view. This object
+ @param layer The layer object to remove from the map view. This object
must conform to the `MGLStyleLayer` protocol.
*/
-- (void)removeLayer:(id <MGLStyleLayer>)styleLayer;
+- (void)removeLayer:(MGLStyleLayer *)layer;
/**
Adds a new source to the map view.
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index 79d7d7e0f6..cd9c4465b5 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -92,95 +92,113 @@ static NSURL *MGLStyleURL_emerald;
return @(self.mapView.mbglMap->getStyleName().c_str());
}
-- (id <MGLStyleLayer>)layerWithIdentifier:(NSString *)identifier
+- (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier
{
- auto layer = self.mapView.mbglMap->getLayer(identifier.UTF8String);
-
- if (!layer) return nil;
+ auto mbglLayer = self.mapView.mbglMap->getLayer(identifier.UTF8String);
+ if (!mbglLayer) {
+ return nil;
+ }
- Class clazz = [self classFromLayer:layer];
+ MGLStyleLayer *styleLayer;
+ if (auto fillLayer = mbglLayer->as<mbgl::style::FillLayer>()) {
+ MGLSource *source = [self sourceWithIdentifier:@(fillLayer->getSourceID().c_str())];
+ styleLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:identifier source:source];
+ } else if (auto lineLayer = mbglLayer->as<mbgl::style::LineLayer>()) {
+ MGLSource *source = [self sourceWithIdentifier:@(lineLayer->getSourceID().c_str())];
+ styleLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:identifier source:source];
+ } else if (auto symbolLayer = mbglLayer->as<mbgl::style::SymbolLayer>()) {
+ MGLSource *source = [self sourceWithIdentifier:@(symbolLayer->getSourceID().c_str())];
+ styleLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:identifier source:source];
+ } else if (auto rasterLayer = mbglLayer->as<mbgl::style::RasterLayer>()) {
+ MGLSource *source = [self sourceWithIdentifier:@(rasterLayer->getSourceID().c_str())];
+ styleLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:identifier source:source];
+ } else if (auto circleLayer = mbglLayer->as<mbgl::style::CircleLayer>()) {
+ MGLSource *source = [self sourceWithIdentifier:@(circleLayer->getSourceID().c_str())];
+ styleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:identifier source:source];
+ } else if (mbglLayer->as<mbgl::style::BackgroundLayer>()) {
+ styleLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:identifier];
+ } else {
+ NSAssert(NO, @"Unrecognized layer type");
+ return nil;
+ }
- id <MGLStyleLayer, MGLStyleLayer_Private> styleLayer = [[clazz alloc] init];
- styleLayer.layerIdentifier = identifier;
- styleLayer.layer = layer;
- styleLayer.mapView = self.mapView;
+ styleLayer.layer = mbglLayer;
return styleLayer;
}
- (MGLSource *)sourceWithIdentifier:(NSString *)identifier
{
- auto s = self.mapView.mbglMap->getSource(identifier.UTF8String);
-
- if (!s) return nil;
+ auto mbglSource = self.mapView.mbglMap->getSource(identifier.UTF8String);
+ if (!mbglSource) {
+ return nil;
+ }
- Class clazz = [self classFromSource:s];
+ // TODO: Fill in options specific to the respective source classes
+ // https://github.com/mapbox/mapbox-gl-native/issues/6584
+ MGLSource *source;
+ if (mbglSource->is<mbgl::style::VectorSource>()) {
+ source = [[MGLVectorSource alloc] initWithIdentifier:identifier];
+ } else if (mbglSource->is<mbgl::style::GeoJSONSource>()) {
+ source = [[MGLGeoJSONSource alloc] initWithIdentifier:identifier];
+ } else if (mbglSource->is<mbgl::style::RasterSource>()) {
+ source = [[MGLRasterSource alloc] initWithIdentifier:identifier];
+ } else {
+ NSAssert(NO, @"Unrecognized source type");
+ return nil;
+ }
- MGLSource *source = [[clazz alloc] init];
- source.sourceIdentifier = identifier;
- source.source = s;
+ source.source = mbglSource;
return source;
}
-- (Class)classFromSource:(mbgl::style::Source *)source
+- (void)removeLayer:(MGLStyleLayer *)layer
{
- if (source->is<mbgl::style::VectorSource>()) {
- return MGLVectorSource.class;
- } else if (source->is<mbgl::style::GeoJSONSource>()) {
- return MGLGeoJSONSource.class;
- } else if (source->is<mbgl::style::RasterSource>()) {
- return MGLRasterSource.class;
- }
-
- [NSException raise:@"Source type not handled" format:@""];
- return Nil;
+ self.mapView.mbglMap->removeLayer(layer.identifier.UTF8String);
}
-- (Class)classFromLayer:(mbgl::style::Layer *)layer
+- (void)addLayer:(MGLStyleLayer *)layer
{
- if (layer->is<mbgl::style::FillLayer>()) {
- return MGLFillStyleLayer.class;
- } else if (layer->is<mbgl::style::LineLayer>()) {
- return MGLLineStyleLayer.class;
- } else if (layer->is<mbgl::style::SymbolLayer>()) {
- return MGLSymbolStyleLayer.class;
- } else if (layer->is<mbgl::style::RasterLayer>()) {
- return MGLRasterStyleLayer.class;
- } else if (layer->is<mbgl::style::CircleLayer>()) {
- return MGLCircleStyleLayer.class;
- } else if (layer->is<mbgl::style::BackgroundLayer>()) {
- return MGLBackgroundStyleLayer.class;
+ if (!layer.layer) {
+ [NSException raise:NSInvalidArgumentException format:
+ @"The style layer %@ cannot be added to the style. "
+ @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
+ NSStringFromClass(self)];
}
- [NSException raise:@"Layer type not handled" format:@""];
- return Nil;
-}
-
-- (void)removeLayer:(id <MGLStyleLayer_Private>)styleLayer
-{
- self.mapView.mbglMap->removeLayer(styleLayer.layer->getID());
-}
-
-- (void)addLayer:(id <MGLStyleLayer, MGLStyleLayer_Private>)styleLayer
-{
- self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(styleLayer.layer));
+
+ self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer));
}
-- (void)insertLayer:(id <MGLStyleLayer, MGLStyleLayer_Private>)styleLayer
- belowLayer:(id <MGLStyleLayer, MGLStyleLayer_Private>)belowLayer
+- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer
{
- const mbgl::optional<std::string> belowLayerId{[belowLayer layerIdentifier].UTF8String};
- self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(styleLayer.layer), belowLayerId);
+ if (!layer.layer) {
+ [NSException raise:NSInvalidArgumentException
+ format:
+ @"The style layer %@ cannot be added to the style. "
+ @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
+ NSStringFromClass(layer)];
+ }
+ if (!otherLayer.layer) {
+ [NSException raise:NSInvalidArgumentException
+ format:
+ @"A style layer cannot be placed before %@ in the style. "
+ @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
+ NSStringFromClass(otherLayer)];
+ }
+
+ const mbgl::optional<std::string> belowLayerId{otherLayer.identifier.UTF8String};
+ self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer), belowLayerId);
}
- (void)addSource:(MGLSource *)source
{
- self.mapView.mbglMap->addSource([source mbglSource]);
+ self.mapView.mbglMap->addSource(source.mbglSource);
}
- (void)removeSource:(MGLSource *)source
{
- self.mapView.mbglMap->removeSource(source.sourceIdentifier.UTF8String);
+ self.mapView.mbglMap->removeSource(source.identifier.UTF8String);
}
- (NS_ARRAY_OF(NSString *) *)styleClasses
diff --git a/platform/darwin/src/MGLStyleLayer.h b/platform/darwin/src/MGLStyleLayer.h
index d4ed525a3f..763854f44c 100644
--- a/platform/darwin/src/MGLStyleLayer.h
+++ b/platform/darwin/src/MGLStyleLayer.h
@@ -1,12 +1,74 @@
#import <Foundation/Foundation.h>
-@class MGLMapView;
+#import "MGLBaseStyleLayer.h"
-@protocol MGLStyleLayer <NSObject>
+NS_ASSUME_NONNULL_BEGIN
-@property (nonatomic, weak) MGLMapView *mapView;
-@property (nonatomic, copy, readonly) NSString *layerIdentifier;
-@property (nonatomic, readonly) NSString *sourceIdentifier;
-@property (nonatomic, readonly) NSString *sourceLayerIdentifier;
+@class MGLSource;
+
+/**
+ `MGLForegroundStyleLayer` is an abstract superclass for style layers whose
+ content is defined by an `MGLSource` object.
+
+ Do not create instances of this class directly, and do not create your own
+ subclasses of this class. Instead, create instances of `MGLRasterStyleLayer`
+ and the concrete subclasses of `MGLVectorStyleLayer`.
+ */
+@interface MGLForegroundStyleLayer : MGLStyleLayer
+
+#pragma mark Initializing a Style Layer
+
+/**
+ Returns a foreground style layer initialized with an identifier and source.
+
+ After initializing and configuring the style layer, add it to a map view’s
+ style using the `-[MGLStyle addLayer:]` or
+ `-[MGLStyle insertLayer:belowLayer:]` method.
+
+ @param identifier A string that uniquely identifies the source in the style to
+ which it is added.
+ @param source The source from which to obtain the data to style. If the source
+ has not yet been added to the current style, the behavior is undefined.
+ @return An initialized foreground style layer.
+ */
+- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source NS_DESIGNATED_INITIALIZER;
+
+#pragma mark Specifying a Style Layer’s Content
+
+/**
+ Identifier of the source from which the receiver obtains the data to style.
+ */
+@property (nonatomic, readonly, nullable) NSString *sourceIdentifier;
+
+@end
+
+/**
+ `MGLVectorStyleLayer` is an abstract superclass for style layers whose content
+ is defined by an `MGLGeoJSONSource` or `MGLVectorSource` object.
+
+ Do not create instances of this class directly, and do not create your own
+ subclasses of this class. Instead, create instances of the following concrete
+ subclasses: `MGLCircleStyleLayer`, `MGLFillStyleLayer`, `MGLLineStyleLayer`,
+ and `MGLSymbolStyleLayer`.
+ */
+@interface MGLVectorStyleLayer : MGLForegroundStyleLayer
+
+#pragma mark Refining a Style Layer’s Content
+
+/**
+ Identifier of the layer within the source identified by the `sourceIdentifier`
+ property from which the receiver obtains the data to style.
+ */
+@property (nonatomic, nullable) NSString *sourceLayerIdentifier;
+
+/**
+ A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>.
+
+ The predicate's left expression must be a string that identifies a feature
+ property, or one of the special keys.
+ */
+@property (nonatomic, nullable) NSPredicate *predicate;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLStyleLayer.h.ejs b/platform/darwin/src/MGLStyleLayer.h.ejs
index 40b750e73c..e27808bfc7 100644
--- a/platform/darwin/src/MGLStyleLayer.h.ejs
+++ b/platform/darwin/src/MGLStyleLayer.h.ejs
@@ -60,28 +60,16 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(type) %>StyleLayer<%- camelize(prope
`-[MGLStyle layerWithIdentifier:]` method.
*/
<% } -%>
-@interface MGL<%- camelize(type) %>StyleLayer : MGLBaseStyleLayer <MGLStyleLayer>
-<% if (type == 'background') { -%>
+@interface MGL<%- camelize(type) %>StyleLayer : <%-
+(type === 'background' ? 'MGLStyleLayer' :
+ (type === 'raster' ? 'MGLForegroundStyleLayer' :
+ 'MGLVectorStyleLayer'))
+%>
+<% if (type === 'background') { -%>
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier;
+- (instancetype)initWithIdentifier:(NSString *)identifier NS_DESIGNATED_INITIALIZER;
<% } -%>
-- (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>.
-
- The predicate's left expression must be a string that identifies a feature
- property, or one of the special keys.
- */
-@property (nonatomic, nullable) NSPredicate *predicate;
-
-<% } -%>
<% if (layoutProperties.length) { -%>
#pragma mark - Accessing the Layout Attributes
diff --git a/platform/darwin/src/MGLStyleLayer.mm b/platform/darwin/src/MGLStyleLayer.mm
index 43d98d62dc..b0fbb38dc9 100644
--- a/platform/darwin/src/MGLStyleLayer.mm
+++ b/platform/darwin/src/MGLStyleLayer.mm
@@ -1,4 +1,28 @@
-#import "MGLStyleLayer.h"
-
#import "MGLStyleLayer_Private.h"
-#import "MGLMapView_Private.h"
+#import "MGLSource.h"
+
+@implementation MGLForegroundStyleLayer
+
+- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source {
+ if (self = [super initWithIdentifier:identifier]) {
+ _sourceIdentifier = source.identifier;
+ }
+ return self;
+}
+
+@end
+
+@implementation MGLVectorStyleLayer
+
+- (void)setPredicate:(NSPredicate *)predicate {
+ [NSException raise:@"MGLAbstractClassException"
+ format:@"MGLVectorLayer is an abstract class"];
+}
+
+- (NSPredicate *)predicate {
+ [NSException raise:@"MGLAbstractClassException"
+ format:@"MGLVectorLayer is an abstract class"];
+ return nil;
+}
+
+@end
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);
diff --git a/platform/darwin/src/MGLStyleLayer_Private.h b/platform/darwin/src/MGLStyleLayer_Private.h
index bc3d87bcb7..a499775a52 100644
--- a/platform/darwin/src/MGLStyleLayer_Private.h
+++ b/platform/darwin/src/MGLStyleLayer_Private.h
@@ -19,12 +19,9 @@
#import "NSColor+MGLStyleAttributeAdditions_Private.h"
#endif
-@class MGLMapView;
+@interface MGLStyleLayer (Private)
-@protocol MGLStyleLayer_Private <MGLStyleLayer>
-
-@property (nonatomic, weak) MGLMapView *mapView;
-@property (nonatomic, readwrite, copy) NSString *layerIdentifier;
+@property (nonatomic, readwrite, copy) NSString *identifier;
@property (nonatomic) mbgl::style::Layer *layer;
@end
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h
index b805ee18da..45387bdf87 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.h
+++ b/platform/darwin/src/MGLSymbolStyleLayer.h
@@ -208,19 +208,7 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextTranslateAnchor) {
`MGLMapView` for its `style` and obtain existing layers using the
`-[MGLStyle layerWithIdentifier:]` method.
*/
-@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>.
-
- The predicate's left expression must be a string that identifies a feature
- property, or one of the special keys.
- */
-@property (nonatomic, nullable) NSPredicate *predicate;
+@interface MGLSymbolStyleLayer : MGLVectorStyleLayer
#pragma mark - Accessing the Layout Attributes
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm
index 4d9b20fbcb..48673acf81 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.mm
+++ b/platform/darwin/src/MGLSymbolStyleLayer.mm
@@ -12,36 +12,28 @@
@interface MGLSymbolStyleLayer ()
@property (nonatomic) mbgl::style::SymbolLayer *layer;
-@property (nonatomic, readwrite) NSString *layerIdentifier;
-@property (nonatomic, readwrite) NSString *sourceIdentifier;
-@property (nonatomic, readwrite) NSString *sourceLayerIdentifier;
@end
@implementation MGLSymbolStyleLayer
-@synthesize mapView;
-
-
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
+- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::SymbolLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
+ if (self = [super initWithIdentifier:identifier source:source]) {
+ _layer = new mbgl::style::SymbolLayer(identifier.UTF8String, source.identifier.UTF8String);
}
return self;
}
-- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
+- (NSString *)sourceLayerIdentifier
{
- if (self = [super init]) {
- _layerIdentifier = layerIdentifier;
- _sourceIdentifier = source.sourceIdentifier;
- _layer = new mbgl::style::SymbolLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
- _layer->setSourceLayer(sourceLayer.UTF8String);
- }
- return self;
+ auto layerID = self.layer->getSourceLayer();
+ return layerID.empty() ? nil : @(layerID.c_str());
+}
+
+- (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier
+{
+ self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: "");
}
- (void)setPredicate:(NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLVectorSource.h b/platform/darwin/src/MGLVectorSource.h
index 2106a5cf42..6cfab09489 100644
--- a/platform/darwin/src/MGLVectorSource.h
+++ b/platform/darwin/src/MGLVectorSource.h
@@ -13,27 +13,56 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface MGLVectorSource : MGLSource
-@property (nonatomic, readonly, copy) NSURL *URL;
-@property (nonatomic, readonly, nullable) MGLTileSet *tileSet;
+#pragma mark Initializing a Source
/**
- Initializes and returns a vector source from a remote URL.
+ Returns a vector source initialized with an identifier and TileJSON URL.
- @param sourceIdentifier The source identifier.
- @param URL A remote URL holding the vector source data.
+ After initializing and configuring the source, add it to a map view’s style
+ using the `-[MGLStyle addSource:]` method.
- @return An `MGLVectorSource`.
+ @param identifier A string that uniquely identifies the source in the style to
+ which it is added.
+ @param url A URL to a TileJSON configuration file describing the source’s
+ contents and other metadata.
+ @return An initialized vector source.
*/
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url;
+- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url NS_DESIGNATED_INITIALIZER;
/**
- Initializes a source with the given identifier, tile size, and tile
- URL template set.
+ Returns a vector source initialized an identifier and tile set.
- @param sourceIdentifier A string that uniquely identifies the source.
- @param tileSet A tile set describing where to download tiles.
+ After initializing and configuring the source, add it to a map view’s style
+ using the `-[MGLStyle addSource:]` method.
+
+ @param identifier A string that uniquely identifies the source in the style to
+ which it is added.
+ @param tileSet A tile set describing the source’s contents and other metadata.
+ @return An initialized vector source.
*/
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSet:(MGLTileSet *)tileSet;
+- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet NS_DESIGNATED_INITIALIZER;
+
+#pragma mark Accessing a Source’s Content
+
+/**
+ A URL to a TileJSON configuration file describing the source’s contents and
+ other metadata.
+
+ The URL may be a full HTTP or HTTPS URL or a Mapbox URL indicating the tile
+ set’s map ID (`mapbox://<mapid>`).
+
+ If the receiver was initialized using `-initWithIdentifier:tileSet:`, this
+ property is set to `nil`.
+ */
+@property (nonatomic, readonly, copy) NSURL *URL;
+
+/**
+ A tile set describing the source’s contents and other metadata.
+
+ If the receiver was initialized using `-initWithIdentifier:URL:`, this property
+ is set to `nil`.
+ */
+@property (nonatomic, readonly, nullable) MGLTileSet *tileSet;
@end
diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm
index 2ab9627ef5..3597812359 100644
--- a/platform/darwin/src/MGLVectorSource.mm
+++ b/platform/darwin/src/MGLVectorSource.mm
@@ -10,18 +10,18 @@
static NSString *MGLVectorSourceType = @"vector";
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url
+- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url
{
- if (self = [super initWithSourceIdentifier:sourceIdentifier])
+ if (self = [super initWithIdentifier:identifier])
{
_URL = url;
}
return self;
}
-- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSet:(MGLTileSet *)tileSet
+- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet
{
- if (self = [super initWithSourceIdentifier:sourceIdentifier])
+ if (self = [super initWithIdentifier:identifier])
{
_tileSet = tileSet;
}
@@ -34,12 +34,12 @@ static NSString *MGLVectorSourceType = @"vector";
if (self.URL)
{
- source = std::make_unique<mbgl::style::VectorSource>(self.sourceIdentifier.UTF8String,
+ source = std::make_unique<mbgl::style::VectorSource>(self.identifier.UTF8String,
self.URL.mgl_URLByStandardizingScheme.absoluteString.UTF8String);
}
else
{
- source = std::make_unique<mbgl::style::VectorSource>(self.sourceIdentifier.UTF8String,
+ source = std::make_unique<mbgl::style::VectorSource>(self.identifier.UTF8String,
self.tileSet.mbglTileset);
}
diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.m b/platform/darwin/test/MGLBackgroundStyleLayerTests.m
index f4fdae61a4..2681b773ae 100644
--- a/platform/darwin/test/MGLBackgroundStyleLayerTests.m
+++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.m
@@ -9,18 +9,15 @@
@implementation MGLBackgroundLayerTests
- (void)testBackgroundLayer {
- 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" source:source];
- [self.mapView.style addSource:source];
+ MGLBackgroundStyleLayer *layer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"layerID"];
[self.mapView.style addLayer:layer];
layer.backgroundColor = [MGLRuntimeStylingHelper testColor];
layer.backgroundPattern = [MGLRuntimeStylingHelper testString];
layer.backgroundOpacity = [MGLRuntimeStylingHelper testNumber];
- MGLBackgroundStyleLayer *gLayer = [self.mapView.style layerWithIdentifier:@"layerID"];
+ MGLBackgroundStyleLayer *gLayer = (MGLBackgroundStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"];
+ XCTAssertTrue([gLayer isKindOfClass:[MGLBackgroundStyleLayer class]]);
XCTAssertEqualObjects(gLayer.backgroundColor, [MGLRuntimeStylingHelper testColor]);
XCTAssertEqualObjects(gLayer.backgroundPattern, [MGLRuntimeStylingHelper testString]);
XCTAssertEqualObjects(gLayer.backgroundOpacity, [MGLRuntimeStylingHelper testNumber]);
diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.m b/platform/darwin/test/MGLCircleStyleLayerTests.m
index 0e70c3f836..7b26f21fce 100644
--- a/platform/darwin/test/MGLCircleStyleLayerTests.m
+++ b/platform/darwin/test/MGLCircleStyleLayerTests.m
@@ -11,9 +11,9 @@
- (void)testCircleLayer {
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" source:source];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil];
[self.mapView.style addSource:source];
+ MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layerID" source:source];
[self.mapView.style addLayer:layer];
layer.circleRadius = [MGLRuntimeStylingHelper testNumber];
@@ -24,7 +24,8 @@ MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithLayerIdentifie
layer.circleTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLCircleStyleLayerCircleTranslateAnchorViewport type:@encode(MGLCircleStyleLayerCircleTranslateAnchor)];
layer.circlePitchScale = [MGLRuntimeStylingHelper testEnum:MGLCircleStyleLayerCirclePitchScaleViewport type:@encode(MGLCircleStyleLayerCirclePitchScale)];
- MGLCircleStyleLayer *gLayer = [self.mapView.style layerWithIdentifier:@"layerID"];
+ MGLCircleStyleLayer *gLayer = (MGLCircleStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"];
+ XCTAssertTrue([gLayer isKindOfClass:[MGLCircleStyleLayer class]]);
XCTAssertEqualObjects(gLayer.circleRadius, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.circleColor, [MGLRuntimeStylingHelper testColor]);
XCTAssertEqualObjects(gLayer.circleBlur, [MGLRuntimeStylingHelper testNumber]);
diff --git a/platform/darwin/test/MGLFillStyleLayerTests.m b/platform/darwin/test/MGLFillStyleLayerTests.m
index 7994d76517..779851a279 100644
--- a/platform/darwin/test/MGLFillStyleLayerTests.m
+++ b/platform/darwin/test/MGLFillStyleLayerTests.m
@@ -11,9 +11,9 @@
- (void)testFillLayer {
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" source:source];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil];
[self.mapView.style addSource:source];
+ MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"layerID" source:source];
[self.mapView.style addLayer:layer];
layer.fillAntialias = [MGLRuntimeStylingHelper testBool];
@@ -24,7 +24,8 @@ MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"
layer.fillTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLFillStyleLayerFillTranslateAnchorViewport type:@encode(MGLFillStyleLayerFillTranslateAnchor)];
layer.fillPattern = [MGLRuntimeStylingHelper testString];
- MGLFillStyleLayer *gLayer = [self.mapView.style layerWithIdentifier:@"layerID"];
+ MGLFillStyleLayer *gLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"];
+ XCTAssertTrue([gLayer isKindOfClass:[MGLFillStyleLayer class]]);
XCTAssertEqualObjects(gLayer.fillAntialias, [MGLRuntimeStylingHelper testBool]);
XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.fillColor, [MGLRuntimeStylingHelper testColor]);
diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm
index d73313e27d..2bb188575b 100644
--- a/platform/darwin/test/MGLFilterTests.mm
+++ b/platform/darwin/test/MGLFilterTests.mm
@@ -18,9 +18,9 @@
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"];
NSURL *url = [NSURL fileURLWithPath:filePath];
NSData *geoJSONData = [NSData dataWithContentsOfURL:url];
- source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"test-source" geoJSONData:geoJSONData];
+ source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"test-source" geoJSONData:geoJSONData options:nil];
[self.mapView.style addSource:source];
- layer = [[MGLLineStyleLayer alloc] initWithLayerIdentifier:@"test-layer" source:source];
+ layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"test-layer" source:source];
}
- (void)tearDown
diff --git a/platform/darwin/test/MGLLineStyleLayerTests.m b/platform/darwin/test/MGLLineStyleLayerTests.m
index ff607f2e2b..165c29900a 100644
--- a/platform/darwin/test/MGLLineStyleLayerTests.m
+++ b/platform/darwin/test/MGLLineStyleLayerTests.m
@@ -11,9 +11,9 @@
- (void)testLineLayer {
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" source:source];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil];
[self.mapView.style addSource:source];
+ MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"layerID" source:source];
[self.mapView.style addLayer:layer];
layer.lineCap = [MGLRuntimeStylingHelper testEnum:MGLLineStyleLayerLineCapSquare type:@encode(MGLLineStyleLayerLineCap)];
@@ -31,7 +31,8 @@ MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithLayerIdentifier:@"
layer.lineDasharray = [MGLRuntimeStylingHelper testDashArray];
layer.linePattern = [MGLRuntimeStylingHelper testString];
- MGLLineStyleLayer *gLayer = [self.mapView.style layerWithIdentifier:@"layerID"];
+ MGLLineStyleLayer *gLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"];
+ XCTAssertTrue([gLayer isKindOfClass:[MGLLineStyleLayer class]]);
XCTAssert([(NSValue *)gLayer.lineCap isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLLineStyleLayerLineCapSquare type:@encode(MGLLineStyleLayerLineCap)]], @"%@ is not equal to %@", gLayer.lineCap, [MGLRuntimeStylingHelper testEnum:MGLLineStyleLayerLineCapSquare type:@encode(MGLLineStyleLayerLineCap)]);
XCTAssert([(NSValue *)gLayer.lineJoin isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLLineStyleLayerLineJoinMiter type:@encode(MGLLineStyleLayerLineJoin)]], @"%@ is not equal to %@", gLayer.lineJoin, [MGLRuntimeStylingHelper testEnum:MGLLineStyleLayerLineJoinMiter type:@encode(MGLLineStyleLayerLineJoin)]);
XCTAssertEqualObjects(gLayer.lineMiterLimit, [MGLRuntimeStylingHelper testNumber]);
diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.m b/platform/darwin/test/MGLRasterStyleLayerTests.m
index 7158c9aef2..f68f6d3283 100644
--- a/platform/darwin/test/MGLRasterStyleLayerTests.m
+++ b/platform/darwin/test/MGLRasterStyleLayerTests.m
@@ -11,9 +11,9 @@
- (void)testRasterLayer {
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" source:source];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil];
[self.mapView.style addSource:source];
+ MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"layerID" source:source];
[self.mapView.style addLayer:layer];
layer.rasterOpacity = [MGLRuntimeStylingHelper testNumber];
@@ -24,7 +24,8 @@ MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithLayerIdentifie
layer.rasterContrast = [MGLRuntimeStylingHelper testNumber];
layer.rasterFadeDuration = [MGLRuntimeStylingHelper testNumber];
- MGLRasterStyleLayer *gLayer = [self.mapView.style layerWithIdentifier:@"layerID"];
+ MGLRasterStyleLayer *gLayer = (MGLRasterStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"];
+ XCTAssertTrue([gLayer isKindOfClass:[MGLRasterStyleLayer class]]);
XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterHueRotate, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMin, [MGLRuntimeStylingHelper testNumber]);
diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.m b/platform/darwin/test/MGLSymbolStyleLayerTests.m
index 096a49b571..798cfca710 100644
--- a/platform/darwin/test/MGLSymbolStyleLayerTests.m
+++ b/platform/darwin/test/MGLSymbolStyleLayerTests.m
@@ -11,9 +11,9 @@
- (void)testSymbolLayer {
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" source:source];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil];
[self.mapView.style addSource:source];
+ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"layerID" source:source];
[self.mapView.style addLayer:layer];
layer.symbolPlacement = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerSymbolPlacementLine type:@encode(MGLSymbolStyleLayerSymbolPlacement)];
@@ -65,7 +65,8 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie
layer.textTranslate = [MGLRuntimeStylingHelper testOffset];
layer.textTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextTranslateAnchorViewport type:@encode(MGLSymbolStyleLayerTextTranslateAnchor)];
- MGLSymbolStyleLayer *gLayer = [self.mapView.style layerWithIdentifier:@"layerID"];
+ MGLSymbolStyleLayer *gLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"];
+ XCTAssertTrue([gLayer isKindOfClass:[MGLSymbolStyleLayer class]]);
XCTAssert([(NSValue *)gLayer.symbolPlacement isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerSymbolPlacementLine type:@encode(MGLSymbolStyleLayerSymbolPlacement)]], @"%@ is not equal to %@", gLayer.symbolPlacement, [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerSymbolPlacementLine type:@encode(MGLSymbolStyleLayerSymbolPlacement)]);
XCTAssertEqualObjects(gLayer.symbolSpacing, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.symbolAvoidEdges, [MGLRuntimeStylingHelper testBool]);
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index feebb59a23..5a3c56af69 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -677,10 +677,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
- (void)styleRasterLayer
{
NSURL *rasterURL = [NSURL URLWithString:@"mapbox://mapbox.satellite"];
- MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithSourceIdentifier:@"my-raster-source" URL:rasterURL tileSize:512];
+ MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"my-raster-source" URL:rasterURL tileSize:512];
[self.mapView.style addSource:rasterSource];
- MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithLayerIdentifier:@"my-raster-layer" source:rasterSource];
+ MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"my-raster-layer" source:rasterSource];
MGLStyleAttributeFunction *opacityFunction = [[MGLStyleAttributeFunction alloc] init];
opacityFunction.stops = @{@20.0f: @1.0f,
@5.0f: @0.0f};
@@ -692,10 +692,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
{
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"];
NSURL *geoJSONURL = [NSURL fileURLWithPath:filePath];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"ams" URL:geoJSONURL];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"ams" URL:geoJSONURL options:nil];
[self.mapView.style addSource:source];
- MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"test" source:source];
+ MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"test" source:source];
fillLayer.fillColor = [UIColor purpleColor];
[self.mapView.style addLayer:fillLayer];
}
diff --git a/platform/ios/jazzy.yml b/platform/ios/jazzy.yml
index b2b3d3878e..c41dddc899 100644
--- a/platform/ios/jazzy.yml
+++ b/platform/ios/jazzy.yml
@@ -53,14 +53,15 @@ custom_categories:
- MGLShapeCollectionFeature
- name: Style Layers
children:
- - MGLStyleLayer
- - MGLBaseStyleLayer
- MGLBackgroundStyleLayer
- MGLCircleStyleLayer
- MGLFillStyleLayer
+ - MGLForegroundStyleLayer
- MGLLineStyleLayer
- MGLRasterStyleLayer
+ - MGLStyleLayer
- MGLSymbolStyleLayer
+ - MGLVectorStyleLayer
- name: Data Sources
children:
- MGLSource
diff --git a/platform/ios/test/MGLGeoJSONSourceTests.mm b/platform/ios/test/MGLGeoJSONSourceTests.mm
index 76353dc76b..eed2112211 100644
--- a/platform/ios/test/MGLGeoJSONSourceTests.mm
+++ b/platform/ios/test/MGLGeoJSONSourceTests.mm
@@ -20,7 +20,7 @@
MGLGeoJSONMaximumZoomLevelOption: @99,
MGLGeoJSONBufferOption: @1976,
MGLGeoJSONToleranceOption: @0.42};
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"source-id" URL:url options:options];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" URL:url options:options];
auto mbglOptions = [source geoJSONOptions];
XCTAssertTrue(mbglOptions.cluster);
@@ -32,7 +32,7 @@
// when the supplied option cluster value is not of the correct type
options = @{MGLGeoJSONClusterOption: @"number 1"};
- source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"source-id" URL:url options:options];
+ source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" URL:url options:options];
XCTAssertThrows([source geoJSONOptions]);
}
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index 42398ff0a6..9c3abc1a1e 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -504,10 +504,10 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"];
NSURL *geoJSONURL = [NSURL fileURLWithPath:filePath];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"ams" URL:geoJSONURL];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"ams" URL:geoJSONURL options:nil];
[self.mapView.style addSource:source];
- MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"test" source:source];
+ MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"test" source:source];
fillLayer.fillColor = [NSColor greenColor];
fillLayer.predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"type", @"park"];
[self.mapView.style addLayer:fillLayer];
diff --git a/platform/macos/jazzy.yml b/platform/macos/jazzy.yml
index 406154ec5e..6909e14385 100644
--- a/platform/macos/jazzy.yml
+++ b/platform/macos/jazzy.yml
@@ -47,14 +47,15 @@ custom_categories:
- MGLShapeCollectionFeature
- name: Style Layers
children:
- - MGLStyleLayer
- - MGLBaseStyleLayer
- MGLBackgroundStyleLayer
- MGLCircleStyleLayer
- MGLFillStyleLayer
+ - MGLForegroundStyleLayer
- MGLLineStyleLayer
- MGLRasterStyleLayer
+ - MGLStyleLayer
- MGLSymbolStyleLayer
+ - MGLVectorStyleLayer
- name: Data Sources
children:
- MGLSource