From 2df0654a8f2c49e072885ff598bfbb4855f79606 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 22 Feb 2023 08:09:38 -0800 Subject: [PATCH] Centering on update --- .../Views/Map/Custom/MapViewSwiftUI.swift | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift index 62396ec2..e3f54baa 100644 --- a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift @@ -45,7 +45,7 @@ struct MapViewSwiftUI: UIViewRepresentable { mapView.fit(annotations: positions, andShow: true) case .clientGps: - let span = MKCoordinateSpan(latitudeDelta: 0.001, longitudeDelta: 0.001) + let span = MKCoordinateSpan(latitudeDelta: 0.003, longitudeDelta: 0.003) let center = CLLocationCoordinate2D(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude) let region = MKCoordinateRegion(center: center, span: span) mapView.setRegion(region, animated: true) @@ -68,8 +68,6 @@ struct MapViewSwiftUI: UIViewRepresentable { #if targetEnvironment(macCatalyst) mapView.showsZoomControls = true mapView.showsPitchControl = true - #else - mapView.showsPointsOfInterest = true #endif mapView.delegate = context.coordinator return mapView @@ -102,14 +100,20 @@ struct MapViewSwiftUI: UIViewRepresentable { } DispatchQueue.main.async { - if centeringMode == CenteringMode.clientGps { - let span = MKCoordinateSpan(latitudeDelta: 0.001, longitudeDelta: 0.001) + mapView.removeAnnotations(mapView.annotations) + mapView.addAnnotations(waypoints) + switch centeringMode { + case .allAnnotations: + mapView.addAnnotations(positions) + mapView.fitAllAnnotations() + case .allPositions: + mapView.fit(annotations: positions, andShow: true) + case .clientGps: + mapView.addAnnotations(positions) + let span = MKCoordinateSpan(latitudeDelta: 0.003, longitudeDelta: 0.003) let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude), span: span) mapView.setRegion(region, animated: true) } - mapView.removeAnnotations(mapView.annotations) - mapView.addAnnotations(positions) - mapView.addAnnotations(waypoints) } }