diff options
Diffstat (limited to 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/MGLForegroundStyleLayer.h | 9 | ||||
-rw-r--r-- | platform/darwin/src/MGLHillshadeStyleLayer.h | 25 | ||||
-rw-r--r-- | platform/darwin/src/MGLHillshadeStyleLayer.mm | 29 | ||||
-rw-r--r-- | platform/darwin/src/MGLRasterDEMSource.h | 37 | ||||
-rw-r--r-- | platform/darwin/src/MGLRasterDEMSource.mm | 17 | ||||
-rw-r--r-- | platform/darwin/src/MGLRasterSource.mm | 11 | ||||
-rw-r--r-- | platform/darwin/src/MGLRasterSource_Private.h | 13 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyle.mm | 8 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayer.h.ejs | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayer.mm.ejs | 2 |
10 files changed, 112 insertions, 43 deletions
diff --git a/platform/darwin/src/MGLForegroundStyleLayer.h b/platform/darwin/src/MGLForegroundStyleLayer.h index bcd323fb99..7e05023ef1 100644 --- a/platform/darwin/src/MGLForegroundStyleLayer.h +++ b/platform/darwin/src/MGLForegroundStyleLayer.h @@ -11,10 +11,11 @@ NS_ASSUME_NONNULL_BEGIN `MGLForegroundStyleLayer` is an abstract superclass for style layers whose content is defined by an `MGLSource` object. - Create instances of `MGLRasterStyleLayer` and the concrete subclasses of - `MGLVectorStyleLayer` in order to use `MGLForegroundStyleLayer`'s methods. - Do not create instances of `MGLForegroundStyleLayer` directly, and do not - create your own subclasses of this class. + Create instances of `MGLRasterStyleLayer`, `MGLHillshadeStyleLayer`, and the + concrete subclasses of `MGLVectorStyleLayer` in order to use + `MGLForegroundStyleLayer`'s methods. Do not create instances of + `MGLForegroundStyleLayer` directly, and do not create your own subclasses of + this class. */ MGL_EXPORT @interface MGLForegroundStyleLayer : MGLStyleLayer diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.h b/platform/darwin/src/MGLHillshadeStyleLayer.h index 199bf214c2..b2eeb59aba 100644 --- a/platform/darwin/src/MGLHillshadeStyleLayer.h +++ b/platform/darwin/src/MGLHillshadeStyleLayer.h @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLVectorStyleLayer.h" +#import "MGLForegroundStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -24,8 +24,20 @@ typedef NS_ENUM(NSUInteger, MGLHillshadeIlluminationAnchor) { }; /** - Client-side hillshading visualization based on DEM data. Currently, the - implementation only supports Mapbox Terrain RGB tiles + An `MGLHillshadeStyleLayer` is a style layer that renders raster <a + href="https://en.wikipedia.org/wiki/Digital_elevation_model">digital elevation + model</a> (DEM) tiles on the map. + + Use a hillshade style layer to configure the color parameters of raster tiles + loaded by an `MGLRasterDEMSource` object. For example, you could use a + hillshade style layer to render <a + href="https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb">Mapbox + Terrain-RGB</a> data. + + To display posterized hillshading based on vector shapes, as with the <a + href="https://www.mapbox.com/vector-tiles/mapbox-terrain/">Mapbox Terrain</a> + source, use an `MGLVectorSource` object in conjunction with several + `MGLFillStyleLayer` objects. You can access an existing hillshade style layer using the `-[MGLStyle layerWithIdentifier:]` method if you know its identifier; @@ -36,10 +48,15 @@ typedef NS_ENUM(NSUInteger, MGLHillshadeIlluminationAnchor) { ### Example ```swift + let layer = MGLHillshadeStyleLayer(identifier: "hills", source: source) + layer.hillshadeExaggeration = NSExpression(forConstantValue: 0.6) + if let canalShadowLayer = mapView.style?.layer(withIdentifier: "waterway-river-canal-shadow") { + mapView.style?.insertLayer(layer, below: canalShadowLayer) + } ``` */ MGL_EXPORT -@interface MGLHillshadeStyleLayer : MGLVectorStyleLayer +@interface MGLHillshadeStyleLayer : MGLForegroundStyleLayer /** Returns a hillshade style layer initialized with an identifier and source. diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.mm b/platform/darwin/src/MGLHillshadeStyleLayer.mm index 538a99daf6..2383c1ce26 100644 --- a/platform/darwin/src/MGLHillshadeStyleLayer.mm +++ b/platform/darwin/src/MGLHillshadeStyleLayer.mm @@ -46,35 +46,6 @@ namespace mbgl { return @(self.rawLayer->getSourceID().c_str()); } -- (NSString *)sourceLayerIdentifier -{ - MGLAssertStyleLayerIsValid(); - - auto layerID = self.rawLayer->getSourceLayer(); - return layerID.empty() ? nil : @(layerID.c_str()); -} - -- (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier -{ - MGLAssertStyleLayerIsValid(); - - self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); -} - -- (void)setPredicate:(NSPredicate *)predicate -{ - MGLAssertStyleLayerIsValid(); - - self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); -} - -- (NSPredicate *)predicate -{ - MGLAssertStyleLayerIsValid(); - - return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; -} - #pragma mark - Accessing the Paint Attributes - (void)setHillshadeAccentColor:(NSExpression *)hillshadeAccentColor { diff --git a/platform/darwin/src/MGLRasterDEMSource.h b/platform/darwin/src/MGLRasterDEMSource.h new file mode 100644 index 0000000000..d00912ca79 --- /dev/null +++ b/platform/darwin/src/MGLRasterDEMSource.h @@ -0,0 +1,37 @@ +#import "MGLFoundation.h" + +#import "MGLRasterSource.h" + +/** + `MGLRasterDEMSource` is a map content source that supplies rasterized + <a href="https://en.wikipedia.org/wiki/Digital_elevation_model">digital elevation model</a> + (DEM) tiles to be shown on the map. The location of and metadata about the + tiles are defined either by an option dictionary or by an external file that + conforms to the + <a href="https://github.com/mapbox/tilejson-spec/">TileJSON specification</a>. + A raster DEM source is added to an `MGLStyle` object along with one or more + `MGLHillshadeStyleLayer` objects. Use a hillshade style layer to control the + appearance of content supplied by the raster DEM source. + + Each + <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-raster-dem"><code>raster-dem</code></a> + source defined by the style JSON file is represented at runtime by an + `MGLRasterDEMSource` object that you can use to initialize new style layers. + You can also add and remove sources dynamically using methods such as + `-[MGLStyle addSource:]` and `-[MGLStyle sourceWithIdentifier:]`. + + Currently, raster DEM sources only support the format used by + <a href="https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb">Mapbox Terrain-RGB</a>. + + ### Example + + ```swift + let terrainRGBURL = URL(string: "mapbox://mapbox.terrain-rgb")! + let source = MGLRasterDEMSource(identifier: "hills", configurationURL: terrainRGBURL) + mapView.style?.addSource(source) + ``` + */ +MGL_EXPORT +@interface MGLRasterDEMSource : MGLRasterSource + +@end diff --git a/platform/darwin/src/MGLRasterDEMSource.mm b/platform/darwin/src/MGLRasterDEMSource.mm new file mode 100644 index 0000000000..d8639b70e3 --- /dev/null +++ b/platform/darwin/src/MGLRasterDEMSource.mm @@ -0,0 +1,17 @@ +#import "MGLRasterDEMSource.h" + +#import "MGLRasterSource_Private.h" +#import "NSURL+MGLAdditions.h" + +#import <mbgl/style/sources/raster_dem_source.hpp> + +@implementation MGLRasterDEMSource + +- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize { + NSString *configurationURLString = configurationURL.mgl_URLByStandardizingScheme.absoluteString; + return std::make_unique<mbgl::style::RasterDEMSource>(identifier.UTF8String, + configurationURLString.UTF8String, + uint16_t(round(tileSize))); +} + +@end diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm index 8fc18ba69d..c47cc199eb 100644 --- a/platform/darwin/src/MGLRasterSource.mm +++ b/platform/darwin/src/MGLRasterSource.mm @@ -33,12 +33,17 @@ static const CGFloat MGLRasterSourceRetinaTileSize = 512; } - (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize { - auto source = std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String, - configurationURL.mgl_URLByStandardizingScheme.absoluteString.UTF8String, - uint16_t(round(tileSize))); + auto source = [self pendingSourceWithIdentifier:identifier configurationURL:configurationURL tileSize:tileSize]; return self = [super initWithPendingSource:std::move(source)]; } +- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize { + NSString *configurationURLString = configurationURL.mgl_URLByStandardizingScheme.absoluteString; + return std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String, + configurationURLString.UTF8String, + uint16_t(round(tileSize))); +} + - (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates options:(nullable NS_DICTIONARY_OF(MGLTileSourceOption, id) *)options { mbgl::Tileset tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, options); diff --git a/platform/darwin/src/MGLRasterSource_Private.h b/platform/darwin/src/MGLRasterSource_Private.h index 76790bd053..6f40fbc5a9 100644 --- a/platform/darwin/src/MGLRasterSource_Private.h +++ b/platform/darwin/src/MGLRasterSource_Private.h @@ -1,8 +1,21 @@ #import "MGLRasterSource.h" +#include <memory> + +namespace mbgl { + namespace style { + class RasterSource; + } +} + NS_ASSUME_NONNULL_BEGIN @interface MGLRasterSource (Private) + +@property (nonatomic, readonly) mbgl::style::RasterSource *rawSource; + +- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index fefd8fcf37..5128944312 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -8,6 +8,7 @@ #import "MGLLineStyleLayer.h" #import "MGLCircleStyleLayer.h" #import "MGLSymbolStyleLayer.h" +#import "MGLHillshadeStyleLayer.h" #import "MGLRasterStyleLayer.h" #import "MGLBackgroundStyleLayer.h" #import "MGLOpenGLStyleLayer.h" @@ -19,6 +20,7 @@ #import "MGLVectorSource.h" #import "MGLVectorSource_Private.h" #import "MGLRasterSource.h" +#import "MGLRasterDEMSource.h" #import "MGLShapeSource.h" #import "MGLImageSource.h" @@ -34,12 +36,14 @@ #include <mbgl/style/layers/line_layer.hpp> #include <mbgl/style/layers/symbol_layer.hpp> #include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/style/layers/hillshade_layer.hpp> #include <mbgl/style/layers/circle_layer.hpp> #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/layers/custom_layer.hpp> #include <mbgl/style/sources/geojson_source.hpp> #include <mbgl/style/sources/vector_source.hpp> #include <mbgl/style/sources/raster_source.hpp> +#include <mbgl/style/sources/raster_dem_source.hpp> #include <mbgl/style/sources/image_source.hpp> #import "NSDate+MGLAdditions.h" @@ -231,6 +235,8 @@ static NSURL *MGLStyleURL_trafficNight; return [[MGLShapeSource alloc] initWithRawSource:geoJSONSource mapView:self.mapView]; } else if (auto rasterSource = rawSource->as<mbgl::style::RasterSource>()) { return [[MGLRasterSource alloc] initWithRawSource:rasterSource mapView:self.mapView]; + } else if (auto rasterDEMSource = rawSource->as<mbgl::style::RasterDEMSource>()) { + return [[MGLRasterDEMSource alloc] initWithRawSource:rasterDEMSource mapView:self.mapView]; } else if (auto imageSource = rawSource->as<mbgl::style::ImageSource>()) { return [[MGLImageSource alloc] initWithRawSource:imageSource mapView:self.mapView]; } else { @@ -395,6 +401,8 @@ static NSURL *MGLStyleURL_trafficNight; return [[MGLSymbolStyleLayer alloc] initWithRawLayer:symbolLayer]; } else if (auto rasterLayer = rawLayer->as<mbgl::style::RasterLayer>()) { return [[MGLRasterStyleLayer alloc] initWithRawLayer:rasterLayer]; + } else if (auto hillshadeLayer = rawLayer->as<mbgl::style::HillshadeLayer>()) { + return [[MGLHillshadeStyleLayer alloc] initWithRawLayer:hillshadeLayer]; } else if (auto circleLayer = rawLayer->as<mbgl::style::CircleLayer>()) { return [[MGLCircleStyleLayer alloc] initWithRawLayer:circleLayer]; } else if (auto backgroundLayer = rawLayer->as<mbgl::style::BackgroundLayer>()) { diff --git a/platform/darwin/src/MGLStyleLayer.h.ejs b/platform/darwin/src/MGLStyleLayer.h.ejs index db16df3de5..05f450a4f8 100644 --- a/platform/darwin/src/MGLStyleLayer.h.ejs +++ b/platform/darwin/src/MGLStyleLayer.h.ejs @@ -11,7 +11,7 @@ #import "MGLFoundation.h" #import "MGL<%- (type === 'background' ? '' : - (type === 'raster' ? 'Foreground' : + (type === 'raster' || type === 'hillshade' ? 'Foreground' : 'Vector')) %>StyleLayer.h" @@ -78,7 +78,7 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(property.name) %>) { MGL_EXPORT @interface MGL<%- camelize(type) %>StyleLayer : MGL<%- (type === 'background' ? '' : - (type === 'raster' ? 'Foreground' : + (type === 'raster' || type === 'hillshade' ? 'Foreground' : 'Vector')) %>StyleLayer <% if (type === 'background') { -%> diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 8101c1f463..41b029791f 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -83,7 +83,7 @@ namespace mbgl { return @(self.rawLayer->getSourceID().c_str()); } -<% if (type !== 'raster') { -%> +<% if (type !== 'raster' && type !== 'hillshade') { -%> - (NSString *)sourceLayerIdentifier { MGLAssertStyleLayerIsValid(); |