MKMarkerAnnotationView cluster color
Asked Answered
P

2

6

I’ve been trying out the new iOS 11 MKMarkerAnnotationView, and finally clustering works like a charm. But the problem is that the clusters have the wrong color as you can see in the picture. How can I control this? Wrong cluster color

Phina answered 13/10, 2017 at 8:56 Comment(0)
P
13

Nevermind I managed to figure it out.

I added the following to the mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) function of the delegate.

if let cluster = annotation as? MKClusterAnnotation {
    let markerAnnotationView = MKMarkerAnnotationView()
    markerAnnotationView.glyphText = String(cluster.memberAnnotations.count)
    markerAnnotationView.markerTintColor = UIColor.appPrimary
    markerAnnotationView.canShowCallout = false

    return markerAnnotationView
}
Phina answered 13/10, 2017 at 11:17 Comment(0)
R
0

if you are not using MKMapViewDelegate you can just set, in your MKMarkerAnnotationView subclass,

clusteringIdentifier = MKMapViewDefaultClusterAnnotationViewReuseIdentifier

and in your view controller

mapView.register(SubclassMarkerView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier)

mapView.register(SubclassMarkerView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultClusterAnnotationViewReuseIdentifier)
Rustic answered 3/12, 2018 at 14:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.