Currently the only way I know to change the visiblity of markers in ClusterManager is to do markerClusterManager.getMarkerCollection().getMarkers()
, which gives me a Collection<Marker> object
. You can then change the visibility of these markers.
However, I want to change the visiblity of the markers based on information that is only available in my custom ClusterItem
objects. But the getMarkers()
method is only giving me a Collection of Marker objects, which don't have this information. I can get my custom ClusterItem
objects but I can't change their visibility. I can only do it by getting the Marker object itself, which, to reiterate, does not have the information contained in my custom ClusterItem
object.
Okay I thought of a workaround that seems to work well. In order to change the visibility of markers, I just do clusterManager.removeItem() on the ClusterItem objects that I want to be invisible, and clusterManager.addItem() on the ClusterItem objects that I want to be visible. Afterwards, I call clusterManager.cluster() to get it to re-load the clusters. For ClusterItem objects that I've removed from the clusterManager, I save them in a list and then add them back to the ClusterManager whenever I want them to be visible again. I would still prefer a solution that was able to utilize the setVisibility() method, but I'm going to use this workaround until someone shows a better way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.