mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Added a button to change waypoint to your location
This commit is contained in:
parent
6e5c045226
commit
c09291e1b2
2 changed files with 26 additions and 10 deletions
|
|
@ -14,9 +14,6 @@ extension WaypointEntity {
|
|||
static func allWaypointssFetchRequest() -> NSFetchRequest<WaypointEntity> {
|
||||
let request: NSFetchRequest<WaypointEntity> = WaypointEntity.fetchRequest()
|
||||
request.fetchLimit = 50
|
||||
// request.fetchBatchSize = 1
|
||||
// request.returnsObjectsAsFaults = false
|
||||
// request.includesSubentities = true
|
||||
request.returnsDistinctResults = true
|
||||
request.sortDescriptors = [NSSortDescriptor(key: "name", ascending: false)]
|
||||
request.predicate = NSPredicate(format: "expire == nil || expire >= %@", Date() as NSDate)
|
||||
|
|
@ -24,7 +21,6 @@ extension WaypointEntity {
|
|||
}
|
||||
|
||||
var latitude: Double? {
|
||||
|
||||
let d = Double(latitudeI)
|
||||
if d == 0 {
|
||||
return 0
|
||||
|
|
@ -33,7 +29,6 @@ extension WaypointEntity {
|
|||
}
|
||||
|
||||
var longitude: Double? {
|
||||
|
||||
let d = Double(longitudeI)
|
||||
if d == 0 {
|
||||
return 0
|
||||
|
|
@ -46,7 +41,7 @@ extension WaypointEntity {
|
|||
let coord = CLLocationCoordinate2D(latitude: latitude!, longitude: longitude!)
|
||||
return coord
|
||||
} else {
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -60,16 +55,29 @@ extension WaypointEntity {
|
|||
}
|
||||
|
||||
extension WaypointEntity: MKAnnotation {
|
||||
public var coordinate: CLLocationCoordinate2D { waypointCoordinate ?? LocationsHandler.DefaultLocation }
|
||||
public var title: String? { name ?? "Dropped Pin" }
|
||||
@MainActor
|
||||
public var coordinate: CLLocationCoordinate2D {
|
||||
get {
|
||||
waypointCoordinate ?? LocationsHandler.currentLocation
|
||||
}
|
||||
set {
|
||||
latitudeI = Int32(newValue.latitude * 1e7)
|
||||
longitudeI = Int32(newValue.longitude * 1e7)
|
||||
}
|
||||
}
|
||||
|
||||
public var title: String? {
|
||||
name ?? "Dropped Pin"
|
||||
}
|
||||
|
||||
public var subtitle: String? {
|
||||
(longDescription ?? "") +
|
||||
String(expire != nil ? "\n⌛ Expires \(String(describing: expire?.formatted()))" : "") +
|
||||
String(locked > 0 ? "\n🔒 Locked" : "") }
|
||||
String(locked > 0 ? "\n🔒 Locked" : "")
|
||||
}
|
||||
}
|
||||
|
||||
struct WaypointCoordinate: Identifiable {
|
||||
|
||||
let id: UUID
|
||||
let coordinate: CLLocationCoordinate2D?
|
||||
let waypointId: Int64
|
||||
|
|
|
|||
|
|
@ -47,6 +47,14 @@ struct WaypointForm: View {
|
|||
.textSelection(.enabled)
|
||||
.foregroundColor(.secondary)
|
||||
.font(.caption)
|
||||
|
||||
Button {
|
||||
let currentLoc = LocationsHandler.currentLocation
|
||||
waypoint.coordinate.longitude = currentLoc.longitude
|
||||
waypoint.coordinate.latitude = currentLoc.latitude
|
||||
} label: {
|
||||
Image(systemName: "location")
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
if waypoint.coordinate.latitude != 0 && waypoint.coordinate.longitude != 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue