Skip to content

Instantly share code, notes, and snippets.

@worthbak
Created February 8, 2018 14:05
Show Gist options
  • Save worthbak/21001aa29171ff702fdef329e15df079 to your computer and use it in GitHub Desktop.
Save worthbak/21001aa29171ff702fdef329e15df079 to your computer and use it in GitHub Desktop.
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