diff --git a/Meshtastic/Helpers/LocationsHandler.swift b/Meshtastic/Helpers/LocationsHandler.swift index fec450ff..4742914a 100644 --- a/Meshtastic/Helpers/LocationsHandler.swift +++ b/Meshtastic/Helpers/LocationsHandler.swift @@ -18,7 +18,6 @@ import CoreLocation var enableSmartPosition: Bool @Published var locationsArray: [CLLocation] - @Published var lastLocation: CLLocation @Published var isStationary = false @Published var count = 0 @Published var isRecording = false @@ -43,7 +42,6 @@ import CoreLocation private init() { self.manager = CLLocationManager() // Creating a location manager instance is safe to call here in `MainActor`. locationsArray = [CLLocation]() - lastLocation = CLLocation() enableSmartPosition = true } @@ -66,11 +64,7 @@ import CoreLocation locationAdded = addLocation(loc) //print("Added Location \(self.count): \(loc)") } else { - if !isRecording { - lastLocation = loc - } else { - locationsArray.append(loc) - } + locationsArray.append(loc) locationAdded = true } if locationAdded { @@ -105,14 +99,16 @@ import CoreLocation return false } if isRecording { - let distance = location.distance(from: lastLocation) - let gain = location.altitude - lastLocation.altitude - distanceTraveled += distance - if gain > 0 { - elevationGain += gain + if let lastLocation = locationsArray.last { + let distance = location.distance(from: lastLocation) + let gain = location.altitude - lastLocation.altitude + distanceTraveled += distance + if gain > 0 { + elevationGain += gain + } } - locationsArray.append(location) } + locationsArray.append(location) return true } @@ -120,23 +116,26 @@ import CoreLocation static var satsInView: Int { var sats = 0 - if shared.lastLocation.verticalAccuracy > 0 { - sats = 4 - if 0...5 ~= shared.lastLocation.horizontalAccuracy { - sats = 12 - } else if 6...15 ~= shared.lastLocation.horizontalAccuracy { - sats = 10 - } else if 16...30 ~= shared.lastLocation.horizontalAccuracy { - sats = 9 - } else if 31...45 ~= shared.lastLocation.horizontalAccuracy { - sats = 7 - } else if 46...60 ~= shared.lastLocation.horizontalAccuracy { - sats = 5 + if let newLocation = shared.locationsArray.last { + sats = 1 + if newLocation.verticalAccuracy > 0 { + sats = 4 + if 0...5 ~= newLocation.horizontalAccuracy { + sats = 12 + } else if 6...15 ~= newLocation.horizontalAccuracy { + sats = 10 + } else if 16...30 ~= newLocation.horizontalAccuracy { + sats = 9 + } else if 31...45 ~= newLocation.horizontalAccuracy { + sats = 7 + } else if 46...60 ~= newLocation.horizontalAccuracy { + sats = 5 + } + } else if newLocation.verticalAccuracy < 0 && 60...300 ~= newLocation.horizontalAccuracy { + sats = 3 + } else if newLocation.verticalAccuracy < 0 && newLocation.horizontalAccuracy > 300 { + sats = 2 } - } else if shared.lastLocation.verticalAccuracy < 0 && 60...300 ~= shared.lastLocation.horizontalAccuracy { - sats = 3 - } else if shared.lastLocation.verticalAccuracy < 0 && shared.lastLocation.horizontalAccuracy > 300 { - sats = 2 } return sats } diff --git a/Meshtastic/Views/Nodes/MeshMap.swift b/Meshtastic/Views/Nodes/MeshMap.swift index 3cee7eb3..249a57cd 100644 --- a/Meshtastic/Views/Nodes/MeshMap.swift +++ b/Meshtastic/Views/Nodes/MeshMap.swift @@ -71,7 +71,7 @@ struct MeshMap: View { if waypoints.count > 0 && showWaypoints { ForEach(Array(waypoints), id: \.id) { waypoint in Annotation(waypoint.name ?? "?", coordinate: waypoint.coordinate) { - ZStack { + LazyVStack { CircleText(text: String(UnicodeScalar(Int(waypoint.icon)) ?? "📍"), color: Color.orange, circleSize: 40) .onTapGesture(perform: { location in selectedWaypoint = (selectedWaypoint == waypoint ? nil : waypoint) @@ -94,7 +94,8 @@ struct MeshMap: View { /// Node color from node.num let nodeColor = UIColor(hex: UInt32(position.nodePosition?.num ?? 0)) Annotation(position.nodePosition?.user?.longName ?? "?", coordinate: position.coordinate) { - ZStack { + LazyVStack { + //ZStack { let nodeColor = UIColor(hex: UInt32(position.nodePosition?.num ?? 0)) if position.nodePosition?.isOnline ?? false { Circle() @@ -178,32 +179,32 @@ struct MeshMap: View { /// Node History ForEach(Array(position.nodePosition!.positions!) as! [PositionEntity], id: \.self) { (mappin: PositionEntity) in if showNodeHistory { - if mappin.latest == false && mappin.nodePosition?.user?.vip ?? false { - let pf = PositionFlags(rawValue: Int(mappin.nodePosition?.metadata?.positionFlags ?? 771)) - let headingDegrees = Angle.degrees(Double(mappin.heading)) - Annotation("", coordinate: mappin.coordinate) { - ZStack { - if pf.contains(.Heading) { - Image(systemName: "location.north.circle") - .resizable() - .scaledToFit() - .foregroundStyle(Color(UIColor(hex: UInt32(mappin.nodePosition?.num ?? 0))).isLight() ? .black : .white) - .background(Color(UIColor(hex: UInt32(mappin.nodePosition?.num ?? 0)))) - .clipShape(Circle()) - .rotationEffect(headingDegrees) - .frame(width: 16, height: 16) - - } else { - Circle() - .fill(Color(UIColor(hex: UInt32(mappin.nodePosition?.num ?? 0)))) - .strokeBorder(Color(UIColor(hex: UInt32(mappin.nodePosition?.num ?? 0))).isLight() ? .black : .white ,lineWidth: 2) - .frame(width: 12, height: 12) + if mappin.latest == false && mappin.nodePosition?.user?.vip ?? false { + let pf = PositionFlags(rawValue: Int(mappin.nodePosition?.metadata?.positionFlags ?? 771)) + let headingDegrees = Angle.degrees(Double(mappin.heading)) + Annotation("", coordinate: mappin.coordinate) { + ZStack { + if pf.contains(.Heading) { + Image(systemName: "location.north.circle") + .resizable() + .scaledToFit() + .foregroundStyle(Color(UIColor(hex: UInt32(mappin.nodePosition?.num ?? 0))).isLight() ? .black : .white) + .background(Color(UIColor(hex: UInt32(mappin.nodePosition?.num ?? 0)))) + .clipShape(Circle()) + .rotationEffect(headingDegrees) + .frame(width: 16, height: 16) + + } else { + Circle() + .fill(Color(UIColor(hex: UInt32(mappin.nodePosition?.num ?? 0)))) + .strokeBorder(Color(UIColor(hex: UInt32(mappin.nodePosition?.num ?? 0))).isLight() ? .black : .white ,lineWidth: 2) + .frame(width: 12, height: 12) + } } } + .annotationTitles(.hidden) + .annotationSubtitles(.hidden) } - .annotationTitles(.hidden) - .annotationSubtitles(.hidden) - } } } } @@ -276,7 +277,7 @@ struct MeshMap: View { return } showWaypoints = true - position = .camera(MapCamera(centerCoordinate: waypoint.coordinate, distance: 300, heading: 0, pitch: 60)) + position = .camera(MapCamera(centerCoordinate: waypoint.coordinate, distance: 1000, heading: 0, pitch: 60)) } } .onChange(of: (selectedMapLayer)) { newMapLayer in