2021-12-24 20:06:21 +13:00
|
|
|
//
|
|
|
|
|
// PositionAnnotationView.swift
|
2022-06-09 22:11:54 -07:00
|
|
|
// MeshtasticApple
|
2021-12-24 20:06:21 +13:00
|
|
|
//
|
|
|
|
|
// Created by Joshua Pirihi on 24/12/21.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
import MapKit
|
2022-12-30 13:18:02 -08:00
|
|
|
import SwiftUI
|
2021-12-24 20:06:21 +13:00
|
|
|
|
2021-12-25 23:48:12 -08:00
|
|
|
// a simple circle annotation, with a string in it
|
2021-12-24 20:06:21 +13:00
|
|
|
class PositionAnnotation: NSObject, MKAnnotation {
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2021-12-24 20:06:21 +13:00
|
|
|
// This property must be key-value observable, which the `@objc dynamic` attributes provide.
|
|
|
|
|
@objc dynamic var coordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0)
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2021-12-24 20:06:21 +13:00
|
|
|
// Required if you set the annotation view's `canShowCallout` property to `true`
|
2021-12-25 23:48:12 -08:00
|
|
|
// this string fills the callout label when you tap an annotation
|
2021-12-25 14:48:01 +13:00
|
|
|
var title: String?
|
2021-12-25 23:48:12 -08:00
|
|
|
|
|
|
|
|
// the text to appear inside the little circle
|
2021-12-24 20:06:21 +13:00
|
|
|
var shortName: String?
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2021-12-24 20:06:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PositionAnnotationView: MKAnnotationView {
|
|
|
|
|
|
2022-06-13 20:43:51 -07:00
|
|
|
private let annotationFrame = CGRect(x: 0, y: 0, width: 40, height: 40)
|
2022-01-10 06:09:31 +13:00
|
|
|
private let label: UILabel
|
|
|
|
|
|
|
|
|
|
override init(annotation: MKAnnotation?, reuseIdentifier: String?) {
|
|
|
|
|
self.label = UILabel(frame: annotationFrame.offsetBy(dx: 0, dy: 0))
|
|
|
|
|
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
|
|
|
|
|
self.frame = annotationFrame
|
|
|
|
|
self.label.font = UIFont.preferredFont(forTextStyle: .caption2)
|
|
|
|
|
self.label.textColor = .white
|
|
|
|
|
self.label.textAlignment = .center
|
|
|
|
|
self.backgroundColor = .clear
|
|
|
|
|
self.addSubview(label)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
|
|
fatalError("init(coder:) not implemented!")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public var name: String = "" {
|
|
|
|
|
didSet {
|
|
|
|
|
self.label.text = name
|
2021-12-24 20:06:21 +13:00
|
|
|
}
|
2022-01-10 06:09:31 +13:00
|
|
|
}
|
2021-12-24 20:06:21 +13:00
|
|
|
|
2022-01-10 06:09:31 +13:00
|
|
|
override func draw(_ rect: CGRect) {
|
|
|
|
|
guard let context = UIGraphicsGetCurrentContext() else { return }
|
2021-12-24 20:06:21 +13:00
|
|
|
|
2022-06-13 18:54:16 -07:00
|
|
|
let circleRect = CGRect(x: 1, y: 1, width: 38, height: 38)
|
2022-12-30 13:18:02 -08:00
|
|
|
context.setFillColor(Color.accentColor.cgColor ?? CGColor(red: 0, green: 0.5, blue: 1.0, alpha: 1.0))
|
2022-01-10 06:09:31 +13:00
|
|
|
context.fillEllipse(in: circleRect)
|
|
|
|
|
}
|
2021-12-24 20:06:21 +13:00
|
|
|
}
|