efremidze / Cluster

Easy Map Annotation Clustering 📍
MIT License
1.27k stars 121 forks source link

mapView.showAnnotations breaks clustering #112

Open tomrapadmi opened 5 years ago

tomrapadmi commented 5 years ago

Description Calling MKMapView.showAnnotations(:MKAnnotation) will zoom the map appropriately to show the annotations passed in, however the cluster manager will never cluster those annotations again (even after calling reload). I tried using the function in 2 ways:

  1. When a cluster is clicked: mapView.showAnnotations(clusterAnnotation.annotations, animated: true)
  2. When the annotations are initially created: mapView.showAnnotations(newAnnotations, animated: true)

In the first case the annotations from the cluster are never clustered again. In the second case no annotations are ever clustered.

Smartphone

Checklist

spiegelsauce commented 1 year ago

For anyone struggling with this at this point.

I saw this issue as well. Judging from the behavior I observed with showAnnotations(), it will add the annotations to the mapview if they aren't already there, bypassing the Clustermanager completely. From the mapView's point of view this happens because it only knows about the CluserAnnotation and has no knowledge of its members.

My workaround was to calculate and generate the region of the annotations manually and then use MKMapView.setRegion(:MKCoordinateRegion) with that region. It will adjust the region without touching any annotations of the mapview.