[ios, macos] Revamped MGLStyleLayer, MGLSource inheritance

Removed the MGLStyleLayer protocol, because almost none of its members was actually implemented in every class that adopted the protocol. Removed the unused mapView backpointer property with no replacement. Renamed MGLBaseStyleLayer to MGLStyleLayer. Created the intermediate abstract classes MGLForegroundStyleLayer and MGLVectorStyleLayer to cover subsets of style layer classes with like functionality.

Moved each MGLBaseStyleLayer initializer and the corresponding properties down to an abstract subclass such that the initializer makes sense for all concrete subclasses. Moved more initializers and the predicate property up to MGLVectorStyleLayer to eliminate duplication among the concrete subclasses. Marked these initializers as designated initializers.

Removed “source” or “layer” before identifier wherever the type of identifier is apparent. Removed extra MGLGeoJSONSource initializer variants in favor of nullable parameters.

Added copious documentation comments for source and style layer classes, including several previously undocumented methods and properties. In particular, some preconditions and postconditions have been documented. Added pragma marks to break up the jazzy documentation pages into sections. Reformatted exceptions for consistency.
This commit is contained in:
Minh Nguyễn
2016-10-05 00:34:01 -07:00
committed by Minh Nguyễn
parent 21d7ee11e1
commit 50d2c01d7d
43 changed files with 542 additions and 527 deletions

View File

@@ -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);`
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 MGLBaseStyleLayer : NSObject
@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.
*/
@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.

View File

@@ -5,39 +5,14 @@
#include <mbgl/style/layer.hpp>
@interface MGLBaseStyleLayer() <MGLStyleLayer_Private>
@end
@implementation MGLStyleLayer
@implementation MGLBaseStyleLayer
@synthesize layerIdentifier;
@synthesize mapView;
@synthesize layer;
@synthesize sourceIdentifier;
@synthesize sourceLayerIdentifier;
- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier
- (instancetype)initWithIdentifier:(NSString *)identifier
{
[[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;
if (self = [super init]) {
_identifier = identifier;
}
return self;
}
- (void)setVisible:(BOOL)visible

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -50,7 +50,6 @@ extern NSString * const MGLGeoJSONBufferOption;
*/
extern NSString * const MGLGeoJSONToleranceOption;
/**
A GeoJSON source.
@@ -59,12 +58,43 @@ extern NSString * const MGLGeoJSONToleranceOption;
*/
@interface MGLGeoJSONSource : MGLSource
#pragma mark Initializing a 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>.
@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.
*/
- (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *)data options:(nullable NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER;
/**
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>.
@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.
*/
- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(nullable NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER;
#pragma mark Accessing a Source’s Content
/**
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]`.
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]`.
*/
@property (nonatomic, readonly, nullable) NS_ARRAY_OF(id <MGLFeature>) *features;
@@ -75,62 +105,20 @@ extern NSString * const MGLGeoJSONToleranceOption;
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]`.
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]`.
*/
@property (nonatomic, readonly, nullable, copy) NSData *geoJSONData;
/**
The URL to the GeoJSON document that specifies the contents of the source.
If the receiver was initialized using `-initWithSourceIdentifier:geoJSONData:`,
this property is set to `nil`.
If the receiver was initialized using `-initWithIdentifier:geoJSONData:`, this
property is set to `nil`.
*/
@property (nonatomic, readonly, nullable) NSURL *URL;
/**
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;
/**
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>.
@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.
*/
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier geoJSONData:(NSData *)data options:(NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER;
/**
Initializes a source with the given identifier and URL.
@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.
*/
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url NS_DESIGNATED_INITIALIZER;
/**
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>.
@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.
*/
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_END

View File

@@ -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
- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options
{
if (self = [super initWithSourceIdentifier:sourceIdentifier])
{
_URL = url;
}
return self;
}
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier 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;

View File

@@ -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

View File

@@ -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

View File

@@ -15,9 +15,49 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface MGLRasterSource : MGLSource
#pragma mark Initializing a Source
/**
A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and
`mapbox://<mapid>`.
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 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

View File

@@ -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));

View File

@@ -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

View File

@@ -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 {

View File

@@ -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) %>
<% } -%>

View File

@@ -10,16 +10,25 @@
*/
@interface MGLSource : NSObject
/**
A string that uniquely identifies the source.
*/
@property (nonatomic, copy) NSString *sourceIdentifier;
#pragma mark Initializing a Source
/**
Initializes a source with the given identifier.
@param sourceIdentifier 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.
*/
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier;
- (instancetype)initWithIdentifier:(NSString *)identifier;
#pragma mark Identifying a Source
/**
A string that uniquely identifies the source in the style to which it is added.
*/
@property (nonatomic, copy) NSString *identifier;
@end

View File

@@ -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;
}

View File

@@ -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.

View File

@@ -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;
self.mapView.mbglMap->removeLayer(layer.identifier.UTF8String);
}
- (void)addLayer:(MGLStyleLayer *)layer
{
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:@"Source type not handled" format:@""];
return Nil;
self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer));
}
- (Class)classFromLayer:(mbgl::style::Layer *)layer
- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer
{
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(layer)];
}
[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));
}
- (void)insertLayer:(id <MGLStyleLayer, MGLStyleLayer_Private>)styleLayer
belowLayer:(id <MGLStyleLayer, MGLStyleLayer_Private>)belowLayer
{
const mbgl::optional<std::string> belowLayerId{[belowLayer layerIdentifier].UTF8String};
self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(styleLayer.layer), belowLayerId);
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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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) %>
}
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() %>
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') { -%>
- (NSString *)sourceLayerIdentifier
{
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
{
self.layer->setFilter(predicate.mgl_filter);

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -13,28 +13,57 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface MGLVectorSource : MGLSource
#pragma mark Initializing a Source
/**
Returns a vector source initialized with an identifier and TileJSON URL.
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.
@return An initialized vector source.
*/
- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url NS_DESIGNATED_INITIALIZER;
/**
Returns a vector source initialized an identifier 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.
@return An initialized vector source.
*/
- (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;
/**
Initializes and returns a vector source from a remote URL.
@param sourceIdentifier The source identifier.
@param URL A remote URL holding the vector source data.
@return An `MGLVectorSource`.
*/
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url;
/**
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.
*/
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSet:(MGLTileSet *)tileSet;
@end
NS_ASSUME_NONNULL_END

View File

@@ -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);
}

View File

@@ -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]);

View File

@@ -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]);

View File

@@ -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]);

View File

@@ -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

View File

@@ -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]);

View File

@@ -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]);

View File

@@ -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]);

View File

@@ -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];
}

View File

@@ -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

View File

@@ -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]);
}

View File

@@ -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];

View File

@@ -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