Waypoints on the mesh map

This commit is contained in:
Garth Vander Houwen 2023-11-14 18:11:25 -08:00
parent 78563947b2
commit e164a2b624
4 changed files with 43 additions and 30 deletions

View file

@ -132,12 +132,13 @@ struct WaypointForm: View {
}
HStack {
Button {
/// Send a new or exiting waypoint
var newWaypoint = Waypoint()
// Loading a waypoint from edit
if waypoint.id == 0 {
newWaypoint.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
waypoint.id = Int64(newWaypoint.id)
} else {
newWaypoint.id = UInt32(waypoint.id)
}
newWaypoint.latitudeI = waypoint.latitudeI
newWaypoint.longitudeI = waypoint.longitudeI
@ -198,10 +199,7 @@ struct WaypointForm: View {
dismiss() })
Button("For everyone", action: {
var newWaypoint = Waypoint()
if waypoint.id > 0 {
newWaypoint.id = UInt32(waypoint.id)
}
newWaypoint.id = UInt32(waypoint.id)
newWaypoint.name = name.count > 0 ? name : "Dropped Pin"
newWaypoint.description_p = description
newWaypoint.latitudeI = waypoint.longitudeI
@ -218,9 +216,16 @@ struct WaypointForm: View {
newWaypoint.lockedTo = UInt32(lockedTo)
}
}
newWaypoint.expire = 1
newWaypoint.expire = UInt32(expire.timeIntervalSince1970)
if bleManager.sendWaypoint(waypoint: newWaypoint) {
dismiss()
bleManager.context!.delete(waypoint)
do {
try bleManager.context!.save()
} catch {
bleManager.context!.rollback()
}
dismiss()
} else {
dismiss()
print("Send waypoint failed")

View file

@ -9,6 +9,8 @@ import SwiftUI
import MapKit
struct PositionPopover: View {
@Environment(\.managedObjectContext) var context
@EnvironmentObject var bleManager: BLEManager
@Environment(\.dismiss) private var dismiss
var position: PositionEntity
var popover: Bool = true
@ -17,10 +19,9 @@ struct PositionPopover: View {
VStack {
HStack {
CircleText(text: position.nodePosition?.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(position.nodePosition?.user?.num ?? 0))), circleSize: 65)
Spacer()
.padding(.trailing, 5)
Text(position.nodePosition?.user?.longName ?? "Unknown")
.font(.largeTitle)
Spacer()
}
Divider()
HStack (alignment: .center) {
@ -128,9 +129,10 @@ struct PositionPopover: View {
if position.nodePosition != nil {
if position.nodePosition?.user?.vip ?? false {
Image(systemName: "star.fill")
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
.font(.largeTitle)
.padding(.bottom)
.padding(.bottom, 5)
}
if position.nodePosition?.hasEnvironmentMetrics ?? false {
Image(systemName: "cloud.sun.rain")

View file

@ -24,7 +24,14 @@ struct WaypointPopover: View {
Image(systemName: "lock.fill" )
.font(.largeTitle)
} else {
// Edit Button
Button {
dismiss()
} label: {
Image(systemName: "square.and.pencil" )
.font(.largeTitle)
.symbolRenderingMode(.hierarchical)
.foregroundColor(.accentColor)
}
}
}
Divider()

View file

@ -8,6 +8,7 @@
import SwiftUI
import CoreData
import CoreLocation
import Foundation
#if canImport(MapKit)
import MapKit
#endif
@ -18,6 +19,8 @@ struct MeshMap: View {
@Environment(\.managedObjectContext) var context
@EnvironmentObject var bleManager: BLEManager
@StateObject var appState = AppState.shared
@GestureState var isDetectingLongGesture = false
/// Parameters
@State var showUserLocation: Bool = true
/// Map State User Defaults
@ -62,6 +65,7 @@ struct MeshMap: View {
NavigationStack {
ZStack {
MapReader { reader in
Map(position: $position, bounds: MapCameraBounds(minimumDistance: 1, maximumDistance: .infinity), scope: mapScope) {
/// Waypoint Annotations
if waypoints.count > 0 && showWaypoints {
@ -151,23 +155,17 @@ struct MeshMap: View {
}
}
}
// .gesture(LongPressGesture(minimumDuration: 0.5).sequenced(before: DragGesture(minimumDistance: 0, coordinateSpace: .local))
// .onEnded { value in
// switch value {
// case .second(true, let drag):
// /// Convert the touch point to a Coordinate
// newWaypointCoord = reader.convert(drag?.location ?? .zero, from: .local)
// /// Create a new WaypointEntity using the values from the newWaypoint which will trigger the WaypointForm sheet
// editingWaypoint = WaypointEntity(context: context)
// editingWaypoint!.name = "Waypoint Pin"
// editingWaypoint!.expire = Date.now.addingTimeInterval(60 * 480)
// editingWaypoint!.latitudeI = Int32((newWaypointCoord?.latitude ?? 0) * 1e7)
// editingWaypoint!.longitudeI = Int32((newWaypointCoord?.longitude ?? 0) * 1e7)
// editingWaypoint!.id = 0
// default:
// break
// }
// })
.onTapGesture(perform: { location in
newWaypointCoord = reader.convert(location , from: .local)
})
.onLongPressGesture(minimumDuration: 0.5, maximumDistance: 10) {
editingWaypoint = WaypointEntity(context: context)
editingWaypoint!.name = "Waypoint Pin"
editingWaypoint!.expire = Date.now.addingTimeInterval(60 * 480)
editingWaypoint!.latitudeI = Int32((newWaypointCoord?.latitude ?? 0) * 1e7)
editingWaypoint!.longitudeI = Int32((newWaypointCoord?.longitude ?? 0) * 1e7)
editingWaypoint!.id = 0
}
}
}
.mapScope(mapScope)
@ -190,7 +188,8 @@ struct MeshMap: View {
.padding()
}
.sheet(item: $selectedWaypoint) { selection in
WaypointPopover(waypoint: selection)
//WaypointPopover(waypoint: selection)
WaypointForm(waypoint: selection)
.padding()
}
.sheet(item: $editingWaypoint) { selection in