Center the node detail map on positions, node map on both positions and waypoints

This commit is contained in:
Garth Vander Houwen 2023-01-15 12:47:42 -08:00
parent 3d1111972c
commit f59b4a8a86
3 changed files with 14 additions and 2 deletions

View file

@ -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

View file

@ -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()

View file

@ -33,6 +33,10 @@ struct NodeMap: View {
predicate: NSPredicate(format: "time >= %@", Calendar.current.startOfDay(for: Date()) as NSDate), animation: .easeIn)
private var positions: FetchedResults<PositionEntity>
//@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "name", ascending: false)],
// predicate: NSPredicate(format: "expire >= %@", Calendar.current.startOfDay(for: Date()) as NSDate), animation: .easeIn)
//private var waypoints: FetchedResults<WaypointEntity>
@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "name", ascending: false)], animation: .easeIn)
private var waypoints: FetchedResults<WaypointEntity>
@ -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
)