[ios, macos] Raise correct style layer misuse exception (#6738)

Implement the layer property on MGLStyleLayer itself, where it’s declared, so that the check for an abstract style layer doesn’t itself raise an exception. The concrete style layer classes still declare their own layers as covariant properties, although those properties aren’t actually used anywhere.
This commit is contained in:
Minh Nguyễn
2016-10-18 15:03:10 -07:00
committed by GitHub
parent e5762ab728
commit ce243043f5
2 changed files with 10 additions and 4 deletions

View File

@@ -176,7 +176,7 @@ static NSURL *MGLStyleURL_emerald;
[NSException raise:NSInvalidArgumentException format:
@"The style layer %@ cannot be added to the style. "
@"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
NSStringFromClass(self)];
layer];
}
self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(layer.layer));
@@ -189,14 +189,14 @@ static NSURL *MGLStyleURL_emerald;
format:
@"The style layer %@ cannot be added to the style. "
@"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
NSStringFromClass(layer)];
layer];
}
if (!otherLayer.layer) {
[NSException raise:NSInvalidArgumentException
format:
@"A style layer cannot be placed before %@ in the style. "
@"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
NSStringFromClass(otherLayer)];
@"Make sure otherLayer was obtained using -[MGLStyle layerWithIdentifier:].",
otherLayer];
}
const mbgl::optional<std::string> belowLayerId{otherLayer.identifier.UTF8String};

View File

@@ -3,6 +3,12 @@
#include <mbgl/style/layer.hpp>
@interface MGLStyleLayer ()
@property (nonatomic) mbgl::style::Layer *layer;
@end
@implementation MGLStyleLayer
- (instancetype)initWithIdentifier:(NSString *)identifier