hulab / ClusterKit

An iOS map clustering framework targeting MapKit, Google Maps and Mapbox.
MIT License
512 stars 86 forks source link

Annotation and cluster views are actually re-created when scrolling the map but not re-used (Mapbox) #73

Closed Lawris closed 4 years ago

Lawris commented 5 years ago

Hello,

Using the example project in Swift for MapBox (modifying it a little bit for troubleshooting), I found that when I scroll the map to some point and then get back to the initial position, annotations views are always re-created but not loaded through dequeueReusableAnnotationView().

viewsReacreated

As you can see, in the first place single annotation and cluster views exist. But then, scrolling somewhere seems to "delete" the created views, because when I scroll back to the initial position, annotations and clusters views are re-created.

Screenshot 2019-05-18 at 12 31 43

Here I took the example of annotations (blue markers), I print something when the annotationView that should be loaded using dequeueReusableAnnotationView() is nil. As you can see, every annotation view is re-created.

Am I missing something or is this a bug indeed?

Same thing is happening for Apple's Mapkit.

Any help is really appreciated, thank you :-)

Lawris commented 5 years ago

Update: I think the whole issue is related to this function called in this delegate: func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) { mapView.clusterManager.updateClustersIfNeeded() }

updateClustersIfNeeded() and updateClusters() seem to "delete" the annotation views when not visible (the camera is elsewhere), that could explain why they are recreated each time I scroll fast to the original camera position.

Any fix for this?

GauravTechbirds commented 5 years ago

@Lawris any hack for this fix ?

Lawris commented 5 years ago

@GauravTechbirds did not find anything relevant, maybe we should contact Mapbox to ask them what alternative solution could be useful about clustering. Anyhow maybe those hacks could work (not tested yet):

maxep commented 5 years ago

ClusterKit will indeed remove and delete annotations on the map based on zoom or translation. Clusters are computed within a frame which is the visible area + a margin factor. This behavior allows increasing performances on a large set of annotation. If you prefer computing clusters on the entire world map, you can set the margin factor to kCKMarginFactorWorld value (it is actually the default value).

What is the value of your clusterManager's marginFactor property?

maxep commented 4 years ago

I will close this as a nofix. Feel free to comment later in case you have additional questions!