Hi,
I want to set the glyphImage property for an annotation view (MKMarkerAnnotationView) of a cluster annotation (MKClusterAnnotation).
Using the below code, inside the marker I get, instead of the glyphImage, the standard cluster number.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let cluster = annotation as? MKClusterAnnotation {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "GroupMapClusterAnnotation")
if annotationView == nil {
annotationView = MKMarkerAnnotationView(annotation: cluster, reuseIdentifier: "GroupMapClusterAnnotation")
}
(annotationView as? MKMarkerAnnotationView)?.glyphImage = UIImage(systemName: "star.fill")
return annotationView
}
}
I think that the problem is that if you keep the glyphText property empty, MapKit automatically set it with the number of the cluster member annotations.
The documentation for glyphImage says:
Use this property or the glyphText property to specify the marker balloon content. If you specify both an image and text, MapKit displays the text.
So, MapKit is setting glyphText with a value an therefore the glyphImage property is ignored.
How can we use the glyphImage property for a cluster annotation?
Thank you
It is possible to provide your own custom annotation views for cluster annotations and those may provide custom images. You can look at the Decluttering a Map with MapKit Annotation Clustering sample code for a good example of this.
However, when using the default MKMarkerAnnotationView,
it is currently not possible to provide a custom glyphImage
value as a substitute for showing the annotation count on the balloon marker.
We encourage you to file an enhancement feedback report if this is something that would like to accomplish.