* Map pin clustering cleanup

* Show icon direction in pins with available heading
This commit is contained in:
Garth Vander Houwen 2023-02-19 09:57:43 -08:00
parent 91ce572acc
commit 434ed20ff2
2 changed files with 28 additions and 4 deletions

View file

@ -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 {

View file

@ -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