@@ -9,42 +9,46 @@ import CoreLocation
9
9
10
10
struct MapContentView : View {
11
11
@ObservedObject var viewModel : MapViewModel
12
-
12
+
13
13
init ( viewModel: MapViewModel ) {
14
14
self . viewModel = viewModel
15
15
}
16
16
17
17
var body : some View {
18
18
MapViewReader { mapViewProxy in
19
- MapView ( map: viewModel. map,
20
- viewpoint: viewModel. viewpoint,
21
- graphicsOverlays: [ viewModel. defaultGraphicsOverlay] )
22
- . attributionBarHidden ( viewModel. attributionBarHidden)
23
- . locationDisplay ( viewModel. locationDisplay)
24
- . contentInsets ( viewModel. contentInsets)
25
- . interactionModes ( viewModel. interactionModes)
26
- . onViewpointChanged ( kind: . centerAndScale) { newViewpoint in
27
- viewModel. viewpoint = newViewpoint
28
- } . onScaleChanged ( perform: { scale in
29
- viewModel. onScaleChanged ? ( scale)
30
- } ) . onVisibleAreaChanged ( perform: { polygon in
31
- viewModel. onVisibleAreaChanged ? ( polygon)
32
- } )
33
- . onChange ( of: viewModel. map. basemap? . loadStatus) { newValue in
34
- if let newValue {
35
- viewModel. onLoadStatusChanged ? ( newValue)
36
- }
37
- }
38
- . task {
39
- // Store the mapViewProxy for external access
40
- viewModel. mapViewProxy = mapViewProxy
41
- }
42
- . onDisappear {
43
- viewModel. stopLocationDataSource ( )
44
- // Clear the mapViewProxy reference when view disappears
45
- viewModel. mapViewProxy = nil
19
+ MapView (
20
+ map: viewModel. map,
21
+ viewpoint: viewModel. viewpoint,
22
+ graphicsOverlays: [ viewModel. defaultGraphicsOverlay]
23
+ )
24
+ . attributionBarHidden ( viewModel. attributionBarHidden)
25
+ . locationDisplay ( viewModel. locationDisplay)
26
+ . contentInsets ( viewModel. contentInsets)
27
+ . interactionModes ( viewModel. interactionModes)
28
+ . onViewpointChanged ( kind: . centerAndScale) { newViewpoint in
29
+ viewModel. viewpoint = newViewpoint
30
+ }
31
+ . onScaleChanged { scale in
32
+ viewModel. onScaleChanged ? ( scale)
33
+ }
34
+ . onVisibleAreaChanged { polygon in
35
+ viewModel. onVisibleAreaChanged ? ( polygon)
36
+ }
37
+ . onChange ( of: viewModel. map. basemap? . loadStatus) { newValue in
38
+ if let newValue {
39
+ viewModel. onLoadStatusChanged ? ( newValue)
46
40
}
47
- . ignoresSafeArea ( edges: . all)
41
+ }
42
+ . task {
43
+ // Store the mapViewProxy for external access
44
+ viewModel. mapViewProxy = mapViewProxy
45
+ }
46
+ . onDisappear {
47
+ viewModel. stopLocationDataSource ( )
48
+ // Clear the mapViewProxy reference when view disappears
49
+ viewModel. mapViewProxy = nil
50
+ }
51
+ . ignoresSafeArea ( edges: . all)
48
52
}
49
53
}
50
54
}
@@ -68,7 +72,7 @@ class MapViewModel: ObservableObject {
68
72
init ( viewpoint : Viewpoint ) {
69
73
self . viewpoint = viewpoint
70
74
}
71
-
75
+
72
76
/// Stops the location data source.
73
77
func stopLocationDataSource( ) {
74
78
Task {
0 commit comments