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.
116 lines
4.2 KiB
Plaintext
116 lines
4.2 KiB
Plaintext
// 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"
|
|
#import "MGLFillStyleLayer.h"
|
|
|
|
#include <mbgl/style/layers/fill_layer.hpp>
|
|
|
|
@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
|
|
{
|
|
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 = source.sourceIdentifier;
|
|
_layer = new mbgl::style::FillLayer(layerIdentifier.UTF8String, source.sourceIdentifier.UTF8String);
|
|
_layer->setSourceLayer(sourceLayer.UTF8String);
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)setPredicate:(NSPredicate *)predicate
|
|
{
|
|
self.layer->setFilter(predicate.mgl_filter);
|
|
}
|
|
|
|
- (NSPredicate *)predicate
|
|
{
|
|
return [NSPredicate mgl_predicateWithFilter:self.layer->getFilter()];
|
|
}
|
|
|
|
#pragma mark - Accessing the Paint Attributes
|
|
|
|
- (void)setFillAntialias:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)fillAntialias {
|
|
self.layer->setFillAntialias(fillAntialias.mbgl_boolPropertyValue);
|
|
}
|
|
|
|
- (id <MGLStyleAttributeValue>)fillAntialias {
|
|
return [MGLStyleAttribute mbgl_boolWithPropertyValueBool:self.layer->getFillAntialias() ?: self.layer->getDefaultFillAntialias()];
|
|
}
|
|
|
|
- (void)setFillOpacity:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)fillOpacity {
|
|
self.layer->setFillOpacity(fillOpacity.mbgl_floatPropertyValue);
|
|
}
|
|
|
|
- (id <MGLStyleAttributeValue>)fillOpacity {
|
|
return [MGLStyleAttribute mbgl_numberWithPropertyValueNumber:self.layer->getFillOpacity() ?: self.layer->getDefaultFillOpacity()];
|
|
}
|
|
|
|
- (void)setFillColor:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)fillColor {
|
|
self.layer->setFillColor(fillColor.mbgl_colorPropertyValue);
|
|
}
|
|
|
|
- (id <MGLStyleAttributeValue>)fillColor {
|
|
return [MGLStyleAttribute mbgl_colorWithPropertyValueColor:self.layer->getFillColor() ?: self.layer->getDefaultFillColor()];
|
|
}
|
|
|
|
- (void)setFillOutlineColor:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)fillOutlineColor {
|
|
self.layer->setFillOutlineColor(fillOutlineColor.mbgl_colorPropertyValue);
|
|
}
|
|
|
|
- (id <MGLStyleAttributeValue>)fillOutlineColor {
|
|
return [MGLStyleAttribute mbgl_colorWithPropertyValueColor:self.layer->getFillOutlineColor() ?: self.layer->getDefaultFillOutlineColor()];
|
|
}
|
|
|
|
- (void)setFillTranslate:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)fillTranslate {
|
|
self.layer->setFillTranslate(fillTranslate.mbgl_offsetPropertyValue);
|
|
}
|
|
|
|
- (id <MGLStyleAttributeValue>)fillTranslate {
|
|
return [MGLStyleAttribute mbgl_offsetWithPropertyValueOffset:self.layer->getFillTranslate() ?: self.layer->getDefaultFillTranslate()];
|
|
}
|
|
|
|
- (void)setFillTranslateAnchor:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)fillTranslateAnchor {
|
|
MGLSetEnumProperty(fillTranslateAnchor, FillTranslateAnchor, TranslateAnchorType, MGLFillStyleLayerFillTranslateAnchor);
|
|
}
|
|
|
|
- (id <MGLStyleAttributeValue>)fillTranslateAnchor {
|
|
MGLGetEnumProperty(FillTranslateAnchor, TranslateAnchorType, MGLFillStyleLayerFillTranslateAnchor);
|
|
}
|
|
|
|
- (void)setFillPattern:(id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>)fillPattern {
|
|
self.layer->setFillPattern(fillPattern.mbgl_stringPropertyValue);
|
|
}
|
|
|
|
- (id <MGLStyleAttributeValue>)fillPattern {
|
|
return [MGLStyleAttribute mbgl_stringWithPropertyValueString:self.layer->getFillPattern() ?: self.layer->getDefaultFillPattern()];
|
|
}
|
|
|
|
@end
|