Additional map and location cleanup

This commit is contained in:
Garth Vander Houwen 2023-04-09 22:56:09 -07:00
parent e28a970945
commit 1abbae863c
3 changed files with 16 additions and 18 deletions

View file

@ -36,7 +36,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
var timeoutTimerCount = 0
var timeoutTimerRuns = 0
var positionTimer: Timer?
var lastPosition: CLLocationCoordinate2D?
var lastPosition: CLLocation?
let emptyNodeNum: UInt32 = 4294967295
/* Meshtastic Service Details */
var TORADIO_characteristic: CBCharacteristic!
@ -784,25 +784,26 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
if lastPosition != nil {
let connectedNode = getNodeInfo(id: connectedPeripheral?.num ?? 0, context: context!)
if connectedNode?.positionConfig?.smartPositionEnabled ?? false {
if lastPosition!.distance(from: LocationHelper.currentLocation.coordinate) < Double(connectedNode?.positionConfig?.broadcastSmartMinimumDistance ?? 50) {
if lastPosition!.distance(from: LocationHelper.currentLocation) < Double(connectedNode?.positionConfig?.broadcastSmartMinimumDistance ?? 50) {
return false
}
}
}
}
lastPosition = LocationHelper.currentLocation.coordinate
let locationHelper = LocationHelper()
lastPosition = locationHelper.lastLocation
var positionPacket = Position()
positionPacket.latitudeI = Int32(LocationHelper.currentLocation.coordinate.latitude * 1e7)
positionPacket.longitudeI = Int32(LocationHelper.currentLocation.coordinate.longitude * 1e7)
positionPacket.time = UInt32(LocationHelper.currentLocation.timestamp.timeIntervalSince1970)
positionPacket.timestamp = UInt32(LocationHelper.currentLocation.timestamp.timeIntervalSince1970)
positionPacket.altitude = Int32(LocationHelper.currentLocation.altitude)
positionPacket.latitudeI = Int32(locationHelper.lastLocation?.coordinate.latitude ?? 0 * 1e7)
positionPacket.longitudeI = Int32(locationHelper.lastLocation?.coordinate.longitude ?? 0 * 1e7)
positionPacket.time = UInt32(locationHelper.lastLocation?.timestamp.timeIntervalSince1970 ?? 0)
positionPacket.timestamp = UInt32(locationHelper.lastLocation?.timestamp.timeIntervalSince1970 ?? 0)
positionPacket.altitude = Int32(locationHelper.lastLocation?.altitude ?? 0)
positionPacket.satsInView = UInt32(LocationHelper.satsInView)
if LocationHelper.currentLocation.speed >= 0 {
positionPacket.groundSpeed = UInt32(LocationHelper.currentLocation.speed * 3.6)
positionPacket.groundSpeed = UInt32(locationHelper.lastLocation?.speed ?? 0 * 3.6)
}
if LocationHelper.currentLocation.course >= 0 {
positionPacket.groundTrack = UInt32(LocationHelper.currentLocation.course)
positionPacket.groundTrack = UInt32(locationHelper.lastLocation?.course ?? 0)
}
var meshPacket = MeshPacket()
meshPacket.to = UInt32(destNum)

View file

@ -121,6 +121,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
.filter { $0.latest == true }
.sorted { $0.nodePosition?.num ?? 0 > $1.nodePosition?.num ?? -1 }
let annotationCount = waypoints.count + (showNodeHistory ? positions.count : latest.count)
print("Waypoint Count: \(waypoints.count)")
print("Annotation Count: \(annotationCount) Map Annotations: \(mapView.annotations.count)")
mapView.removeAnnotations(mapView.annotations)
mapView.addAnnotations(waypoints)

View file

@ -13,9 +13,7 @@ struct WaypointFormView: View {
@EnvironmentObject var bleManager: BLEManager
@Environment(\.dismiss) private var dismiss
@State var coordinate: WaypointCoordinate
@FocusState private var iconIsFocused: Bool
@State private var name: String = ""
@State private var description: String = ""
@State private var icon: String = "📍"
@ -36,7 +34,7 @@ struct WaypointFormView: View {
.textSelection(.enabled)
.foregroundColor(Color.gray)
.font(.caption2)
if coordinate.coordinate?.latitude ?? -1 != LocationHelper.DefaultLocation.coordinate.latitude && coordinate.coordinate?.longitude ?? 0 != LocationHelper.DefaultLocation.coordinate.longitude {
if coordinate.coordinate?.latitude ?? 0 != 0 && coordinate.coordinate?.longitude ?? 0 != 0 {
DistanceText(meters: distance)
.foregroundColor(Color.gray)
.font(.caption2)
@ -127,27 +125,26 @@ struct WaypointFormView: View {
Button {
var newWaypoint = Waypoint()
// Loading a waypoint from edit
if coordinate.waypointId > 0 {
newWaypoint.id = UInt32(coordinate.waypointId)
let waypoint = getWaypoint(id: Int64(coordinate.waypointId), context: bleManager.context!)
newWaypoint.latitudeI = waypoint.latitudeI
newWaypoint.longitudeI = waypoint.longitudeI
} else {
// New waypoint
newWaypoint.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
newWaypoint.latitudeI = Int32(Double(coordinate.coordinate?.latitude ?? 0) * 1e7)
newWaypoint.longitudeI = Int32(Double(coordinate.coordinate?.longitude ?? 0) * 1e7)
}
newWaypoint.name = name.count > 0 ? name : "Dropped Pin"
newWaypoint.description_p = description
// Unicode scalar value for the icon emoji string
let unicodeScalers = icon.unicodeScalars
// First element as an UInt32
let unicode = unicodeScalers[unicodeScalers.startIndex].value
newWaypoint.icon = unicode
if locked {
if lockedTo == 0 {
newWaypoint.lockedTo = UInt32(bleManager.connectedPeripheral!.num)
} else {
@ -212,7 +209,6 @@ struct WaypointFormView: View {
let unicode = unicodeScalers[unicodeScalers.startIndex].value
newWaypoint.icon = unicode
if locked {
if lockedTo == 0 {
newWaypoint.lockedTo = UInt32(bleManager.connectedPeripheral!.num)
} else {
@ -261,7 +257,7 @@ struct WaypointFormView: View {
description = ""
locked = false
expires = false
expire = Date.now.addingTimeInterval(60 * 120)
expire = Date.now.addingTimeInterval(60 * 480)
icon = "📍"
latitude = coordinate.coordinate?.latitude ?? 0
longitude = coordinate.coordinate?.longitude ?? 0