diff --git a/Meshtastic/Views/Map/WaypointFormView.swift b/Meshtastic/Views/Map/WaypointFormView.swift index 3b0f72fd..0419207e 100644 --- a/Meshtastic/Views/Map/WaypointFormView.swift +++ b/Meshtastic/Views/Map/WaypointFormView.swift @@ -13,13 +13,15 @@ struct WaypointFormView: View { @EnvironmentObject var bleManager: BLEManager @Environment(\.dismiss) private var dismiss @State var coordinate: CLLocationCoordinate2D - @State var id: Int = 0 + @State var waypointId : Int = 0 @FocusState private var iconIsFocused: Bool @State private var name: String = "" @State private var description: String = "" @State private var icon: String = "📍" + @State private var latitude: Double = 0 + @State private var longitude: Double = 0 @State private var expires: Bool = false @State private var expire: Date = Date() // = Date.now.addingTimeInterval(60 * 120) // 1 minute * 120 = 2 Hours @State private var locked: Bool = false @@ -27,9 +29,9 @@ struct WaypointFormView: View { var body: some View { Form { let distance = CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude).distance(from: CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)) - Section(header: Text((id > 0) ? "Editing Waypoint" : "Create Waypoint")) { + Section(header: Text((waypointId > 0) ? "Editing Waypoint" : "Create Waypoint")) { HStack { - Text("Location: \(String(format: "%.5f", coordinate.latitude ) + "," + String(format: "%.5f", coordinate.longitude ))") + Text("Location: \(String(format: "%.5f", latitude) + "," + String(format: "%.5f", longitude))") .textSelection(.enabled) .foregroundColor(Color.gray) .font(.caption2) @@ -125,11 +127,10 @@ struct WaypointFormView: View { var newWaypoint = Waypoint() - if id == 0 { - - newWaypoint.id = UInt32.random(in: UInt32(UInt8.max).. 0 { + newWaypoint.id = UInt32(waypointId) } else { - newWaypoint.id = UInt32(id) + newWaypoint.id = UInt32.random(in: UInt32(UInt8.max).. 0 { - let waypoint = getWaypoint(id: Int64(id), context: bleManager.context!) - id = Int(waypoint.id) + if waypointId > 0 { + let waypoint = getWaypoint(id: Int64(waypointId), context: bleManager.context!) + waypointId = Int(waypoint.id) name = waypoint.name ?? "Dropped Pin" description = waypoint.longDescription ?? "" icon = String(UnicodeScalar(Int(waypoint.icon)) ?? "📍") + latitude = Double(waypoint.latitudeI) / 1e7 + longitude = Double(waypoint.longitudeI) / 1e7 if waypoint.expire != nil { expires = true expire = waypoint.expire ?? Date() } else { expires = false } + } else { + latitude = coordinate.latitude + longitude = coordinate.longitude } } } diff --git a/Meshtastic/Views/Nodes/NodeDetail.swift b/Meshtastic/Views/Nodes/NodeDetail.swift index 1849a136..78c6d78f 100644 --- a/Meshtastic/Views/Nodes/NodeDetail.swift +++ b/Meshtastic/Views/Nodes/NodeDetail.swift @@ -55,9 +55,10 @@ struct NodeDetail: View { presentingWaypointForm = true } }, onWaypointEdit: { wpId in - editingWaypoint = wpId - presentingWaypointForm = true - + if wpId > 0 { + editingWaypoint = wpId + presentingWaypointForm = true + } }, positions: annotations, waypoints: Array(waypoints), mapViewType: mapType, centerOnPositionsOnly: true, customMapOverlay: self.customMapOverlay, @@ -389,7 +390,7 @@ struct NodeDetail: View { } .edgesIgnoringSafeArea([.leading, .trailing]) .sheet(isPresented: $presentingWaypointForm ) {//, onDismiss: didDismissSheet) { - WaypointFormView(coordinate: waypointCoordinate ?? LocationHelper.DefaultLocation, id: editingWaypoint) + WaypointFormView(coordinate: waypointCoordinate ?? LocationHelper.DefaultLocation, waypointId: editingWaypoint) .presentationDetents([.medium, .large]) .presentationDragIndicator(.automatic) } diff --git a/Meshtastic/Views/Nodes/NodeMap.swift b/Meshtastic/Views/Nodes/NodeMap.swift index 7a6c7ef7..8952f3f5 100644 --- a/Meshtastic/Views/Nodes/NodeMap.swift +++ b/Meshtastic/Views/Nodes/NodeMap.swift @@ -86,7 +86,7 @@ struct NodeMap: View { .frame(maxHeight: .infinity) .sheet(isPresented: $presentingWaypointForm ) {//, onDismiss: didDismissSheet) { if waypointCoordinate != nil { - WaypointFormView(coordinate: waypointCoordinate!, id: editingWaypoint) + WaypointFormView(coordinate: waypointCoordinate!, waypointId: editingWaypoint) .presentationDetents([.medium, .large]) .presentationDragIndicator(.automatic) }