diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-08-18 16:28:58 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-11-23 16:02:18 -0800 |
commit | f71dd14bb74be22fb27646b8732843d92cf72c62 (patch) | |
tree | d2097880e70a0e0cc07ae2a5b9eada25ab5b9249 /platform/darwin/src/MGLStyle.mm | |
parent | 767044420d32f6030d25b6b0c979feac2fa1ff60 (diff) | |
download | qtlocation-mapboxgl-f71dd14bb74be22fb27646b8732843d92cf72c62.tar.gz |
[ios, macos] Reorganized MGLStyle
Diffstat (limited to 'platform/darwin/src/MGLStyle.mm')
-rw-r--r-- | platform/darwin/src/MGLStyle.mm | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 980abe3e3d..69d76614c0 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -46,6 +46,8 @@ @implementation MGLStyle +#pragma mark Default style URLs + static_assert(mbgl::util::default_styles::currentVersion == MGLStyleDefaultVersion, "mbgl::util::default_styles::currentVersion and MGLStyleDefaultVersion disagree."); /// @param name The style’s marketing name, written in lower camelCase. @@ -96,6 +98,8 @@ static NSURL *MGLStyleURL_emerald; return MGLStyleURL_emerald; } +#pragma mark Metadata + - (NSString *)name { return @(self.mapView.mbglMap->getStyleName().c_str()); } @@ -104,6 +108,58 @@ static NSURL *MGLStyleURL_emerald; return [NSURL URLWithString:@(self.mapView.mbglMap->getStyleURL().c_str())]; } +#pragma mark Sources + +- (MGLSource *)sourceWithIdentifier:(NSString *)identifier +{ + auto mbglSource = self.mapView.mbglMap->getSource(identifier.UTF8String); + if (!mbglSource) { + return nil; + } + + // TODO: Fill in options specific to the respective source classes + // https://github.com/mapbox/mapbox-gl-native/issues/6584 + MGLSource *source; + if (mbglSource->is<mbgl::style::VectorSource>()) { + source = [[MGLVectorSource alloc] initWithIdentifier:identifier]; + } else if (mbglSource->is<mbgl::style::GeoJSONSource>()) { + source = [[MGLGeoJSONSource alloc] initWithIdentifier:identifier]; + } else if (mbglSource->is<mbgl::style::RasterSource>()) { + source = [[MGLRasterSource alloc] initWithIdentifier:identifier]; + } else { + NSAssert(NO, @"Unrecognized source type"); + return nil; + } + + source.rawSource = mbglSource; + + return source; +} + +- (void)addSource:(MGLSource *)source +{ + if (!source.rawSource) { + [NSException raise:NSInvalidArgumentException format: + @"The source %@ cannot be added to the style. " + @"Make sure the source was created as a member of a concrete subclass of MGLSource.", + source]; + } + [source addToMapView:self.mapView]; +} + +- (void)removeSource:(MGLSource *)source +{ + if (!source.rawSource) { + [NSException raise:NSInvalidArgumentException format: + @"The source %@ cannot be removed from the style. " + @"Make sure the source was created as a member of a concrete subclass of MGLSource.", + source]; + } + [source removeFromMapView:self.mapView]; +} + +#pragma mark Style layers + - (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier { auto mbglLayer = self.mapView.mbglMap->getLayer(identifier.UTF8String); @@ -139,33 +195,6 @@ static NSURL *MGLStyleURL_emerald; return styleLayer; } -- (MGLSource *)sourceWithIdentifier:(NSString *)identifier -{ - auto mbglSource = self.mapView.mbglMap->getSource(identifier.UTF8String); - - if (!mbglSource) { - return nil; - } - - // TODO: Fill in options specific to the respective source classes - // https://github.com/mapbox/mapbox-gl-native/issues/6584 - MGLSource *source; - if (mbglSource->is<mbgl::style::VectorSource>()) { - source = [[MGLVectorSource alloc] initWithIdentifier:identifier]; - } else if (mbglSource->is<mbgl::style::GeoJSONSource>()) { - source = [[MGLGeoJSONSource alloc] initWithIdentifier:identifier]; - } else if (mbglSource->is<mbgl::style::RasterSource>()) { - source = [[MGLRasterSource alloc] initWithIdentifier:identifier]; - } else { - NSAssert(NO, @"Unrecognized source type"); - return nil; - } - - source.rawSource = mbglSource; - - return source; -} - - (void)removeLayer:(MGLStyleLayer *)layer { if (!layer.rawLayer) { @@ -207,27 +236,7 @@ static NSURL *MGLStyleURL_emerald; [layer addToMapView:self.mapView belowLayer:otherLayer]; } -- (void)addSource:(MGLSource *)source -{ - if (!source.rawSource) { - [NSException raise:NSInvalidArgumentException format: - @"The source %@ cannot be added to the style. " - @"Make sure the source was created as a member of a concrete subclass of MGLSource.", - source]; - } - [source addToMapView:self.mapView]; -} - -- (void)removeSource:(MGLSource *)source -{ - if (!source.rawSource) { - [NSException raise:NSInvalidArgumentException format: - @"The source %@ cannot be removed from the style. " - @"Make sure the source was created as a member of a concrete subclass of MGLSource.", - source]; - } - [source removeFromMapView:self.mapView]; -} +#pragma mark Style classes - (NS_ARRAY_OF(NSString *) *)styleClasses { @@ -282,6 +291,8 @@ static NSURL *MGLStyleURL_emerald; } } +#pragma mark Style images + - (void)setImage:(MGLImage *)image forName:(NSString *)name { NSAssert(image, @"image is null"); |