diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2018-01-25 10:46:27 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-25 10:46:27 -0800 |
commit | b6747a84f4ba6bd48ab2d461e04cffa7fc8d5348 (patch) | |
tree | e01efa0e57e6dc5a0a55db2f68bc964cb6fb1606 /platform/macos/app/MapDocument.m | |
parent | a4546a84de28cfddfcb1e5a4ba8b0516a4b4dfa4 (diff) | |
download | qtlocation-mapboxgl-b6747a84f4ba6bd48ab2d461e04cffa7fc8d5348.tar.gz |
[ios, macos] Hook up hillshade style layers, raster DEM sources to iOS/macOS (#11036)
* [ios, macos] Finished implementing MGLHillshadeStyleLayer
* [macos] Added icon for hillshade layer
Also set the background layer icon to mirror in right-to-left locales.
* [ios, macos] Implemented raster DEM source
* [macos] Added Enhance Terrain debugging command
* [ios, macos] Simplified raster DEM source example
Diffstat (limited to 'platform/macos/app/MapDocument.m')
-rw-r--r-- | platform/macos/app/MapDocument.m | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 94b0cffcdc..602ed1aa41 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -50,6 +50,25 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio return flattenedShapes; } +@interface MGLVectorSource (MBXAdditions) + +@property (nonatomic, readonly, getter=isMapboxTerrain) BOOL mapboxTerrain; + +@end + +@implementation MGLVectorSource (MBXAdditions) + +- (BOOL)isMapboxTerrain { + NSURL *url = self.configurationURL; + if (![url.scheme isEqualToString:@"mapbox"]) { + return NO; + } + NSArray *identifiers = [url.host componentsSeparatedByString:@","]; + return [identifiers containsObject:@"mapbox.mapbox-terrain-v2"] || [identifiers containsObject:@"mapbox.mapbox-terrain-v1"]; +} + +@end + @interface MapDocument () <NSWindowDelegate, NSSharingServicePickerDelegate, NSMenuDelegate, NSSplitViewDelegate, MGLMapViewDelegate, MGLComputedShapeSourceDataSource> @property (weak) IBOutlet NSArrayController *styleLayersArrayController; @@ -739,6 +758,49 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio [self.mapView.style removeSource:source]; } +- (IBAction)enhanceTerrain:(id)sender { + // Find all the identifiers of Mapbox Terrain sources used in the style. + NSMutableSet *terrainSourceIdentifiers = [NSMutableSet set]; + for (MGLVectorSource *source in self.mapView.style.sources) { + if (![source isKindOfClass:[MGLVectorSource class]]) { + continue; + } + + if (source.mapboxTerrain) { + [terrainSourceIdentifiers addObject:source.identifier]; + } + } + + // Find and remove all the style layers using those sources. + NSUInteger hillshadeIndex = NSNotFound; + NSEnumerator *layerEnumerator = self.mapView.style.layers.objectEnumerator; + MGLVectorStyleLayer *layer; + for (NSUInteger i = 0; (layer = layerEnumerator.nextObject); i++) { + if (![layer isKindOfClass:[MGLVectorStyleLayer class]]) { + continue; + } + + if ([terrainSourceIdentifiers containsObject:layer.sourceIdentifier] + && [layer.sourceLayerIdentifier isEqualToString:@"hillshade"]) { + hillshadeIndex = i; + [self.mapView.style removeLayer:layer]; + } + } + + if (hillshadeIndex == NSNotFound) { + return; + } + + // Add a Mapbox Terrain-RGB source. + NSURL *terrainRGBURL = [NSURL URLWithString:@"mapbox://mapbox.terrain-rgb"]; + MGLRasterDEMSource *terrainRGBSource = [[MGLRasterDEMSource alloc] initWithIdentifier:@"terrain" configurationURL:terrainRGBURL]; + [self.mapView.style addSource:terrainRGBSource]; + + // Insert a hillshade layer where the Mapbox Terrain–based layers were. + MGLHillshadeStyleLayer *hillshadeLayer = [[MGLHillshadeStyleLayer alloc] initWithIdentifier:@"hillshade" source:terrainRGBSource]; + [self.mapView.style insertLayer:hillshadeLayer atIndex:hillshadeIndex]; +} + #pragma mark Offline packs - (IBAction)addOfflinePack:(id)sender { @@ -1058,6 +1120,9 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio if (menuItem.action == @selector(showAllAnnotations:) || menuItem.action == @selector(removeAllAnnotations:)) { return self.mapView.annotations.count > 0; } + if (menuItem.action == @selector(enhanceTerrain:)) { + return YES; + } if (menuItem.action == @selector(startWorldTour:)) { return !_isTouringWorld; } |