From 84cabd9aa70ef511ddd09f1f594cf8748c7bad6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 24 Jan 2018 16:53:07 -0800 Subject: [ios, macos] Simplified raster DEM source example --- platform/darwin/src/MGLRasterDEMSource.h | 13 +++++-------- .../darwin/test/MGLDocumentationExampleTests.swift | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/platform/darwin/src/MGLRasterDEMSource.h b/platform/darwin/src/MGLRasterDEMSource.h index 50896f4fc9..d00912ca79 100644 --- a/platform/darwin/src/MGLRasterDEMSource.h +++ b/platform/darwin/src/MGLRasterDEMSource.h @@ -19,18 +19,15 @@ `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 + Mapbox Terrain-RGB. ### Example ```swift - let source = MGLRasterDEMSource(identifier: "hills", tileURLTemplates: ["https://example.com/raster-rgb/{z}/{x}/{y}.png"], options: [ - .minimumZoomLevel: 9, - .maximumZoomLevel: 16, - .tileSize: 512, - .attributionInfos: [ - MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com")) - ] - ]) + let terrainRGBURL = URL(string: "mapbox://mapbox.terrain-rgb")! + let source = MGLRasterDEMSource(identifier: "hills", configurationURL: terrainRGBURL) mapView.style?.addSource(source) ``` */ diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift index 37f04a718b..9bf9924869 100644 --- a/platform/darwin/test/MGLDocumentationExampleTests.swift +++ b/platform/darwin/test/MGLDocumentationExampleTests.swift @@ -90,15 +90,19 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { } func testMGLRasterDEMSource() { + // We want to use mapbox.terrain-rgb in the example, but using a mapbox: + // URL requires setting an access token. So this identically named + // subclass of MGLRasterDEMSource swaps in a nonexistent URL. + class MGLRasterDEMSource: Mapbox.MGLRasterDEMSource { + override init(identifier: String, configurationURL: URL, tileSize: CGFloat = 256) { + let bogusURL = URL(string: "https://example.com/raster-rgb.json")! + super.init(identifier: identifier, configurationURL: bogusURL, tileSize: tileSize) + } + } + //#-example-code - let source = MGLRasterDEMSource(identifier: "hills", tileURLTemplates: ["https://example.com/raster-rgb/{z}/{x}/{y}.png"], options: [ - .minimumZoomLevel: 9, - .maximumZoomLevel: 16, - .tileSize: 512, - .attributionInfos: [ - MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com")) - ] - ]) + let terrainRGBURL = URL(string: "mapbox://mapbox.terrain-rgb")! + let source = MGLRasterDEMSource(identifier: "hills", configurationURL: terrainRGBURL) mapView.style?.addSource(source) //#-end-example-code @@ -276,7 +280,7 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { let source = MGLRasterDEMSource(identifier: "dem", tileURLTemplates: ["https://example.com/raster-rgb/{z}/{x}/{y}.png"], options: [ .minimumZoomLevel: 9, .maximumZoomLevel: 16, - .tileSize: 512, + .tileSize: 256, .attributionInfos: [ MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com")) ] -- cgit v1.2.1