Annotation and cluster views are actually re-created when scrolling the map but not re-used (Mapbox)
Lawris opened this issue · 5 comments
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()
.
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.
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 :-)
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?
@Lawris any hack for this fix ?
@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):
- Slowing down the scrolling speed when searching through the map
- Extend the perimeter where the annotations views are being loaded
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?
I will close this as a nofix. Feel free to comment later in case you have additional questions!