Assorted waypoint updates

This commit is contained in:
Garth Vander Houwen 2023-01-14 11:26:32 -08:00
parent 7450df4bcc
commit f1d70a4103
5 changed files with 18 additions and 14 deletions

View file

@ -1314,7 +1314,7 @@ func textMessageAppPacket(packet: MeshPacket, connectedNode: Int64, context: NSM
func waypointPacket (packet: MeshPacket, context: NSManagedObjectContext) {
let logString = String.localizedStringWithFormat(NSLocalizedString("mesh.log.waypoint.received %@", comment: "Waypoint Packet received from node: %@"), String(packet.from))
let logString = String.localizedStringWithFormat(NSLocalizedString("mesh.log.waypoint.received %@", comment: "Waypoint Packet received from node: %@"), String(packet.from))
MeshLogger.log("📍 \(logString)")
let fetchWaypointRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "WaypointEntity")
@ -1329,12 +1329,12 @@ func waypointPacket (packet: MeshPacket, context: NSManagedObjectContext) {
if fetchedWaypoint.isEmpty {
let waypoint = WaypointEntity(context: context)
waypoint.id = Int64(UInt32.random(in: UInt32(UInt8.max)..<UInt32.max))//Int64(packet.id)
waypoint.id = Int64(packet.id)
waypoint.name = waypointMessage.name
waypoint.longDescription = waypointMessage.description_p
waypoint.latitudeI = waypointMessage.latitudeI
waypoint.longitudeI = waypointMessage.longitudeI
//waypoint.icon = Int32(waypointMessage.icon)
waypoint.icon = Int32(waypointMessage.icon)
waypoint.locked = waypointMessage.locked
if waypointMessage.expire != 0 {
waypoint.expire = Date(timeIntervalSince1970: TimeInterval(Int64(waypointMessage.expire)))
@ -1353,7 +1353,7 @@ func waypointPacket (packet: MeshPacket, context: NSManagedObjectContext) {
fetchedWaypoint[0].longDescription = waypointMessage.description_p
fetchedWaypoint[0].latitudeI = waypointMessage.latitudeI
fetchedWaypoint[0].longitudeI = waypointMessage.longitudeI
//fetchedWaypoint[0].icon = Int32(waypointMessage.icon)
fetchedWaypoint[0].icon = Int32(waypointMessage.icon)
fetchedWaypoint[0].locked = waypointMessage.locked
if waypointMessage.expire != 0 {
fetchedWaypoint[0].expire = Date(timeIntervalSince1970: TimeInterval(Int64(waypointMessage.expire)))

View file

@ -275,6 +275,6 @@
<attribute name="locked" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="longDescription" optional="YES" attributeType="String" maxValueString="100"/>
<attribute name="longitudeI" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="name" optional="YES" attributeType="String" maxValueString="30"/>
<attribute name="name" attributeType="String" minValueString="1" maxValueString="30"/>
</entity>
</model>

View file

@ -49,6 +49,6 @@ extension WaypointEntity {
extension WaypointEntity: MKAnnotation {
public var coordinate: CLLocationCoordinate2D { waypointCoordinate ?? LocationHelper.DefaultLocation }
public var title: String? { self.title ?? "" }
public var subtitle: String? { self.description }
public var title: String? { name ?? "Dropped Pin" }
public var subtitle: String? { longDescription }
}

View file

@ -29,6 +29,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
// Parameters
mapView.addAnnotations(positions)
mapView.addAnnotations(waypoints)
mapView.mapType = mapViewType
mapView.setRegion(region, animated: true)
mapView.setUserTrackingMode(.none, animated: false)
@ -159,7 +160,11 @@ struct MapViewSwiftUI: UIViewRepresentable {
case let waypointAnnotation as WaypointEntity:
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "waypoint") as? MKMarkerAnnotationView ?? MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "Waypoint")
annotationView.canShowCallout = true
annotationView.glyphText = "🪧"
if waypointAnnotation.icon == 0 {
annotationView.glyphText = "🪧"
} else {
}
annotationView.clusteringIdentifier = "waypointGroup"
annotationView.markerTintColor = UIColor(.green)
annotationView.titleVisibility = .visible

View file

@ -17,7 +17,7 @@ struct WaypointFormView: View {
@State private var id: Int32?
@State private var name: String = ""
@State private var description: String = ""
@State private var icon: String = "📍"
@State private var icon: String = "🪧"
@State private var expires: Bool = false
@State private var expire: Date = Date()// = Date.now.addingTimeInterval(60 * 120) // 1 minute * 120 = 2 Hours
@State private var locked: Bool = false
@ -125,6 +125,9 @@ struct WaypointFormView: View {
newWaypoint.description_p = description
newWaypoint.latitudeI = Int32(coordinate.latitude * 1e7)
newWaypoint.longitudeI = Int32(coordinate.longitude * 1e7)
let uni = icon.unicodeScalars // Unicode scalar values of the string
let unicode = uni[uni.startIndex].value // First element as an UInt32
newWaypoint.icon = unicode
//newWaypoint.icon = icon
newWaypoint.locked = locked
//newWaypoint.expire = expire
@ -132,7 +135,7 @@ struct WaypointFormView: View {
dismiss()
} label: {
Label("save", systemImage: "square.and.arrow.down")
Label("Send", systemImage: "arrow.up")
}
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
@ -151,7 +154,3 @@ struct WaypointFormView: View {
}
}
}
//var smiley = "😊"
//var data: NSData = smiley.dataUsingEncoding(NSUTF32LittleEndianStringEncoding, allowLossyConversion: false)!
//var unicode:UInt32 = UInt32()
//data.getBytes(&unicode)