|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +import ArcGIS |
15 | 16 | import SwiftUI |
16 | 17 |
|
17 | 18 | struct AddWebTiledLayerView: View { |
| 19 | + /// The view model for the sample. |
| 20 | + @StateObject private var model = Model() |
| 21 | + |
18 | 22 | var body: some View { |
19 | | - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) |
| 23 | + VStack { |
| 24 | + MapView(map: model.map) |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +private extension AddWebTiledLayerView { |
| 30 | + // MARK: - Model |
| 31 | + |
| 32 | + /// The view model for the sample. |
| 33 | + final class Model: ObservableObject { |
| 34 | + @Published var map: Map |
| 35 | + |
| 36 | + init() { |
| 37 | + self.map = Model.createMap() |
| 38 | + } |
| 39 | + |
| 40 | + /// A map with a web tiled layer as basemap. |
| 41 | + static func createMap() -> Map { |
| 42 | + let webTiledLayer = webTiledLayer() |
| 43 | + let basemap = Basemap(baseLayer: webTiledLayer) |
| 44 | + let map = Map(basemap: basemap) |
| 45 | + return map |
| 46 | + } |
| 47 | + |
| 48 | + static func webTiledLayer() -> WebTiledLayer { |
| 49 | + let worldTileServiceURL = "https://server.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{level}/{row}/{col}.jpg" |
| 50 | + |
| 51 | + let attribution = """ |
| 52 | + Map tiles by <a href="https://livingatlas.arcgis.com">ArcGIS Living Atlas of the World</a>, under <a href="https://www.esri.com/en-us/legal/terms/full-master-agreement">Esri Master License Agreement</a>. Data by Esri, Garmin, GEBCO, NOAA NGDC, and other contributors. |
| 53 | + """ |
| 54 | + |
| 55 | + // Build the web tiled layer from ArcGIS Living Atlas of the World tile service url. |
| 56 | + let webTiledLayer = WebTiledLayer(urlTemplate: worldTileServiceURL) |
| 57 | + // Set the attribution on the layer. |
| 58 | + webTiledLayer.setAttribution(attribution) |
| 59 | + |
| 60 | + return webTiledLayer |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +struct AddWebTiledLayerView_Previews: PreviewProvider { |
| 66 | + static var previews: some View { |
| 67 | + AddWebTiledLayerView() |
20 | 68 | } |
21 | 69 | } |
22 | 70 |
|
|
0 commit comments