Skip to content

Commit 9b5e60c

Browse files
committed
Apply suggestions from Caleb
1 parent 7a09f93 commit 9b5e60c

File tree

2 files changed

+20
-39
lines changed

2 files changed

+20
-39
lines changed

Shared/Samples/Add web tiled layer/AddWebTiledLayerView.swift

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,31 @@ import ArcGIS
1616
import SwiftUI
1717

1818
struct AddWebTiledLayerView: View {
19-
/// The view model for the sample.
20-
@StateObject private var model = Model()
19+
// A map with web tiled layer as a basemap.
20+
@State private var map: Map = {
21+
// Build the web tiled layer from ArcGIS Living Atlas of the World tile service url.
22+
let webTiledLayer = WebTiledLayer(urlTemplate: .worldTileServiceStringURL)
23+
webTiledLayer.setAttribution(.attributionString)
24+
25+
let basemap = Basemap(baseLayer: webTiledLayer)
26+
let map = Map(basemap: basemap)
27+
map.initialViewpoint = Viewpoint(
28+
center: Point(x: -1e6, y: 1e6),
29+
scale: 15e7
30+
)
31+
return map
32+
}()
2133

2234
var body: some View {
23-
VStack {
24-
MapView(map: model.map)
25-
}
35+
MapView(map: map)
2636
}
2737
}
2838

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.makeMap()
38-
}
39-
40-
/// A map with a web tiled layer as basemap.
41-
static func makeMap() -> 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-
}
39+
private extension String {
40+
static let attributionString = """
41+
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.
42+
"""
43+
static var worldTileServiceStringURL = "https://services.arcgisonline.com/ArcGIS/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{level}/{row}/{col}.jpg"
6344
}
6445

6546
#Preview {
102 KB
Loading

0 commit comments

Comments
 (0)