This updates the code generation for style layers to add a test to check that the style object returned from mbgl can be safely cast into the expected type so ownership can be returned to the caller when removing layers. This scenario was previously possible if a layer of type T was added before a layer of type U but both layers shared the same identifier. In that case, if the pointer to the second layer of type U was used to remove a layer, a runtime exception would occur since mbgl returns the layer with type T (the first one added). Now, an exception will still occur if layers with the same identifier are manipulated as described above but it is done as part of a validation check for all public style layer methods at the Darwin platform level. The NSException attempts to warn developers about using and reusing style identifiers to avoid this issue in the first place.
70 lines
1.4 KiB
Plaintext
70 lines
1.4 KiB
Plaintext
#import "MGLStyleLayer_Private.h"
|
|
#import "MGLMapView_Private.h"
|
|
|
|
#include <mbgl/style/layer.hpp>
|
|
|
|
@implementation MGLStyleLayer
|
|
|
|
- (instancetype)initWithIdentifier:(NSString *)identifier
|
|
{
|
|
if (self = [super init]) {
|
|
_identifier = identifier;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)setVisible:(BOOL)visible
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
mbgl::style::VisibilityType v = visible
|
|
? mbgl::style::VisibilityType::Visible
|
|
: mbgl::style::VisibilityType::None;
|
|
self.rawLayer->setVisibility(v);
|
|
}
|
|
|
|
- (BOOL)isVisible
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
mbgl::style::VisibilityType v = self.rawLayer->getVisibility();
|
|
return (v == mbgl::style::VisibilityType::Visible);
|
|
}
|
|
|
|
- (void)setMaximumZoomLevel:(float)maximumZoomLevel
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
self.rawLayer->setMaxZoom(maximumZoomLevel);
|
|
}
|
|
|
|
- (float)maximumZoomLevel
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
return self.rawLayer->getMaxZoom();
|
|
}
|
|
|
|
- (void)setMinimumZoomLevel:(float)minimumZoomLevel
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
self.rawLayer->setMinZoom(minimumZoomLevel);
|
|
}
|
|
|
|
- (float)minimumZoomLevel
|
|
{
|
|
MGLAssertStyleLayerIsValid();
|
|
|
|
return self.rawLayer->getMinZoom();
|
|
}
|
|
|
|
- (NSString *)description
|
|
{
|
|
return [NSString stringWithFormat:@"<%@: %p; identifier = %@; visible = %@>",
|
|
NSStringFromClass([self class]), (void *)self, self.identifier,
|
|
self.visible ? @"YES" : @"NO"];
|
|
}
|
|
|
|
@end
|