How to Hide and Show ClusterLayer on Demand

2874
2
Jump to solution
09-05-2015 03:54 AM
BruceGreen
New Contributor III

I followed This API Tutorial to create Cluster Points on the map. Now I would like to have a function to hide them. I already tried like?

clusterLayer.hide();

but it didn't work! I also tried to bind the clusterLayer to a GraphicsLayer like below

  var clayer = new esri.layers.GraphicsLayer();
  clayer.add(clusterLayer);
  clayer.hide();

but still not working

After hours of working I find a sample on google at this Demo doing the job of switching between Points and Cluster but it is supper complicated to me!

Can you please let me know how I can hide and show the cluster layer on demand?

0 Kudos
1 Solution

Accepted Solutions
TomSellsted
MVP Regular Contributor

Behrouz,

Instead of using show() and hide() have you tried using the .setVisibility method?  I took a look at the CrimeMapper example and that is the method they used to toggle the visibility.

You can look at the reference here:

GraphicsLayer | API Reference | ArcGIS API for JavaScript

Regards,

Tom

View solution in original post

2 Replies
BenFousek
Occasional Contributor III

I suspect clusterLayer.hide() is not working for you because the clusterLayer variable is declared within the anonymous function called by ready(function () { var clusterLayer; // only available within this function }).

A simple fix within the sample is to declare clusterLayer as a global along with map; then clusterLayer.hide() will work OR add the layer toggling logic within the aforementioned function.

0 Kudos
TomSellsted
MVP Regular Contributor

Behrouz,

Instead of using show() and hide() have you tried using the .setVisibility method?  I took a look at the CrimeMapper example and that is the method they used to toggle the visibility.

You can look at the reference here:

GraphicsLayer | API Reference | ArcGIS API for JavaScript

Regards,

Tom