@@ -9,42 +9,46 @@ import CoreLocation
99
1010struct MapContentView : View {
1111 @ObservedObject var viewModel : MapViewModel
12-
12+
1313 init ( viewModel: MapViewModel ) {
1414 self . viewModel = viewModel
1515 }
1616
1717 var body : some View {
1818 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)
4640 }
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)
4852 }
4953 }
5054}
@@ -68,7 +72,7 @@ class MapViewModel: ObservableObject {
6872 init ( viewpoint : Viewpoint ) {
6973 self . viewpoint = viewpoint
7074 }
71-
75+
7276 /// Stops the location data source.
7377 func stopLocationDataSource( ) {
7478 Task {
0 commit comments