From f59b4a8a868285d4f8f31d753eb0629165824355 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 15 Jan 2023 12:47:42 -0800 Subject: [PATCH] Center the node detail map on positions, node map on both positions and waypoints --- Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift | 8 +++++++- Meshtastic/Views/Nodes/NodeDetail.swift | 2 ++ Meshtastic/Views/Nodes/NodeMap.swift | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift index a8e37692..9438e038 100644 --- a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift @@ -15,6 +15,7 @@ struct MapViewSwiftUI: UIViewRepresentable { let positions: [PositionEntity] let waypoints: [WaypointEntity] let mapViewType: MKMapType + let centerOnPositionsOnly: Bool // Offline Maps //make this view dependent on the UserDefault that is updated when importing a new map file @@ -27,8 +28,13 @@ struct MapViewSwiftUI: UIViewRepresentable { func makeUIView(context: Context) -> MKMapView { // Parameters - mapView.fit(annotations: positions, andShow: true) mapView.addAnnotations(waypoints) + if centerOnPositionsOnly { + mapView.fit(annotations: positions, andShow: true) + } else { + mapView.addAnnotations(positions) + mapView.fitAllAnnotations() + } mapView.mapType = mapViewType mapView.setUserTrackingMode(.none, animated: true) // Other MKMapView Settings diff --git a/Meshtastic/Views/Nodes/NodeDetail.swift b/Meshtastic/Views/Nodes/NodeDetail.swift index f1d8a03b..c456e246 100644 --- a/Meshtastic/Views/Nodes/NodeDetail.swift +++ b/Meshtastic/Views/Nodes/NodeDetail.swift @@ -52,8 +52,10 @@ struct NodeDetail: View { presentingWaypointForm = true } }, positions: annotations, waypoints: Array(waypoints), mapViewType: mapType, + centerOnPositionsOnly: true, customMapOverlay: self.customMapOverlay, overlays: self.overlays + ) VStack { Spacer() diff --git a/Meshtastic/Views/Nodes/NodeMap.swift b/Meshtastic/Views/Nodes/NodeMap.swift index 30aede82..efe976f1 100644 --- a/Meshtastic/Views/Nodes/NodeMap.swift +++ b/Meshtastic/Views/Nodes/NodeMap.swift @@ -33,6 +33,10 @@ struct NodeMap: View { predicate: NSPredicate(format: "time >= %@", Calendar.current.startOfDay(for: Date()) as NSDate), animation: .easeIn) private var positions: FetchedResults + //@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "name", ascending: false)], + // predicate: NSPredicate(format: "expire >= %@", Calendar.current.startOfDay(for: Date()) as NSDate), animation: .easeIn) + //private var waypoints: FetchedResults + @FetchRequest(sortDescriptors: [NSSortDescriptor(key: "name", ascending: false)], animation: .easeIn) private var waypoints: FetchedResults @@ -58,8 +62,8 @@ struct NodeMap: View { } else { presentingWaypointForm = true } - }, positions: Array(positions), waypoints: Array(waypoints), mapViewType: mapType, + centerOnPositionsOnly: false, customMapOverlay: self.customMapOverlay, overlays: self.overlays )