diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-01-11 08:06:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-11 08:06:20 -0800 |
commit | 424c12499cab69b935779d306d7d47d19139116e (patch) | |
tree | 56c27e57288a5df08083ede6b54db7204b46a02c /platform/ios | |
parent | 581fb3849da8ce97e557bb3633b886fcc369f6cb (diff) | |
download | qtlocation-mapboxgl-424c12499cab69b935779d306d7d47d19139116e.tar.gz |
[ios, macos] Make MGLMapView.style property nullable (#7664)
* [ios, macos] Made MGLMapView.style property nullable
MGLMapView’s style property is now nullable (optional in Swift). The property is set to nil while the style loads and in the event that the style has failed to load.
* [ios, macos] Switch to delegate method
* [macos] Create MGLMapView programmatically for layer tests
When MGLMapView is created via a nib, -initWithCoder: is called, causing styleURL to be set to nil, in turn causing the default Streets style to be loaded, fooling MGLStyleLayerTests into thinking one-line has been loaded. Instead, create MGLMapView programmatically, passing the intended style URL into the initializer, preventing Streets from being loaded.
Diffstat (limited to 'platform/ios')
-rw-r--r-- | platform/ios/src/MGLMapView.h | 9 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 15 |
2 files changed, 15 insertions, 9 deletions
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 771a48c7ff..62f053e96b 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -123,6 +123,13 @@ IB_DESIGNABLE Unlike the `styleURL` property, this property is set to an object that allows you to manipulate every aspect of the style locally. + If the style is loading, this property is set to `nil` until the style finishes + loading. If the style has failed to load, this property is set to `nil`. + Because the style loads asynchronously, you should manipulate it in the + `-[MGLMapViewDelegate mapView:didFinishLoadingStyle:]` or + `-[MGLMapViewDelegate mapViewDidFinishLoadingMap:]` method. It is not possible + to manipulate the style before it has finished loading. + @note The default styles provided by Mapbox contain sources and layers with identifiers that will change over time. Applications that use APIs that manipulate a style's sources and layers must first set the style URL to an @@ -130,7 +137,7 @@ IB_DESIGNABLE `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URL” inspectable in Interface Builder, or a manually constructed `NSURL`. */ -@property (nonatomic, readonly) MGLStyle *style; +@property (nonatomic, readonly, nullable) MGLStyle *style; /** URLs of the styles bundled with the library. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index ddb11ffbb7..f8ca673093 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -347,6 +347,11 @@ public: return self; } ++ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyle +{ + return [NSSet setWithObject:@"styleURL"]; +} + + (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyleURL { return [NSSet setWithObjects:@"styleURL__", nil]; @@ -369,10 +374,8 @@ public: } styleURL = styleURL.mgl_URLByStandardizingScheme; - [self willChangeValueForKey:@"style"]; - _style = [[MGLStyle alloc] initWithMapView:self]; + self.style = nil; _mbglMap->setStyleURL([[styleURL absoluteString] UTF8String]); - [self didChangeValueForKey:@"style"]; } - (IBAction)reloadStyle:(__unused id)sender { @@ -4682,11 +4685,7 @@ public: } case mbgl::MapChangeDidFinishLoadingStyle: { - [self.style willChangeValueForKey:@"name"]; - [self.style willChangeValueForKey:@"sources"]; - [self.style didChangeValueForKey:@"sources"]; - [self.style willChangeValueForKey:@"layers"]; - [self.style didChangeValueForKey:@"layers"]; + self.style = [[MGLStyle alloc] initWithMapView:self]; if ([self.delegate respondsToSelector:@selector(mapView:didFinishLoadingStyle:)]) { [self.delegate mapView:self didFinishLoadingStyle:self.style]; |