diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-08-19 13:56:46 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-11-28 15:45:43 -0800 |
commit | 9fac640bf35db408f56103b45f8ef7982204bfa9 (patch) | |
tree | 95fe49ae283c682db98d3b63a8ebbebf03769450 /platform/darwin | |
parent | 850b70ff91e582916829c5248afcafa195070a43 (diff) | |
download | qtlocation-mapboxgl-9fac640bf35db408f56103b45f8ef7982204bfa9.tar.gz |
[ios, macos] Key-value compliance for MGLStyle
Replaced -[MGLMapView style] with a property. Keep the MGLStyle object around for the lifetime of the style.
Bracket changes to layers in willChange and didChange calls. The built-in point annotation layer is added after the style is finished loading but before the map is finished loading. Cause a second wave of change notifications to go out, about both sources and layers. Issue change notifications for style layers when shape annotations are added or removed.
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/src/MGLStyle.mm | 28 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyle_Private.h | 5 |
2 files changed, 24 insertions, 9 deletions
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 4169c7a5d3..e11ceb028b 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -40,8 +40,10 @@ #endif @interface MGLStyle() -@property (nonatomic, weak) MGLMapView *mapView; + +@property (nonatomic, readwrite, weak) MGLMapView *mapView; @property (readonly, copy, nullable) NSURL *URL; + @end @implementation MGLStyle @@ -98,17 +100,24 @@ static NSURL *MGLStyleURL_emerald; return MGLStyleURL_emerald; } -#pragma mark Metadata +#pragma mark - -- (NSString *)name { - std::string name = self.mapView.mbglMap->getStyleName(); - return name.empty() ? nil : @(name.c_str()); +- (instancetype)initWithMapView:(MGLMapView *)mapView { + if (self = [super init]) { + _mapView = mapView; + } + return self; } - (NSURL *)URL { return [NSURL URLWithString:@(self.mapView.mbglMap->getStyleURL().c_str())]; } +- (NSString *)name { + std::string name = self.mapView.mbglMap->getStyleName(); + return name.empty() ? nil : @(name.c_str()); +} + #pragma mark Sources - (NS_MUTABLE_SET_OF(MGLSource *) *)sources { @@ -158,8 +167,7 @@ static NSURL *MGLStyleURL_emerald; } else if (mbglSource->is<mbgl::style::RasterSource>()) { source = [[MGLRasterSource alloc] initWithIdentifier:identifier]; } else { - NSAssert(NO, @"Unrecognized source type"); - return nil; + source = [[MGLSource alloc] initWithIdentifier:identifier]; } source.rawSource = mbglSource; @@ -320,7 +328,9 @@ static NSURL *MGLStyleURL_emerald; @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", layer]; } - [layer removeFromMapView:self.mapView]; + [self willChangeValueForKey:@"layers"]; + [layer removeFromMapView:self.mapView]; + [self didChangeValueForKey:@"layers"]; } - (void)addLayer:(MGLStyleLayer *)layer @@ -331,7 +341,9 @@ static NSURL *MGLStyleURL_emerald; @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", layer]; } + [self willChangeValueForKey:@"layers"]; [layer addToMapView:self.mapView]; + [self didChangeValueForKey:@"layers"]; } - (void)insertLayer:(MGLStyleLayer *)layer atIndex:(NSUInteger)index { diff --git a/platform/darwin/src/MGLStyle_Private.h b/platform/darwin/src/MGLStyle_Private.h index 46291b37b9..b7c2fa4cdb 100644 --- a/platform/darwin/src/MGLStyle_Private.h +++ b/platform/darwin/src/MGLStyle_Private.h @@ -6,7 +6,10 @@ #include <mbgl/mbgl.hpp> @interface MGLStyle (Private) -@property (nonatomic, weak) MGLMapView *mapView; + +- (instancetype)initWithMapView:(MGLMapView *)mapView; + +@property (nonatomic, readonly, weak) MGLMapView *mapView; - (void)setStyleClasses:(NS_ARRAY_OF(NSString *) *)appliedClasses transitionDuration:(NSTimeInterval)transitionDuration; |