Files
MapLibreParticleLab/platform/darwin/src/MGLStyleLayer.h.ejs
Jesse Bounds 4c8d61abf1 [ios, macos] Put MGLStyleLayer inits in respective classes
Previously, we declared MGLStyleLayer initializers in the MGLStyleLayer
protocol as optional methods. This made it easy to opt in and out
of initializers that did or or did not make sense for the subclass.
However, this approach was dangerous since it was easy for an
application developer to initialize an MGLStyleLayer subclass with an
init method that was actually not implemented in that class causing
an exception at runtime.

This commit moves the init methods that each subclass supports to
each subclass so xcode (and the compiler) help the developer avoid
the previously possible runtime exception.

In addition, a new init method is added that takes the source layer
and passes that on to `mbgl::style:Layer` (but only on classes
where this is possible in core). This allows an application developer
to style a specific source layer (i.e. the contour lines of the mapbox
terrain vector source).

Finally, this refactors MGLStyleLayer classes to use an MGLSource instead of a
string identifier for the source when initializing the style.
2016-09-08 09:17:35 -07:00

97 lines
3.4 KiB
Plaintext

<%
const type = locals.type;
const layoutProperties = locals.layoutProperties;
const paintProperties = locals.paintProperties;
const layoutPropertiesByName = locals.layoutPropertiesByName;
const paintPropertiesByName = locals.paintPropertiesByName;
-%>
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.
#import "MGLStyleAttributeValue.h"
#import "MGLBaseStyleLayer.h"
NS_ASSUME_NONNULL_BEGIN
<% for (const property of layoutProperties) { -%>
<% if (property.type == "enum") { -%>
typedef NS_ENUM(NSUInteger, MGL<%- camelize(type) %>StyleLayer<%- camelize(property.name) %>) {
<% for (const value of property.values) { -%>
MGL<%- camelize(type) %>StyleLayer<%- camelize(property.name) %><%- camelize(value) %>,
<% } -%>
};
<% } -%>
<% } -%>
<% for (const property of paintProperties) { -%>
<% if (property.type == "enum") { -%>
typedef NS_ENUM(NSUInteger, MGL<%- camelize(type) %>StyleLayer<%- camelize(property.name) %>) {
<% for (const value of property.values) { -%>
MGL<%- camelize(type) %>StyleLayer<%- camelize(property.name) %><%- camelize(value) %>,
<% } -%>
};
<% } -%>
<% } -%>
@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>.
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
<% for (const property of layoutProperties) { -%>
/**
<%- propertyDoc(property, type) %>
<% if ('default' in property) { -%>
The default value of this property is <%- propertyDefault(property, type) %>.<% if (!property.required) { %> Set this property to `nil` to reset it to the default value.<% } %>
<% } if (property.requires) { -%>
<%- propertyReqs(property, layoutPropertiesByName, type) %>
<% } -%>
*/
@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) <%- propertyType(property, false, type) %> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>
<% } -%>
<% if (paintProperties.length) { -%>
#pragma mark - Accessing the Paint Attributes
<% for (const property of paintProperties) { -%>
/**
<%- propertyDoc(property, type) %>
<% if ('default' in property) { -%>
The default value of this property is <%- propertyDefault(property, type) %>.<% if (!property.required) { %> Set this property to `nil` to reset it to the default value.<% } %>
<% } if (property.requires) { -%>
<%- propertyReqs(property, paintPropertiesByName, type) %>
<% } -%>
*/
@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) <%- propertyType(property, false, type) %> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>
<% } -%>
@end
NS_ASSUME_NONNULL_END