Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Revamp MGLStyleLayer, MGLSource inheritance #6588

Merged
merged 4 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);`
}
Expand Down
9 changes: 3 additions & 6 deletions platform/darwin/src/MGLBackgroundStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLStyleAttributeValue.h"
#import "MGLBaseStyleLayer.h"
#import "MGLStyleLayer.h"

NS_ASSUME_NONNULL_BEGIN

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

Expand Down
23 changes: 3 additions & 20 deletions platform/darwin/src/MGLBackgroundStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 0 additions & 35 deletions platform/darwin/src/MGLBaseStyleLayer.h

This file was deleted.

77 changes: 0 additions & 77 deletions platform/darwin/src/MGLBaseStyleLayer.mm

This file was deleted.

16 changes: 2 additions & 14 deletions platform/darwin/src/MGLCircleStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLStyleAttributeValue.h"
#import "MGLBaseStyleLayer.h"
#import "MGLVectorStyleLayer.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -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

Expand Down
30 changes: 11 additions & 19 deletions platform/darwin/src/MGLCircleStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 2 additions & 14 deletions platform/darwin/src/MGLFillStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLStyleAttributeValue.h"
#import "MGLBaseStyleLayer.h"
#import "MGLVectorStyleLayer.h"

NS_ASSUME_NONNULL_BEGIN

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

Expand Down
30 changes: 11 additions & 19 deletions platform/darwin/src/MGLFillStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading