mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Edit waypoint round 2
This commit is contained in:
parent
9a7c40e7a8
commit
33d843937e
6 changed files with 52 additions and 20 deletions
|
|
@ -735,7 +735,6 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
|
|||
var meshPacket = MeshPacket()
|
||||
meshPacket.to = emptyNodeNum
|
||||
meshPacket.from = fromNodeNum
|
||||
meshPacket.id = waypointPacket.id
|
||||
meshPacket.wantAck = true
|
||||
var dataMessage = DataMessage()
|
||||
dataMessage.payload = try! waypointPacket.serializedData()
|
||||
|
|
@ -753,6 +752,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
|
|||
success = true
|
||||
|
||||
let wayPointEntity = getWaypoint(id: Int64(waypoint.id), context: context!)
|
||||
wayPointEntity.id = Int64(waypoint.id)
|
||||
wayPointEntity.name = waypoint.name.count >= 1 ? waypointPacket.name : "Dropped Pin"
|
||||
wayPointEntity.longDescription = waypoint.description_p
|
||||
wayPointEntity.icon = Int64(waypoint.icon)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public func getWaypoint(id: Int64, context: NSManagedObjectContext) -> WaypointE
|
|||
return fetchedWaypoint[0]
|
||||
}
|
||||
} catch {
|
||||
return WaypointEntity()
|
||||
return WaypointEntity(context: context)
|
||||
}
|
||||
return WaypointEntity()
|
||||
return WaypointEntity(context: context)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import MapKit
|
|||
|
||||
struct MapViewSwiftUI: UIViewRepresentable {
|
||||
|
||||
var onMarkerTap: (_ waypointCoordinate: CLLocationCoordinate2D?, _ tag: Int? ) -> Void
|
||||
var onLongPress: (_ waypointCoordinate: CLLocationCoordinate2D?, _ tag: Int ) -> Void
|
||||
var onWaypointEdit: (_ waypointId: Int ) -> Void
|
||||
let mapView = MKMapView()
|
||||
let positions: [PositionEntity]
|
||||
let waypoints: [WaypointEntity]
|
||||
|
|
@ -124,6 +125,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
case let waypointAnnotation as WaypointEntity:
|
||||
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "waypoint") as? MKMarkerAnnotationView ?? MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "Waypoint")
|
||||
annotationView.tag = Int(waypointAnnotation.id)
|
||||
annotationView.isEnabled = true
|
||||
annotationView.canShowCallout = true
|
||||
if waypointAnnotation.icon == 0 {
|
||||
annotationView.glyphText = "📍"
|
||||
|
|
@ -133,29 +135,42 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
annotationView.clusteringIdentifier = "waypointGroup"
|
||||
annotationView.markerTintColor = UIColor(.indigo)
|
||||
annotationView.titleVisibility = .visible
|
||||
let editWaypoint = UIButton(type: .detailDisclosure)
|
||||
editWaypoint.setImage(UIImage(systemName: "square.and.pencil"), for: .normal)
|
||||
annotationView.rightCalloutAccessoryView = editWaypoint
|
||||
return annotationView
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
|
||||
{
|
||||
// Only Allow Edit for annotations with a tag
|
||||
if view.tag > 0 {
|
||||
// Screen Position - CGPoint
|
||||
let location = longPressRecognizer.location(in: self.parent.mapView)
|
||||
// Map Coordinate - CLLocationCoordinate2D
|
||||
let coordinate = self.parent.mapView.convert(location, toCoordinateFrom: self.parent.mapView)
|
||||
parent.onMarkerTap(coordinate, view.tag)
|
||||
}
|
||||
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
|
||||
let control = view.annotation as! WaypointEntity
|
||||
print(control)
|
||||
// Only Allow Edit for annotations with a id
|
||||
//if control.id > 0 {
|
||||
print(view.tag)
|
||||
parent.onWaypointEdit(view.tag)
|
||||
//}
|
||||
}
|
||||
|
||||
// func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
|
||||
// {
|
||||
// // Only Allow Edit for annotations with a tag
|
||||
// if view.tag > 0 {
|
||||
// // Screen Position - CGPoint
|
||||
// let location = longPressRecognizer.location(in: self.parent.mapView)
|
||||
// // Map Coordinate - CLLocationCoordinate2D
|
||||
// let coordinate = self.parent.mapView.convert(location, toCoordinateFrom: self.parent.mapView)
|
||||
// parent.onMarkerTap(coordinate, view.tag)
|
||||
// }
|
||||
// }
|
||||
|
||||
@objc func longPressHandler(_ gesture: UILongPressGestureRecognizer) {
|
||||
// Screen Position - CGPoint
|
||||
let location = longPressRecognizer.location(in: self.parent.mapView)
|
||||
// Map Coordinate - CLLocationCoordinate2D
|
||||
let coordinate = self.parent.mapView.convert(location, toCoordinateFrom: self.parent.mapView)
|
||||
parent.onMarkerTap(coordinate, 0)
|
||||
parent.onLongPress(coordinate, 0)
|
||||
// Add annotation:
|
||||
let annotation = MKPointAnnotation()
|
||||
annotation.title = "Dropped Pin"
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ struct WaypointFormView: View {
|
|||
@State private var description: String = ""
|
||||
@State private var icon: String = "📍"
|
||||
@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 expire: Date = Date() // = Date.now.addingTimeInterval(60 * 120) // 1 minute * 120 = 2 Hours
|
||||
@State private var locked: Bool = false
|
||||
|
||||
var body: some View {
|
||||
|
|
@ -126,6 +126,7 @@ struct WaypointFormView: View {
|
|||
var newWaypoint = Waypoint()
|
||||
|
||||
if id == 0 {
|
||||
|
||||
newWaypoint.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
|
||||
} else {
|
||||
newWaypoint.id = UInt32(id)
|
||||
|
|
@ -146,7 +147,15 @@ struct WaypointFormView: View {
|
|||
newWaypoint.expire = UInt32(expire.timeIntervalSince1970)
|
||||
}
|
||||
if bleManager.sendWaypoint(waypoint: newWaypoint) {
|
||||
id = 0
|
||||
name = ""
|
||||
description = ""
|
||||
locked = false
|
||||
expires = false
|
||||
expire = Date.now.addingTimeInterval(60 * 120)
|
||||
icon = "📍"
|
||||
dismiss()
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,12 +48,16 @@ struct NodeDetail: View {
|
|||
ZStack {
|
||||
let annotations = node.positions?.array as! [PositionEntity]
|
||||
ZStack {
|
||||
MapViewSwiftUI(onMarkerTap: { coord, id in
|
||||
MapViewSwiftUI(onLongPress: { coord, id in
|
||||
waypointCoordinate = coord
|
||||
editingWaypoint = id ?? 0
|
||||
|
||||
if waypointCoordinate != nil {
|
||||
presentingWaypointForm = true
|
||||
}
|
||||
}, onWaypointEdit: { wpId in
|
||||
editingWaypoint = wpId
|
||||
presentingWaypointForm = true
|
||||
|
||||
}, positions: annotations, waypoints: Array(waypoints), mapViewType: mapType,
|
||||
centerOnPositionsOnly: true,
|
||||
customMapOverlay: self.customMapOverlay,
|
||||
|
|
|
|||
|
|
@ -55,14 +55,18 @@ struct NodeMap: View {
|
|||
NavigationStack {
|
||||
ZStack {
|
||||
|
||||
MapViewSwiftUI(onMarkerTap: { coord, id in
|
||||
editingWaypoint = id ?? 0
|
||||
MapViewSwiftUI(onLongPress: { coord, id in
|
||||
print(id)
|
||||
waypointCoordinate = coord
|
||||
if waypointCoordinate == nil {
|
||||
presentingWaypointForm = false
|
||||
} else {
|
||||
presentingWaypointForm = true
|
||||
}
|
||||
}, onWaypointEdit: { wpId in
|
||||
editingWaypoint = wpId
|
||||
presentingWaypointForm = true
|
||||
|
||||
}, positions: Array(positions), waypoints: Array(waypoints), mapViewType: mapType,
|
||||
centerOnPositionsOnly: false,
|
||||
customMapOverlay: self.customMapOverlay,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue