I am using iOS SDK of Mappls which uses MapplsMapView class to point out the annotations. I need to design the mapView in a way if it is zoomed out, the nearer or overlapping annotations should be updated to a single annotation. At the same time while zooming in, the grouped annotation should ungroup to individual annotations.
In MapKit of Apple, I can usually do this by checking whether the annotation is of type MKClusterAnnotation and update the image of the annotation like this :
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isKind(of: MKUserLocation.self) {
return nil
}
if let annotation = annotation as? MKClusterAnnotation {
if let selected = mapView.selectedAnnotations.first {
let underCluster = annotation.memberAnnotations.contains { $0 === selected }
if underCluster {
mapView.deselectAnnotation(selected, animated: false)
}
}
let view = mapView.dequeueReusableAnnotationView(withIdentifier: "multipleRecords", for: annotation)
let hidden = annotation.count > 99 ? "+99" : "\(annotation.count)"
view.image = theme.clusterAnnotation.withOverlay(text: hidden)
return view
}
return nil
}
In Mappls, I implemented the same function like this:
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
if let cluster = annotation as? MGLCluster {
print("Cluster found with count \(cluster.clusterPointCount)")
}
return nil
}
But the above check is not itself passed. Am I missing something here? Please help out on this.