Created
February 8, 2018 14:05
-
-
Save worthbak/21001aa29171ff702fdef329e15df079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { | |
// 1 | |
if let item = annotation as? MapItem { | |
// 2 | |
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "mapItem") | |
?? MKAnnotationView(annotation: annotation, reuseIdentifier: "mapItem") | |
annotationView.annotation = item | |
annotationView.image = UIImage(named: "annotation") | |
// 3 | |
annotationView.clusteringIdentifier = "mapItemClustered" | |
return annotationView | |
} else if let cluster = annotation as? MKClusterAnnotation { | |
// 4 | |
let clusterView = mapView.dequeueReusableAnnotationView(withIdentifier: "clusterView") | |
?? MKAnnotationView(annotation: annotation, reuseIdentifier: "clusterView") | |
clusterView.annotation = cluster | |
clusterView.image = UIImage(named: "cluster") | |
return clusterView | |
} else { | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment