mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Switch to new locations handler
This commit is contained in:
parent
ea8d06480b
commit
88e7c92f89
9 changed files with 28 additions and 20 deletions
|
|
@ -13,7 +13,7 @@ import SwiftUI
|
|||
|
||||
extension PositionEntity {
|
||||
|
||||
static func allPositionsFetchRequest() -> NSFetchRequest<PositionEntity> {
|
||||
@MainActor static func allPositionsFetchRequest() -> NSFetchRequest<PositionEntity> {
|
||||
let request: NSFetchRequest<PositionEntity> = PositionEntity.fetchRequest()
|
||||
request.fetchLimit = 1000
|
||||
request.returnsObjectsAsFaults = false
|
||||
|
|
@ -22,9 +22,9 @@ extension PositionEntity {
|
|||
request.sortDescriptors = [NSSortDescriptor(key: "time", ascending: false)]
|
||||
let positionPredicate = NSPredicate(format: "nodePosition != nil && (nodePosition.user.shortName != nil || nodePosition.user.shortName != '') && latest == true")
|
||||
|
||||
let pointOfInterest = LocationHelper.currentLocation
|
||||
let pointOfInterest = LocationsHandler.currentLocation
|
||||
|
||||
if pointOfInterest.latitude != LocationHelper.DefaultLocation.latitude && pointOfInterest.longitude != LocationHelper.DefaultLocation.longitude {
|
||||
if pointOfInterest.latitude != LocationsHandler.DefaultLocation.latitude && pointOfInterest.longitude != LocationsHandler.DefaultLocation.longitude {
|
||||
let d: Double = UserDefaults.meshMapDistance * 1.1
|
||||
let r: Double = 6371009
|
||||
let meanLatitidue = pointOfInterest.latitude * .pi / 180
|
||||
|
|
@ -88,7 +88,7 @@ extension PositionEntity {
|
|||
}
|
||||
|
||||
extension PositionEntity: MKAnnotation {
|
||||
public var coordinate: CLLocationCoordinate2D { nodeCoordinate ?? LocationHelper.DefaultLocation }
|
||||
public var coordinate: CLLocationCoordinate2D { nodeCoordinate ?? LocationsHandler.DefaultLocation }
|
||||
public var title: String? { nodePosition?.user?.shortName ?? "unknown".localized }
|
||||
public var subtitle: String? { time?.formatted() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ extension WaypointEntity {
|
|||
}
|
||||
|
||||
extension WaypointEntity: MKAnnotation {
|
||||
public var coordinate: CLLocationCoordinate2D { waypointCoordinate ?? LocationHelper.DefaultLocation }
|
||||
public var coordinate: CLLocationCoordinate2D { waypointCoordinate ?? LocationsHandler.DefaultLocation }
|
||||
public var title: String? { name ?? "Dropped Pin" }
|
||||
public var subtitle: String? {
|
||||
(longDescription ?? "") +
|
||||
|
|
|
|||
|
|
@ -113,6 +113,12 @@ import OSLog
|
|||
}
|
||||
|
||||
static let DefaultLocation = CLLocationCoordinate2D(latitude: 37.3346, longitude: -122.0090)
|
||||
static var currentLocation: CLLocationCoordinate2D {
|
||||
guard let location = shared.manager.location else {
|
||||
return DefaultLocation
|
||||
}
|
||||
return location.coordinate
|
||||
}
|
||||
|
||||
static var satsInView: Int {
|
||||
var sats = 0
|
||||
|
|
@ -139,4 +145,6 @@ import OSLog
|
|||
}
|
||||
return sats
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ struct NodeWeatherForecast {
|
|||
|
||||
struct NodeWeatherForecastView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NodeWeatherForecastView(location: CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude) )
|
||||
NodeWeatherForecastView(location: CLLocation(latitude: LocationsHandler.currentLocation.latitude, longitude: LocationsHandler.currentLocation.longitude) )
|
||||
.aspectRatio(2, contentMode: .fit)
|
||||
.padding()
|
||||
.previewLayout(.sizeThatFits)
|
||||
|
|
|
|||
|
|
@ -346,9 +346,9 @@ struct UserList: View {
|
|||
}
|
||||
/// Distance
|
||||
if distanceFilter {
|
||||
let pointOfInterest = LocationHelper.currentLocation
|
||||
let pointOfInterest = LocationsHandler.currentLocation
|
||||
|
||||
if pointOfInterest.latitude != LocationHelper.DefaultLocation.latitude && pointOfInterest.longitude != LocationHelper.DefaultLocation.longitude {
|
||||
if pointOfInterest.latitude != LocationsHandler.DefaultLocation.latitude && pointOfInterest.longitude != LocationsHandler.DefaultLocation.longitude {
|
||||
let d: Double = maxDistance * 1.1
|
||||
let r: Double = 6371009
|
||||
let meanLatitidue = pointOfInterest.latitude * .pi / 180
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ struct MeshMapContent: MapContent {
|
|||
let nodePositions = Array(positions) as? [PositionEntity] {
|
||||
if showRouteLines {
|
||||
let routeCoords = nodePositions.compactMap({(pos) -> CLLocationCoordinate2D in
|
||||
return pos.nodeCoordinate ?? LocationHelper.DefaultLocation
|
||||
return pos.nodeCoordinate ?? LocationsHandler.DefaultLocation
|
||||
})
|
||||
let gradient = LinearGradient(
|
||||
colors: [Color(nodeColor.lighter().lighter()), Color(nodeColor.lighter()), Color(nodeColor)],
|
||||
|
|
@ -148,9 +148,9 @@ struct MeshMapContent: MapContent {
|
|||
ForEach(routes) { route in
|
||||
if let routeLocations = route.locations, let locations = Array(routeLocations) as? [LocationEntity] {
|
||||
let routeCoords = locations.compactMap {(loc) -> CLLocationCoordinate2D in
|
||||
return loc.locationCoordinate ?? LocationHelper.DefaultLocation
|
||||
return loc.locationCoordinate ?? LocationsHandler.DefaultLocation
|
||||
}
|
||||
Annotation("Start", coordinate: routeCoords.first ?? LocationHelper.DefaultLocation) {
|
||||
Annotation("Start", coordinate: routeCoords.first ?? LocationsHandler.DefaultLocation) {
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(Color(.green))
|
||||
|
|
@ -159,7 +159,7 @@ struct MeshMapContent: MapContent {
|
|||
}
|
||||
}
|
||||
.annotationTitles(.automatic)
|
||||
Annotation("Finish", coordinate: routeCoords.last ?? LocationHelper.DefaultLocation) {
|
||||
Annotation("Finish", coordinate: routeCoords.last ?? LocationsHandler.DefaultLocation) {
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(Color(.black))
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ struct WaypointForm: View {
|
|||
.font(.largeTitle)
|
||||
Divider()
|
||||
Form {
|
||||
let distance = CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude).distance(from: CLLocation(latitude: waypoint.coordinate.latitude, longitude: waypoint.coordinate.longitude ))
|
||||
let distance = CLLocation(latitude: LocationsHandler.currentLocation.latitude, longitude: LocationsHandler.currentLocation.longitude).distance(from: CLLocation(latitude: waypoint.coordinate.latitude, longitude: waypoint.coordinate.longitude ))
|
||||
Section(header: Text("Coordinate") ) {
|
||||
HStack {
|
||||
Text("Location:")
|
||||
|
|
@ -335,8 +335,8 @@ struct WaypointForm: View {
|
|||
.padding(.bottom, 5)
|
||||
}
|
||||
/// Distance
|
||||
if LocationHelper.currentLocation.distance(from: LocationHelper.DefaultLocation) > 0.0 {
|
||||
let metersAway = waypoint.coordinate.distance(from: LocationHelper.currentLocation)
|
||||
if LocationsHandler.currentLocation.distance(from: LocationsHandler.DefaultLocation) > 0.0 {
|
||||
let metersAway = waypoint.coordinate.distance(from: LocationsHandler.currentLocation)
|
||||
Label {
|
||||
Text("distance".localized + ": \(distanceFormatter.string(fromDistance: Double(metersAway)))")
|
||||
.foregroundColor(.primary)
|
||||
|
|
|
|||
|
|
@ -418,9 +418,9 @@ struct NodeList: View {
|
|||
}
|
||||
/// Distance
|
||||
if distanceFilter {
|
||||
let pointOfInterest = LocationHelper.currentLocation
|
||||
let pointOfInterest = LocationsHandler.currentLocation
|
||||
|
||||
if pointOfInterest.latitude != LocationHelper.DefaultLocation.latitude && pointOfInterest.longitude != LocationHelper.DefaultLocation.longitude {
|
||||
if pointOfInterest.latitude != LocationsHandler.DefaultLocation.latitude && pointOfInterest.longitude != LocationsHandler.DefaultLocation.longitude {
|
||||
let d: Double = maxDistance * 1.1
|
||||
let r: Double = 6371009
|
||||
let meanLatitidue = pointOfInterest.latitude * .pi / 180
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ struct Routes: View {
|
|||
if selectedRoute != nil {
|
||||
let locationArray = selectedRoute?.locations?.array as? [LocationEntity] ?? []
|
||||
let lineCoords = locationArray.compactMap({(location) -> CLLocationCoordinate2D in
|
||||
return location.locationCoordinate ?? LocationHelper.DefaultLocation
|
||||
return location.locationCoordinate ?? LocationsHandler.DefaultLocation
|
||||
})
|
||||
Form {
|
||||
TextField(
|
||||
|
|
@ -248,7 +248,7 @@ struct Routes: View {
|
|||
hasChanges = true
|
||||
}
|
||||
Map {
|
||||
Annotation("Start", coordinate: lineCoords.first ?? LocationHelper.DefaultLocation) {
|
||||
Annotation("Start", coordinate: lineCoords.first ?? LocationsHandler.DefaultLocation) {
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(Color(.green))
|
||||
|
|
@ -257,7 +257,7 @@ struct Routes: View {
|
|||
}
|
||||
}
|
||||
.annotationTitles(.automatic)
|
||||
Annotation("Finish", coordinate: lineCoords.last ?? LocationHelper.DefaultLocation) {
|
||||
Annotation("Finish", coordinate: lineCoords.last ?? LocationsHandler.DefaultLocation) {
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(Color(.black))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue