diff --git a/ios/RCTMGL/RCTMGLCircleLayer.m b/ios/RCTMGL/RCTMGLCircleLayer.m index 232a75878..ceb42aaa4 100644 --- a/ios/RCTMGL/RCTMGLCircleLayer.m +++ b/ios/RCTMGL/RCTMGLCircleLayer.m @@ -16,6 +16,7 @@ @implementation RCTMGLCircleLayer - (MGLCircleStyleLayer*)makeLayer:(MGLStyle*)style { MGLSource *source = [style sourceWithIdentifier:self.sourceID]; + if (source == nil) { return nil; } MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:self.id source:source]; layer.sourceLayerIdentifier = self.sourceLayerID; return layer; diff --git a/ios/RCTMGL/RCTMGLFillExtrusionLayer.m b/ios/RCTMGL/RCTMGLFillExtrusionLayer.m index 68b93bda4..78a051179 100644 --- a/ios/RCTMGL/RCTMGLFillExtrusionLayer.m +++ b/ios/RCTMGL/RCTMGLFillExtrusionLayer.m @@ -15,6 +15,7 @@ @implementation RCTMGLFillExtrusionLayer - (MGLFillExtrusionStyleLayer*)makeLayer:(MGLStyle*)style { MGLSource *source = [style sourceWithIdentifier:self.sourceID]; + if (source == nil) { return nil; } MGLFillExtrusionStyleLayer *layer = [[MGLFillExtrusionStyleLayer alloc] initWithIdentifier:self.id source:source]; layer.sourceLayerIdentifier = self.sourceLayerID; return layer; diff --git a/ios/RCTMGL/RCTMGLFillLayer.m b/ios/RCTMGL/RCTMGLFillLayer.m index 211548ec3..8ffecf7c2 100644 --- a/ios/RCTMGL/RCTMGLFillLayer.m +++ b/ios/RCTMGL/RCTMGLFillLayer.m @@ -15,6 +15,7 @@ @implementation RCTMGLFillLayer - (MGLStyleLayer*)makeLayer:(MGLStyle*)style { MGLSource *source = [style sourceWithIdentifier:self.sourceID]; + if (source == nil) { return nil; } MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:self.id source:source]; layer.sourceLayerIdentifier = self.sourceLayerID; return layer; diff --git a/ios/RCTMGL/RCTMGLHeatmapLayer.m b/ios/RCTMGL/RCTMGLHeatmapLayer.m index 936263bfc..5f7c5e6cc 100644 --- a/ios/RCTMGL/RCTMGLHeatmapLayer.m +++ b/ios/RCTMGL/RCTMGLHeatmapLayer.m @@ -12,6 +12,7 @@ @implementation RCTMGLHeatmapLayer - (MGLHeatmapStyleLayer*)makeLayer:(MGLStyle*)style { MGLSource *source = [style sourceWithIdentifier:self.sourceID]; + if (source == nil) { return nil; } MGLHeatmapStyleLayer *layer = [[MGLHeatmapStyleLayer alloc] initWithIdentifier:self.id source:source]; layer.sourceLayerIdentifier = self.sourceLayerID; return layer; diff --git a/ios/RCTMGL/RCTMGLImageSource.m b/ios/RCTMGL/RCTMGLImageSource.m index bc533b6c3..57d4db43f 100644 --- a/ios/RCTMGL/RCTMGLImageSource.m +++ b/ios/RCTMGL/RCTMGLImageSource.m @@ -21,7 +21,7 @@ - (void)setUrl:(NSString *)url } } -- (MGLSource *)makeSource +- (nullable MGLSource *)makeSource { NSURL *myURL; diff --git a/ios/RCTMGL/RCTMGLLayer.m b/ios/RCTMGL/RCTMGLLayer.m index 5ca420eef..cee7bc5fc 100644 --- a/ios/RCTMGL/RCTMGLLayer.m +++ b/ios/RCTMGL/RCTMGLLayer.m @@ -108,6 +108,10 @@ - (void)addToMap:(RCTMGLMapView*) map style:(MGLStyle *)style _styleLayer = existingLayer; } else { _styleLayer = [self makeLayer:style]; + if (_styleLayer == nil) { + RCTLogError(@"Failed to make layer: %@", _id); + return; + } [self insertLayer: map]; } @@ -122,7 +126,7 @@ - (void)removeFromMap:(MGLStyle *)style } } -- (MGLStyleLayer*)makeLayer:(MGLStyle*)style +- (nullable MGLStyleLayer*)makeLayer:(MGLStyle*)style { @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] diff --git a/ios/RCTMGL/RCTMGLLineLayer.m b/ios/RCTMGL/RCTMGLLineLayer.m index 2e1baf8f0..b463f3277 100644 --- a/ios/RCTMGL/RCTMGLLineLayer.m +++ b/ios/RCTMGL/RCTMGLLineLayer.m @@ -15,6 +15,7 @@ @implementation RCTMGLLineLayer - (MGLLineStyleLayer*)makeLayer:(MGLStyle*)style { MGLSource *source = [style sourceWithIdentifier:self.sourceID]; + if (source == nil) { return nil; } MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:self.id source:source]; layer.sourceLayerIdentifier = self.sourceLayerID; return layer; diff --git a/ios/RCTMGL/RCTMGLRasterLayer.m b/ios/RCTMGL/RCTMGLRasterLayer.m index 6064f68fb..85891035f 100644 --- a/ios/RCTMGL/RCTMGLRasterLayer.m +++ b/ios/RCTMGL/RCTMGLRasterLayer.m @@ -14,6 +14,7 @@ @implementation RCTMGLRasterLayer - (MGLStyleLayer*)makeLayer:(MGLStyle*)style { MGLSource *source = [style sourceWithIdentifier:self.sourceID]; + if (source == nil) { return nil; } MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithIdentifier:self.id source:source]; return layer; } diff --git a/ios/RCTMGL/RCTMGLRasterSource.m b/ios/RCTMGL/RCTMGLRasterSource.m index 76f7359b7..049da0db8 100644 --- a/ios/RCTMGL/RCTMGLRasterSource.m +++ b/ios/RCTMGL/RCTMGLRasterSource.m @@ -10,7 +10,7 @@ @implementation RCTMGLRasterSource -- (MGLSource*)makeSource +- (nullable MGLSource*)makeSource { if (self.url != nil) { NSURL *url = [NSURL URLWithString:self.url]; diff --git a/ios/RCTMGL/RCTMGLShapeSource.m b/ios/RCTMGL/RCTMGLShapeSource.m index e5eb4f13a..fe55f6f49 100644 --- a/ios/RCTMGL/RCTMGLShapeSource.m +++ b/ios/RCTMGL/RCTMGLShapeSource.m @@ -50,7 +50,7 @@ - (void)removeFromMap [super removeFromMap]; } -- (MGLSource*)makeSource +- (nullable MGLSource*)makeSource { NSDictionary *options = [self _getOptions]; @@ -59,8 +59,11 @@ - (MGLSource*)makeSource return [[MGLShapeSource alloc] initWithIdentifier:self.id shape:shape options:options]; } - NSURL *url = [[NSURL alloc] initWithString:_url]; - return [[MGLShapeSource alloc] initWithIdentifier:self.id URL:url options:options]; + if (_url != nil) { + NSURL *url = [[NSURL alloc] initWithString:_url]; + return [[MGLShapeSource alloc] initWithIdentifier:self.id URL:url options:options]; + } + return nil; } - (NSDictionary*)_getOptions diff --git a/ios/RCTMGL/RCTMGLSource.h b/ios/RCTMGL/RCTMGLSource.h index fa3c282e2..03c66c5e1 100644 --- a/ios/RCTMGL/RCTMGLSource.h +++ b/ios/RCTMGL/RCTMGLSource.h @@ -27,7 +27,7 @@ extern NSString * _Nonnull const DEFAULT_SOURCE_ID; - (void)addToMap; - (void)removeFromMap; -- (MGLSource*)makeSource; +- (nullable MGLSource*)makeSource; - (NSArray *)getLayerIDs; + (BOOL)isDefaultSource:(NSString*)sourceID; diff --git a/ios/RCTMGL/RCTMGLSource.m b/ios/RCTMGL/RCTMGLSource.m index a5973d71d..536317751 100644 --- a/ios/RCTMGL/RCTMGLSource.m +++ b/ios/RCTMGL/RCTMGLSource.m @@ -9,6 +9,7 @@ #import "RCTMGLSource.h" #import "UIView+React.h" #import "RCTMGLMapView.h" +#import @implementation RCTMGLSource @@ -83,7 +84,11 @@ - (void)addToMap _source = existingSource; } else { _source = [self makeSource]; - [_map.style addSource:_source]; + if (_source != nil) { + [_map.style addSource:_source]; + } else { + RCTLogError(@"Count not find source: %@. Either make sure it's an existing id or provide url/shape or other data required to create that source", _id); + } } if (_layers.count > 0) { @@ -112,7 +117,7 @@ - (void)removeFromMap } } -- (MGLSource*)makeSource +- (nullable MGLSource*)makeSource { @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] diff --git a/ios/RCTMGL/RCTMGLSymbolLayer.m b/ios/RCTMGL/RCTMGLSymbolLayer.m index f56fc907a..57d17acdd 100644 --- a/ios/RCTMGL/RCTMGLSymbolLayer.m +++ b/ios/RCTMGL/RCTMGLSymbolLayer.m @@ -91,6 +91,7 @@ - (void)addedToMap - (MGLSymbolStyleLayer*)makeLayer:(MGLStyle*)style { MGLSource *source = [style sourceWithIdentifier:self.sourceID]; + if (source == nil) { return nil; } MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:self.id source:source]; layer.sourceLayerIdentifier = self.sourceLayerID; return layer;