266 lines
9.9 KiB
Plaintext
266 lines
9.9 KiB
Plaintext
<%
|
|
const type = locals.type;
|
|
const layoutProperties = locals.layoutProperties;
|
|
const paintProperties = locals.paintProperties;
|
|
const enumProperties = locals.enumProperties;
|
|
-%>
|
|
// This file is generated.
|
|
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
|
|
|
|
#import "MGLSource.h"
|
|
#import "NSPredicate+MGLPrivateAdditions.h"
|
|
#import "NSDate+MGLAdditions.h"
|
|
#import "MGLStyleLayer_Private.h"
|
|
#import "MGLStyleValue_Private.h"
|
|
#import "MGL<%- camelize(type) %>StyleLayer.h"
|
|
#import "MGLLoggingConfiguration_Private.h"
|
|
#import "MGL<%- camelize(type) %>StyleLayer_Private.h"
|
|
|
|
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer.hpp>
|
|
#include <mbgl/style/transition_options.hpp>
|
|
|
|
<% if (enumProperties) { -%>
|
|
|
|
namespace mbgl {
|
|
|
|
<% if (layoutProperties.length) { -%>
|
|
<% for (const property of layoutProperties) { -%>
|
|
<% if (definesEnum(property, layoutProperties)) { -%>
|
|
MBGL_DEFINE_ENUM(MGL<%- camelize(enumName(property)) %>, {
|
|
<% for (const value in property.values) { -%>
|
|
{ MGL<%- camelize(enumName(property)) %><%- camelize(value) %>, "<%-value%>" },
|
|
<% } -%>
|
|
});
|
|
|
|
<% } -%>
|
|
<% } -%>
|
|
<% } -%>
|
|
<% if (paintProperties.length) { -%>
|
|
<% for (const property of paintProperties) { -%>
|
|
<% if (definesEnum(property, paintProperties)) { -%>
|
|
MBGL_DEFINE_ENUM(MGL<%- camelize(enumName(property)) %>, {
|
|
<% for (const value in property.values) { -%>
|
|
{ MGL<%- camelize(enumName(property)) %><%- camelize(value) %>, "<%-value%>" },
|
|
<% } -%>
|
|
});
|
|
|
|
<% } -%>
|
|
<% } -%>
|
|
<% } -%>
|
|
}
|
|
<% } -%>
|
|
|
|
@interface MGL<%- camelize(type) %>StyleLayer ()
|
|
|
|
@property (nonatomic, readonly) mbgl::style::<%- camelize(type) %>Layer *rawLayer;
|
|
|
|
@end
|
|
|
|
@implementation MGL<%- camelize(type) %>StyleLayer
|
|
|
|
<% if (type == 'background') { -%>
|
|
- (instancetype)initWithIdentifier:(NSString *)identifier
|
|
{
|
|
MGLLogDebug(@"Initializing %@ with identifier: %@", NSStringFromClass([self class]), identifier);
|
|
auto layer = std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(identifier.UTF8String);
|
|
return self = [super initWithPendingLayer:std::move(layer)];
|
|
}
|
|
|
|
<% } else { -%>
|
|
- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source
|
|
{
|
|
MGLLogDebug(@"Initializing %@ with identifier: %@ source: %@", NSStringFromClass([self class]), identifier, source);
|
|
auto layer = std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(identifier.UTF8String, source.identifier.UTF8String);
|
|
return self = [super initWithPendingLayer:std::move(layer)];
|
|
}
|
|
|
|
<% } -%>
|
|
- (mbgl::style::<%- camelize(type) %>Layer *)rawLayer
|
|
{
|
|
return (mbgl::style::<%- camelize(type) %>Layer *)super.rawLayer;
|
|
}
|
|
|
|
<% if (type !== 'background') { -%>
|
|
- (NSString *)sourceIdentifier
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
return @(self.rawLayer->getSourceID().c_str());
|
|
}
|
|
|
|
<% if (type !== 'raster' && type !== 'hillshade') { -%>
|
|
- (NSString *)sourceLayerIdentifier
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
auto layerID = self.rawLayer->getSourceLayer();
|
|
return layerID.empty() ? nil : @(layerID.c_str());
|
|
}
|
|
|
|
- (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
MGLLogDebug(@"Setting sourceLayerIdentifier: %@", sourceLayerIdentifier);
|
|
|
|
self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: "");
|
|
}
|
|
|
|
- (void)setPredicate:(NSPredicate *)predicate
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
MGLLogDebug(@"Setting predicate: %@", predicate);
|
|
|
|
self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter());
|
|
}
|
|
|
|
- (NSPredicate *)predicate
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()];
|
|
}
|
|
|
|
<% }} -%>
|
|
<% if (layoutProperties.length) { -%>
|
|
#pragma mark - Accessing the Layout Attributes
|
|
|
|
<% for (const property of layoutProperties) { -%>
|
|
- (void)set<%- camelize(property.name) %>:(NSExpression *)<%- objCName(property) %> {
|
|
MGLAssertStyleLayerIsValid();
|
|
MGLLogDebug(@"Setting <%- objCName(property) %>: %@", <%- objCName(property) %>);
|
|
|
|
<% if (property.tokens) { -%>
|
|
if (<%- objCName(property) %> && <%- objCName(property) %>.expressionType == NSConstantValueExpressionType) {
|
|
std::string string = ((NSString *)<%- objCName(property) %>.constantValue).UTF8String;
|
|
if (mbgl::style::conversion::hasTokens(string)) {
|
|
<% if (property.type === 'formatted') { -%>
|
|
self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbgl::style::PropertyValue<mbgl::style::expression::Formatted>(
|
|
mbgl::style::conversion::convertTokenStringToFormatExpression(string)));
|
|
<% } else if (property.type === 'resolvedImage') { -%>
|
|
self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbgl::style::PropertyValue<mbgl::style::expression::Image>(
|
|
mbgl::style::conversion::convertTokenStringToImageExpression(string)));
|
|
<% } else { -%>
|
|
self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbgl::style::PropertyValue<std::string>(
|
|
mbgl::style::conversion::convertTokenStringToExpression(string)));
|
|
<% } -%>
|
|
return;
|
|
}
|
|
}
|
|
<% } -%>
|
|
<% if (isDataDriven(property)) { -%>
|
|
auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>, true);
|
|
<% } else { -%>
|
|
auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>, false);
|
|
<% } -%>
|
|
self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue);
|
|
}
|
|
|
|
- (NSExpression *)<%- objCGetter(property) %> {
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
auto propertyValue = self.rawLayer->get<%- camelize(originalPropertyName(property)) %>();
|
|
if (propertyValue.isUndefined()) {
|
|
propertyValue = self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>();
|
|
}
|
|
return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toExpression(propertyValue);
|
|
}
|
|
|
|
<% if (property.original) { -%>
|
|
- (void)set<%- camelize(originalPropertyName(property)) %>:(NSExpression *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> {
|
|
}
|
|
|
|
- (NSExpression *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> {
|
|
return self.<%- objCGetter(property) %>;
|
|
}
|
|
|
|
<% } -%>
|
|
<% } -%>
|
|
<% } -%>
|
|
<% if (paintProperties.length) { -%>
|
|
#pragma mark - Accessing the Paint Attributes
|
|
<% for (const property of paintProperties) { -%>
|
|
|
|
- (void)set<%- camelize(property.name) %>:(NSExpression *)<%- objCName(property) %> {
|
|
MGLAssertStyleLayerIsValid();
|
|
MGLLogDebug(@"Setting <%- objCName(property) %>: %@", <%- objCName(property) %>);
|
|
|
|
<% switch (property['property-type']) {
|
|
case 'color-ramp': -%>
|
|
auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::ColorRampPropertyValue>(<%- objCName(property) %>);
|
|
<% break
|
|
case 'data-driven':
|
|
case 'cross-faded-data-driven': -%>
|
|
auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>, true);
|
|
<% break
|
|
default: -%>
|
|
auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>, false);
|
|
<% } -%>
|
|
self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue);
|
|
}
|
|
|
|
- (NSExpression *)<%- objCGetter(property) %> {
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
auto propertyValue = self.rawLayer->get<%- camelize(originalPropertyName(property)) %>();
|
|
if (propertyValue.isUndefined()) {
|
|
propertyValue = self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>();
|
|
}
|
|
return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toExpression(propertyValue);
|
|
}
|
|
<% if (property["transition"]) { -%>
|
|
|
|
- (void)set<%- camelize(property.name) %>Transition:(MGLTransition )transition {
|
|
MGLAssertStyleLayerIsValid();
|
|
MGLLogDebug(@"Setting <%- objCName(property) %>Transition: %@", MGLStringFromMGLTransition(transition));
|
|
|
|
self.rawLayer->set<%- camelize(originalPropertyName(property)) %>Transition(MGLOptionsFromTransition(transition));
|
|
}
|
|
|
|
- (MGLTransition)<%- objCGetter(property) %>Transition {
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
mbgl::style::TransitionOptions transitionOptions = self.rawLayer->get<%- camelize(originalPropertyName(property)) %>Transition();
|
|
|
|
return MGLTransitionFromOptions(transitionOptions);
|
|
}
|
|
<% } -%>
|
|
<% if (property.original) { -%>
|
|
|
|
- (void)set<%- camelize(originalPropertyName(property)) %>:(NSExpression *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> {
|
|
}
|
|
|
|
- (NSExpression *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> {
|
|
return self.<%- objCGetter(property) %>;
|
|
}
|
|
<% } -%>
|
|
<% } -%>
|
|
<% } -%>
|
|
|
|
@end
|
|
<% if (enumProperties) { -%>
|
|
|
|
@implementation NSValue (MGL<%- camelize(type) %>StyleLayerAdditions)
|
|
|
|
<% for (let property of enumProperties) { -%>
|
|
+ (NSValue *)valueWithMGL<%- camelize(enumName(property)) %>:(MGL<%- camelize(enumName(property)) %>)<%- objCName(property) %> {
|
|
return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(enumName(property)) %>)];
|
|
}
|
|
|
|
- (MGL<%- camelize(enumName(property)) %>)MGL<%- camelize(enumName(property)) %>Value {
|
|
MGL<%- camelize(enumName(property)) %> <%- objCName(property) %>;
|
|
[self getValue:&<%- objCName(property) %>];
|
|
return <%- objCName(property) %>;
|
|
}
|
|
|
|
<% } -%>
|
|
@end
|
|
<% } -%>
|
|
|
|
namespace mbgl {
|
|
|
|
MGLStyleLayer* <%- camelize(type) %>StyleLayerPeerFactory::createPeer(style::Layer* rawLayer) {
|
|
return [[MGL<%- camelize(type) %>StyleLayer alloc] initWithRawLayer:rawLayer];
|
|
}
|
|
|
|
} // namespace mbgl
|