2

I am using two ClusterManager each with their own items.

I need to toggle (show/hide) those items depending on what ClusterManager they belong to.

Example:a button that hides all cluster items that belong to cluster 1.

I am only using Cluster Items and not Markers and thus can't do Marker.setVisibility(Boolean).

I tried to save all cluster items into an array and then iterate thorugh it on the button press but it seems you cannot hide a cluster item.

Many thanks!

KasparTr
  • 2,328
  • 5
  • 26
  • 55

1 Answers1

0

Based on this documentation, it only show how to add ClusterItem.

To use the marker clustering utility, you will need to add markers as ClusterItem objects to the ClusterManager. The ClusterManager passes the markers to the Algorithm, which transforms them into a set of clusters. The ClusterRenderer takes care of the rendering, by adding and removing clusters and individual markers. The ClusterRenderer and Algorithm are pluggable and can be customized.

For hiding the ClusterItem.

I found a solution in this SO question, on how to hide the ClusterItem.

Because ClusterManager doesn't implement removing elements.

You can try to use GridBasedAlgorithm(it supports elements remove):

clusterMng.setAlgorithm(new GridBasedAlgorithm<MyClusterItem>());

Or, for better performance, wrap it with PreCachingAlgorithmDecorator, as ClusterManager does by default:

clusterMng.setAlgorithm(new PreCachingAlgorithmDecorator<MyClusterItem>(new GridBasedAlgorithm<MyClusterItem>()));
Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31