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

[ios, macos] Put MGLStyleLayer inits in respective classes #6269

Merged
merged 1 commit into from
Sep 8, 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
16 changes: 14 additions & 2 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,26 @@ global.propertyType = function (property, _private) {
return _private ? `id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>` : `id <MGLStyleAttributeValue>`;
};

global.initLayerIdentifierOnly = function (layerType) {
return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String);`
}

global.initLayer = function (layerType) {
if (layerType == "background") {
return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String);`
return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String);`
Copy link
Contributor

@frederoni frederoni Sep 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're leaking this layer and all other mbgl::style::layers. Should we delete the ref in -dealloc or rewrite the getters and setters to make them access the layer in a lazy way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to take a step back and address this leak in #6254. Until then, any patches will only add to the confusion.

} else {
return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String);`
return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);`
}
}

global.initLayerWithSourceLayer = function(layerType) {
return `_layer = new mbgl::style::${camelize(layerType)}Layer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);`
}

global.setSourceLayer = function() {
return `_layer->setSourceLayer(sourceLayer.UTF8String);`
}

global.setterImplementation = function(property, layerType) {
let implementation = '';
switch (property.type) {
Expand Down
5 changes: 5 additions & 0 deletions platform/darwin/src/MGLBackgroundStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ NS_ASSUME_NONNULL_BEGIN

@interface MGLBackgroundStyleLayer : MGLBaseStyleLayer <MGLStyleLayer>

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier;

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source;


#pragma mark - Accessing the Paint Attributes

#if TARGET_OS_IPHONE
Expand Down
17 changes: 15 additions & 2 deletions platform/darwin/src/MGLBackgroundStyleLayer.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLSource.h"
#import "NSPredicate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleAttributeValue.h"
Expand All @@ -13,22 +14,34 @@ @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 sourceIdentifier:(NSString *)sourceIdentifier {
- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = sourceIdentifier;
_layer = new mbgl::style::BackgroundLayer(layerIdentifier.UTF8String);
}
return self;
}

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = source.sourceIdentifier;
_layer = new mbgl::style::BackgroundLayer(layerIdentifier.UTF8String);
}
return self;
}


#pragma mark - Accessing the Paint Attributes

- (void)setBackgroundColor:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)backgroundColor {
Expand Down
26 changes: 26 additions & 0 deletions platform/darwin/src/MGLBaseStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ @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;
}

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier sourceLayer:(NSString *)sourceLayer
{
[[NSException exceptionWithName:@"MGLAbstractClassException"
reason:@"MGLBaseStyleLayer is an abstract class"
userInfo:nil] raise];
return nil;
}

- (void)setVisible:(BOOL)visible
{
Expand Down
5 changes: 5 additions & 0 deletions platform/darwin/src/MGLCircleStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ typedef NS_ENUM(NSUInteger, MGLCircleStyleLayerCirclePitchScale) {

@interface MGLCircleStyleLayer : MGLBaseStyleLayer <MGLStyleLayer>


- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source;

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer;

/**
A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>.

Expand Down
21 changes: 18 additions & 3 deletions platform/darwin/src/MGLCircleStyleLayer.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLSource.h"
#import "NSPredicate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleAttributeValue.h"
Expand All @@ -13,18 +14,32 @@ @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 sourceIdentifier:(NSString *)sourceIdentifier {

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = source.sourceIdentifier;
_layer = new mbgl::style::CircleLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
}
return self;
}

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = sourceIdentifier;
_layer = new mbgl::style::CircleLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String);
_sourceIdentifier = source.sourceIdentifier;
_layer = new mbgl::style::CircleLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
_layer->setSourceLayer(sourceLayer.UTF8String);
}
return self;
}
Expand Down
5 changes: 5 additions & 0 deletions platform/darwin/src/MGLFillStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ typedef NS_ENUM(NSUInteger, MGLFillStyleLayerFillTranslateAnchor) {

@interface MGLFillStyleLayer : MGLBaseStyleLayer <MGLStyleLayer>


- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source;

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer;

/**
A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>.

Expand Down
21 changes: 18 additions & 3 deletions platform/darwin/src/MGLFillStyleLayer.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLSource.h"
#import "NSPredicate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleAttributeValue.h"
Expand All @@ -13,18 +14,32 @@ @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 sourceIdentifier:(NSString *)sourceIdentifier {

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = source.sourceIdentifier;
_layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
}
return self;
}

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = sourceIdentifier;
_layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String);
_sourceIdentifier = source.sourceIdentifier;
_layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
_layer->setSourceLayer(sourceLayer.UTF8String);
}
return self;
}
Expand Down
5 changes: 5 additions & 0 deletions platform/darwin/src/MGLLineStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ typedef NS_ENUM(NSUInteger, MGLLineStyleLayerLineTranslateAnchor) {

@interface MGLLineStyleLayer : MGLBaseStyleLayer <MGLStyleLayer>


- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source;

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer;

/**
A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>.

Expand Down
21 changes: 18 additions & 3 deletions platform/darwin/src/MGLLineStyleLayer.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLSource.h"
#import "NSPredicate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleAttributeValue.h"
Expand All @@ -13,18 +14,32 @@ @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 sourceIdentifier:(NSString *)sourceIdentifier {

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = source.sourceIdentifier;
_layer = new mbgl::style::LineLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
}
return self;
}

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = sourceIdentifier;
_layer = new mbgl::style::LineLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String);
_sourceIdentifier = source.sourceIdentifier;
_layer = new mbgl::style::LineLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
_layer->setSourceLayer(sourceLayer.UTF8String);
}
return self;
}
Expand Down
4 changes: 4 additions & 0 deletions platform/darwin/src/MGLRasterStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ NS_ASSUME_NONNULL_BEGIN

@interface MGLRasterStyleLayer : MGLBaseStyleLayer <MGLStyleLayer>


- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source;


#pragma mark - Accessing the Paint Attributes

/**
Expand Down
11 changes: 8 additions & 3 deletions platform/darwin/src/MGLRasterStyleLayer.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLSource.h"
#import "NSPredicate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleAttributeValue.h"
Expand All @@ -13,22 +14,26 @@ @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 sourceIdentifier:(NSString *)sourceIdentifier {

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source
{
if (self = [super init]) {
_layerIdentifier = layerIdentifier;
_sourceIdentifier = sourceIdentifier;
_layer = new mbgl::style::RasterLayer(layerIdentifier.UTF8String, sourceIdentifier.UTF8String);
_sourceIdentifier = source.sourceIdentifier;
_layer = new mbgl::style::RasterLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
}
return self;
}


#pragma mark - Accessing the Paint Attributes

- (void)setRasterOpacity:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)rasterOpacity {
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLRuntimeStylingTests.m.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"];
NSURL *url = [NSURL fileURLWithPath:filePath];
MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url];
MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithLayerIdentifier:@"layerID" sourceIdentifier:@"sourceID"];
MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source];
[self.mapView.style addSource:source];
[self.mapView.style addLayer:layer];

Expand Down
7 changes: 1 addition & 6 deletions platform/darwin/src/MGLStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@

@property (nonatomic, weak) MGLMapView *mapView;
@property (nonatomic, copy, readonly) NSString *layerIdentifier;

@optional

@property (nonatomic, readonly) NSString *sourceIdentifier;

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier;
- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier sourceIdentifier:(NSString *)sourceIdentifier;
@property (nonatomic, readonly) NSString *sourceLayerIdentifier;

@end
10 changes: 10 additions & 0 deletions platform/darwin/src/MGLStyleLayer.h.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(type) %>StyleLayer<%- camelize(prope
<% } -%>
@interface MGL<%- camelize(type) %>StyleLayer : MGLBaseStyleLayer <MGLStyleLayer>

<% if (type == 'background') { -%>
- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier;
<% } -%>

- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source;

<% if (type !== 'background' && type !== 'raster') { -%>
- (instancetype)initWithLayerIdentifier:(NSString *)layerIdentifier source:(MGLSource *)source sourceLayer:(NSString *)sourceLayer;
<% } -%>

<% if (type !== 'background' && type !== 'raster') { -%>
/**
A predicate that corresponds to the layer's <a href='https://www.mapbox.com/mapbox-gl-style-spec/#types-filter'>filter</a>.
Expand Down
Loading