mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Default to hybridFlyover Use short name for node annotation title, add long name to annotation detail Add map settings section to app settings
57 lines
1.2 KiB
Swift
57 lines
1.2 KiB
Swift
import CoreData
|
|
import CoreLocation
|
|
import MapKit
|
|
import SwiftUI
|
|
|
|
extension PositionEntity {
|
|
|
|
var latitude: Double? {
|
|
|
|
let d = Double(latitudeI)
|
|
if d == 0 {
|
|
return 0
|
|
}
|
|
return d / 1e7
|
|
}
|
|
|
|
var longitude: Double? {
|
|
|
|
let d = Double(longitudeI)
|
|
if d == 0 {
|
|
return 0
|
|
}
|
|
return d / 1e7
|
|
}
|
|
|
|
var nodeCoordinate: CLLocationCoordinate2D? {
|
|
if latitudeI != 0 && longitudeI != 0 {
|
|
let coord = CLLocationCoordinate2D(latitude: latitude!, longitude: longitude!)
|
|
return coord
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
var nodeLocation: CLLocation? {
|
|
if latitudeI != 0 && longitudeI != 0 {
|
|
let location = CLLocation(latitude: latitude!, longitude: longitude!)
|
|
return location
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
var annotaton: MKPointAnnotation {
|
|
let pointAnn = MKPointAnnotation()
|
|
if nodeCoordinate != nil {
|
|
pointAnn.coordinate = nodeCoordinate!
|
|
}
|
|
return pointAnn
|
|
}
|
|
}
|
|
|
|
extension PositionEntity: MKAnnotation {
|
|
public var coordinate: CLLocationCoordinate2D { nodeCoordinate ?? LocationHelper.DefaultLocation }
|
|
public var title: String? { nodePosition?.user?.shortName ?? NSLocalizedString("unknown", comment: "Unknown") }
|
|
public var subtitle: String? { time?.formatted() }
|
|
}
|