@EnvironmentObject var mapData: MapViewModel
@Binding var radiusRatio: Double
func makeCoordinator() -> Coordinator {
return TestMapView.Coordinator()
}
func makeUIView(context: Context) -> MKMapView {
let view = mapData.mapView
view.showsUserLocation = true
view.delegate = context.coordinator
return view
}
func updateUIView(_ uiView: MKMapView, context: Context) {
}
class Coordinator: NSObject, MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let indetifire = "TESTING NOTE"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: indetifire)
if annotation.isKind(of: MKUserLocation.self){return nil}
else {
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: indetifire)
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
annotationView?.image = UIImage(systemName: "circle.fill")!.withTintColor(UIColor(red: 1, green: 0, blue: 0, alpha: 0.5) )
let size = CGSize(width: 40 * radiusRatio, height: 40 * radiusRatio)
annotationView?.image = UIGraphicsImageRenderer(size:size).image {_ in
annotationView?.image!.draw(in:CGRect(origin:.zero, size:size))
// annotationView?.backgroundColor = .red
}
}
else {
annotationView?.annotation = annotation
}
// let pinAnnotation = MKPinAnnotationView(annotation: annotation, reuseIdentifier: indetifire)
//// let pinAnnotation = MKAnnotationView(frame: CGRect(x: 1, y: 1, width: 10, height: 10))
// pinAnnotation.tintColor = .green
// pinAnnotation.animatesDrop = true
// pinAnnotation.canShowCallout = true
}
return annotationView
}
}
}
не подскажите?
Обсуждают сегодня