diff --git a/Meshtastic/Helpers/Extensions.swift b/Meshtastic/Helpers/Extensions.swift index 39a2b6af..3437086e 100644 --- a/Meshtastic/Helpers/Extensions.swift +++ b/Meshtastic/Helpers/Extensions.swift @@ -72,6 +72,23 @@ extension Int { } } +extension UIImage { + func rotate(radians: Float) -> UIImage? { + var newSize = CGRect(origin: CGPoint.zero, size: self.size).applying(CGAffineTransform(rotationAngle: CGFloat(radians))).size + newSize.width = floor(newSize.width) + newSize.height = floor(newSize.height) + UIGraphicsBeginImageContextWithOptions(newSize, false, self.scale) + let context = UIGraphicsGetCurrentContext()! + context.translateBy(x: newSize.width/2, y: newSize.height/2) + context.rotate(by: CGFloat(radians)) + self.draw(in: CGRect(x: -self.size.width/2, y: -self.size.height/2, width: self.size.width, height: self.size.height)) + let newImage = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + + return newImage + } +} + extension String { func base64urlToBase64() -> String { diff --git a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift index 7a887550..6cce2dcb 100644 --- a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift @@ -7,6 +7,10 @@ import SwiftUI import MapKit +func degreesToRadians(_ number: Double) -> Double { + return number * .pi / 180 +} + struct MapViewSwiftUI: UIViewRepresentable { var onLongPress: (_ waypointCoordinate: CLLocationCoordinate2D) -> Void @@ -116,7 +120,7 @@ struct MapViewSwiftUI: UIViewRepresentable { case _ as MKClusterAnnotation: let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "nodeGroup") as? MKMarkerAnnotationView ?? MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "NodeGroup") annotationView.markerTintColor = .brown//.systemRed - annotationView.displayPriority = .defaultLow + //annotationView.displayPriority = .defaultLow annotationView.tag = -1 return annotationView case let positionAnnotation as PositionEntity: @@ -127,19 +131,16 @@ struct MapViewSwiftUI: UIViewRepresentable { let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "node") as? MKMarkerAnnotationView ?? MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: reuseID ) annotationView.tag = -1 annotationView.canShowCallout = true - annotationView.glyphText = "📟" if latest == positionAnnotation { annotationView.markerTintColor = .systemRed annotationView.displayPriority = .required annotationView.titleVisibility = .visible - // annotationView.clusteringIdentifier = "nodeGroupLatest" } else { annotationView.markerTintColor = UIColor(.indigo) annotationView.displayPriority = .defaultHigh annotationView.titleVisibility = .adaptive - //annotationView.clusteringIdentifier = "nodeGroup" } annotationView.titleVisibility = .adaptive @@ -165,8 +166,14 @@ struct MapViewSwiftUI: UIViewRepresentable { subtitle.text! += "Speed: \(formatter.string(from: Measurement(value: Double(positionAnnotation.speed), unit: UnitSpeed.kilometersPerHour))) \n" } if pf.contains(.Heading) { + + annotationView.glyphImage = UIImage(systemName: "location.north.fill")?.rotate(radians: Float(degreesToRadians(Double(positionAnnotation.heading)))) subtitle.text! += "Heading: \(String(positionAnnotation.heading)) \n" + } else { + annotationView.glyphText = "📟" } + } else { + annotationView.glyphText = "📟" } subtitle.text! += positionAnnotation.time?.formatted() ?? "Unknown \n" subtitle.numberOfLines = 0