Skip to content

Commit 723635f

Browse files
committed
added updating the view on view updation
1 parent 91e8116 commit 723635f

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

GoInfoGame/GoInfoGame/UI/Map/CustomMap.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct CustomMap: UIViewRepresentable {
2828
@Binding var isMultiSelectModeEnabled: Bool
2929
@Binding var selectedAnnotationType: String?
3030
@Binding var showMultiSelectionBottomSheet: Bool
31+
@Binding var selectedSattiliteOption: SatelliteOption
3132

3233
@State var lineCoordinates: [CLLocationCoordinate2D] = []
3334

@@ -64,6 +65,10 @@ struct CustomMap: UIViewRepresentable {
6465
}
6566
}
6667

68+
if case .wmts(let satelliteServer) = selectedSattiliteOption {
69+
mapView.addOverlay(WMTSSeever(satelliteServer: satelliteServer), level: .aboveLabels)
70+
}
71+
6772
let tapGesture = UILongPressGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.handleMapTap(_:)))
6873
mapView.addGestureRecognizer(tapGesture)
6974

@@ -97,9 +102,9 @@ struct CustomMap: UIViewRepresentable {
97102

98103

99104
// Remove existing overlays
100-
// mapView.overlays.forEach { mapView.removeOverlay($0) }
105+
mapView.overlays.forEach { mapView.removeOverlay($0) }
101106

102-
// mapView.addOverlay(shadowOverlay)
107+
mapView.addOverlay(shadowOverlay)
103108

104109

105110
// Re-add overlays based on selection
@@ -110,6 +115,10 @@ struct CustomMap: UIViewRepresentable {
110115
mapView.addOverlay(tileOverlay, level: .aboveLabels)
111116
}
112117

118+
if case .wmts(let satelliteServer) = selectedSattiliteOption {
119+
mapView.addOverlay(WMTSSeever(satelliteServer: satelliteServer), level: .aboveLabels)
120+
}
121+
113122
// if useBingMaps {
114123
// let tileOverlay = BingTileOverlay()
115124
// tileOverlay.minimumZ = 3 // Set minimum zoom level

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,25 @@ struct MapView: View {
7979
selectedQuest: $viewModel.selectedQuest,
8080
shouldShowPolyline: $shouldShowPolyline,
8181

82-
isPresented: $isPresented, isUserSettingsPresented: $showUserSettingsSheet, selectedAnnotations: $viewModel.selectedAnnotaions, isMultiSelectModeEnabled: $viewModel.isMultiSelectModeEnabled, selectedAnnotationType: $viewModel.selectedAnnotationType, showMultiSelectionBottomSheet: $showMultiSelectionBottomSheet ,
83-
onMapViewCreated: { map in
84-
self.mapViewRef = map
85-
} ,
86-
contextualInfo: { contextualInfo in
87-
print(contextualInfo)
88-
selectedDetent = .fraction(0.8)
89-
self.setContextualInfo(contextualinfo: contextualInfo)
90-
}, useBingMaps: $useBingMaps, tappedCoordinate: $tappedCoordinate, annotationCoordinate: $annotationCoordinate, shadowOverlay: shadowOverlay)
82+
isPresented: $isPresented,
83+
isUserSettingsPresented: $showUserSettingsSheet,
84+
selectedAnnotations: $viewModel.selectedAnnotaions,
85+
isMultiSelectModeEnabled: $viewModel.isMultiSelectModeEnabled,
86+
selectedAnnotationType: $viewModel.selectedAnnotationType,
87+
showMultiSelectionBottomSheet: $showMultiSelectionBottomSheet ,
88+
selectedSattiliteOption: $viewModel.selectedOption,
89+
onMapViewCreated: { map in
90+
self.mapViewRef = map
91+
} ,
92+
contextualInfo: { contextualInfo in
93+
print(contextualInfo)
94+
selectedDetent = .fraction(0.8)
95+
self.setContextualInfo(contextualinfo: contextualInfo)
96+
},
97+
useBingMaps: $useBingMaps,
98+
tappedCoordinate: $tappedCoordinate,
99+
annotationCoordinate: $annotationCoordinate,
100+
shadowOverlay: shadowOverlay)
91101
.onChange(of: tappedCoordinate) { _ in
92102
showMapLongPressedSheet = tappedCoordinate != nil
93103
}
@@ -242,18 +252,7 @@ struct MapView: View {
242252
onSelect: { selected in
243253
viewModel.selectedOption = selected
244254
viewModel.showSatellitePicker = false
245-
// Remove old tile overlays (keep polygons, etc. if needed)
246-
let oldTileOverlays = mapViewRef?.overlays.filter { $0 is WMTSSeever }
247-
mapViewRef?.removeOverlays(oldTileOverlays ?? [])
248-
switch selected {
249-
case .none:
250-
mapViewRef?.mapType = .standard
251-
case .apple:
252-
mapViewRef?.mapType = .satellite
253-
case .wmts(let server):
254-
let layer = WMTSSeever(satelliteServer: server)
255-
mapViewRef?.addOverlay(layer, level: .aboveLabels)
256-
}
255+
addOverlay(selectedSatilliteOption: selected)
257256
}
258257
)
259258
.background(Color(red: 248/255, green: 248/255, blue: 248/255))
@@ -440,6 +439,21 @@ struct MapView: View {
440439
}
441440
}
442441

442+
func addOverlay(selectedSatilliteOption: SatelliteOption) {
443+
// Remove old tile overlays (keep polygons, etc. if needed)
444+
let oldTileOverlays = mapViewRef?.overlays.filter { $0 is WMTSSeever }
445+
mapViewRef?.removeOverlays(oldTileOverlays ?? [])
446+
switch selectedSatilliteOption {
447+
case .none:
448+
mapViewRef?.mapType = .standard
449+
case .apple:
450+
mapViewRef?.mapType = .satellite
451+
case .wmts(let server):
452+
let layer = WMTSSeever(satelliteServer: server)
453+
mapViewRef?.addOverlay(layer, level: .aboveLabels)
454+
}
455+
}
456+
443457
func switchToInitialView() {
444458
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
445459
let window = scene.windows.first {

0 commit comments

Comments
 (0)