@@ -19,26 +19,43 @@ struct ShowGridView: View {
1919 /// The view model for the sample.
2020 @StateObject private var model = Model ( )
2121
22+ /// The current viewpoint of the geo views.
23+ @State private var viewpoint = Viewpoint ( latitude: 34.05 , longitude: - 118.25 , scale: 8e6 )
24+
2225 /// A Boolean value indicating whether the settings view should be presented.
2326 @State private var showsGridSettingsView = false
2427
2528 var body : some View {
26- MapView ( map: model. map)
27- . grid ( model. grid)
28- . toolbar {
29- ToolbarItem ( placement: . bottomBar) {
30- Button ( " Grid Settings " ) {
31- showsGridSettingsView = true
32- }
33- . popover ( isPresented: $showsGridSettingsView) {
34- NavigationStack {
35- GridSettingsView ( model: model)
36- }
37- . presentationDetents ( [ . fraction( 0.6 ) , . large] )
38- . frame ( idealWidth: 350 , idealHeight: 480 )
29+ Group {
30+ if model. geoViewType == . mapView {
31+ MapView ( map: model. map, viewpoint: viewpoint)
32+ . grid ( model. grid)
33+ . onViewpointChanged ( kind: . centerAndScale) { viewpoint = $0 }
34+ } else {
35+ SceneView ( scene: model. scene, viewpoint: viewpoint)
36+ . grid ( model. grid)
37+ . onViewpointChanged ( kind: . centerAndScale) { viewpoint = $0 }
38+ }
39+ }
40+ . toolbar {
41+ ToolbarItemGroup ( placement: . bottomBar) {
42+ Button ( " Grid Settings " ) {
43+ showsGridSettingsView = true
44+ }
45+ . popover ( isPresented: $showsGridSettingsView) {
46+ NavigationStack {
47+ GridSettingsView ( model: model)
3948 }
49+ . presentationDetents ( [ . fraction( 0.6 ) , . large] )
50+ . frame ( idealWidth: 350 , idealHeight: 480 )
51+ }
52+
53+ Picker ( " Geo View " , selection: $model. geoViewType) {
54+ Text ( " Map View " ) . tag ( GeoViewType . mapView)
55+ Text ( " Scene View " ) . tag ( GeoViewType . sceneView)
4056 }
4157 }
58+ }
4259 }
4360}
4461
@@ -47,14 +64,23 @@ private extension ShowGridView {
4764
4865 /// The view model for the sample.
4966 final class Model : ObservableObject {
50- /// A map with topographic basemap.
51- let map : Map = {
52- let map = Map ( basemapStyle: . arcGISTopographic)
53- map. initialViewpoint = Viewpoint ( latitude: 34.05 , longitude: - 118.25 , scale: 8e6 )
54- return map
67+ /// A map with a topographic basemap.
68+ let map = Map ( basemapStyle: . arcGISTopographic)
69+
70+ /// A scene with elevation and a topographic basemap.
71+ let scene : ArcGIS . Scene = {
72+ let scene = Scene ( basemapStyle: . arcGISTopographic)
73+ let elevationSource = ArcGISTiledElevationSource ( url: . worldElevationService)
74+ scene. baseSurface. addElevationSource ( elevationSource)
75+ return scene
5576 } ( )
5677
57- /// The map view's grid, initially set to a Lat-Lon grid.
78+ /// The type of geo view that is showing.
79+ @Published var geoViewType = GeoViewType . mapView {
80+ didSet { grid = makeGrid ( type: gridType) }
81+ }
82+
83+ /// The geo view's grid, initially set to a Lat-Lon grid.
5884 @Published var grid : ArcGIS . Grid = LatitudeLongitudeGrid ( )
5985
6086 /// The kind of grid to display.
@@ -71,6 +97,11 @@ private extension ShowGridView {
7197 /// The units used for labeling the MGRS grid.
7298 @Published var mgrsLabelUnit : MGRSGrid . LabelUnit = . kilometersMeters
7399
100+ /// A Boolean value indicating whether the current grid only supports `LabelPosition.geographic`.
101+ var gridOnlySupportsGeographic : Bool {
102+ geoViewType == . sceneView && gridType != . latitudeLongitude
103+ }
104+
74105 /// Creates a new grid of a given type.
75106 /// - Parameter gridType: The kind of grid to make.
76107 /// - Returns: A new `Grid` object.
@@ -97,12 +128,17 @@ private extension ShowGridView {
97128 newGrid. labelsAreVisible = grid. labelsAreVisible
98129 newGrid. linesColor = grid. linesColor
99130 newGrid. labelsColor = grid. labelsColor
100- newGrid. labelPosition = grid. labelPosition
131+ newGrid. labelPosition = gridOnlySupportsGeographic ? . geographic : grid. labelPosition
101132
102133 return newGrid
103134 }
104135 }
105136
137+ /// A type of `GeoView`.
138+ enum GeoViewType {
139+ case mapView, sceneView
140+ }
141+
106142 // MARK: - Settings View
107143
108144 struct GridSettingsView : View {
@@ -136,6 +172,7 @@ private extension ShowGridView {
136172 Text ( position. label)
137173 }
138174 }
175+ . disabled ( model. gridOnlySupportsGeographic)
139176
140177 if let latitudeLongitudeGrid = model. grid as? LatitudeLongitudeGrid {
141178 Picker ( " Format " , selection: $model. labelFormat) {
@@ -211,7 +248,7 @@ private extension ArcGIS.Grid {
211248}
212249
213250private extension ShowGridView {
214- /// The kinds of grid to show in a map view.
251+ /// The kinds of grid to show on the geo view.
215252 enum GridType : CaseIterable {
216253 case latitudeLongitude, mgrs, usng, utm
217254
@@ -289,6 +326,13 @@ private extension USNGGrid.LabelUnit {
289326 }
290327}
291328
329+ private extension URL {
330+ /// A web URL to the Terrain3D image server on ArcGIS REST.
331+ static var worldElevationService : URL {
332+ URL ( string: " https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer " ) !
333+ }
334+ }
335+
292336// MARK: - Preview
293337
294338#Preview {
0 commit comments