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.
54 lines
3.5 KiB
Objective-C
54 lines
3.5 KiB
Objective-C
// This file is generated.
|
|
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.
|
|
|
|
#import "MGLStyleLayerTests.h"
|
|
|
|
@interface MGLFillLayerTests : MGLStyleLayerTests
|
|
@end
|
|
|
|
@implementation MGLFillLayerTests
|
|
|
|
- (void)testFillLayer {
|
|
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"];
|
|
NSURL *url = [NSURL fileURLWithPath:filePath];
|
|
MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"sourceID" URL:url];
|
|
MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"layerID" source:source];
|
|
[self.mapView.style addSource:source];
|
|
[self.mapView.style addLayer:layer];
|
|
|
|
layer.fillAntialias = [MGLRuntimeStylingHelper testBool];
|
|
layer.fillOpacity = [MGLRuntimeStylingHelper testNumber];
|
|
layer.fillColor = [MGLRuntimeStylingHelper testColor];
|
|
layer.fillOutlineColor = [MGLRuntimeStylingHelper testColor];
|
|
layer.fillTranslate = [MGLRuntimeStylingHelper testOffset];
|
|
layer.fillTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLFillStyleLayerFillTranslateAnchorViewport type:@encode(MGLFillStyleLayerFillTranslateAnchor)];
|
|
layer.fillPattern = [MGLRuntimeStylingHelper testString];
|
|
|
|
MGLFillStyleLayer *gLayer = [self.mapView.style layerWithIdentifier:@"layerID"];
|
|
XCTAssertEqualObjects(gLayer.fillAntialias, [MGLRuntimeStylingHelper testBool]);
|
|
XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumber]);
|
|
XCTAssertEqualObjects(gLayer.fillColor, [MGLRuntimeStylingHelper testColor]);
|
|
XCTAssertEqualObjects(gLayer.fillOutlineColor, [MGLRuntimeStylingHelper testColor]);
|
|
XCTAssertEqualObjects(gLayer.fillTranslate, [MGLRuntimeStylingHelper testOffset]);
|
|
XCTAssert([(NSValue *)gLayer.fillTranslateAnchor isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLFillStyleLayerFillTranslateAnchorViewport type:@encode(MGLFillStyleLayerFillTranslateAnchor)]], @"%@ is not equal to %@", gLayer.fillTranslateAnchor, [MGLRuntimeStylingHelper testEnum:MGLFillStyleLayerFillTranslateAnchorViewport type:@encode(MGLFillStyleLayerFillTranslateAnchor)]);
|
|
XCTAssertEqualObjects(gLayer.fillPattern, [MGLRuntimeStylingHelper testString]);
|
|
|
|
layer.fillAntialias = [MGLRuntimeStylingHelper testBoolFunction];
|
|
layer.fillOpacity = [MGLRuntimeStylingHelper testNumberFunction];
|
|
layer.fillColor = [MGLRuntimeStylingHelper testColorFunction];
|
|
layer.fillOutlineColor = [MGLRuntimeStylingHelper testColorFunction];
|
|
layer.fillTranslate = [MGLRuntimeStylingHelper testOffsetFunction];
|
|
layer.fillTranslateAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLFillStyleLayerFillTranslateAnchorViewport type:@encode(MGLFillStyleLayerFillTranslateAnchor)];
|
|
layer.fillPattern = [MGLRuntimeStylingHelper testStringFunction];
|
|
|
|
XCTAssertEqualObjects(gLayer.fillAntialias, [MGLRuntimeStylingHelper testBoolFunction]);
|
|
XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumberFunction]);
|
|
XCTAssertEqualObjects(gLayer.fillColor, [MGLRuntimeStylingHelper testColorFunction]);
|
|
XCTAssertEqualObjects(gLayer.fillOutlineColor, [MGLRuntimeStylingHelper testColorFunction]);
|
|
XCTAssertEqualObjects(gLayer.fillTranslate, [MGLRuntimeStylingHelper testOffsetFunction]);
|
|
XCTAssertEqualObjects(gLayer.fillTranslateAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLFillStyleLayerFillTranslateAnchorViewport type:@encode(MGLFillStyleLayerFillTranslateAnchor)]);
|
|
XCTAssertEqualObjects(gLayer.fillPattern, [MGLRuntimeStylingHelper testStringFunction]);
|
|
}
|
|
|
|
@end
|