@@ -21,6 +21,7 @@ struct CustomMap: UIViewRepresentable {
2121 @Binding var selectedQuest : DisplayUnit ?
2222 @Binding var shouldShowPolyline : Bool
2323 @Binding var isPresented : Bool
24+ @Binding var isUserSettingsPresented : Bool
2425 @StateObject var locationManagerDelegate = LocationManagerDelegate ( )
2526
2627 @Binding var selectedAnnotations : Set < DisplayUnitAnnotation >
@@ -137,6 +138,8 @@ struct CustomMap: UIViewRepresentable {
137138
138139 let shadowOverlay : ShadowOverlay
139140
141+ var isCenteredOnUser = false
142+
140143 private let maxZoomAltitude : CLLocationDistance = 120
141144 private var zoomReachedLimit : Bool = false
142145
@@ -476,12 +479,21 @@ struct CustomMap: UIViewRepresentable {
476479 // Helper method to manage annotations
477480 private func manageAnnotations( _ mapView: MKMapView , context: Context ) {
478481
479- let existingCoordinates = mapView. annotations. compactMap { ( $0 as? DisplayUnitAnnotation ) ? . coordinate }
482+ let existingCoordinates = mapView. annotations. compactMap {
483+ ( $0 as? DisplayUnitAnnotation ) ? . coordinate
484+ }
480485
481- /// resetting region only when app is launched/re-launched
482- if existingCoordinates. count == 0 {
483- mapView. setCenter ( userLocation, animated: true )
484- }
486+ // Check for modals or settings before changing map
487+ if isPresented || isUserSettingsPresented {
488+ return
489+ }
490+
491+ // ✅ Only if no annotations and safe state
492+ if existingCoordinates. isEmpty && !context. coordinator. isCenteredOnUser {
493+ mapView. setCenter ( userLocation, animated: true )
494+ context. coordinator. isCenteredOnUser = true
495+ }
496+
485497 context. coordinator. isRegionSet = true
486498
487499
0 commit comments