I download TOC here:
https://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109
I want to create a button like the sample one able to turn on/off a layer.
I only able to turn on a sublayer using setVisibleLayers method here when a button is clicked.
on(dom.byId("SetVisibleLayersProgramatically"),'click', function(evt){
Dynlayer.setVisibleLayers([11]);
});
But how do you turn off the same sublayer when another button is clicked? I don't want to use toc.findTOCNode( Dynlayer, 11).hide(). It will remove the layer. I would to uncheck the layer instead of remove the layer.
Is there any way, simple way to do this task?
Thank you.
You can use the button to turn off the sublayer the same way you use to turn it on, with the setVisibleLayers method of the layer. You just have to make sure that the sublayer is not in the array used in that method.
To do this, you would first obtain the list of visible layers using the layer visibleLayers method. Next, use Dojo's indexOf (this gets around any browser incompatibilities with the normal array.indexOf) to determine whether that visibleLayers array contains a specific sublayer, then use splice to remove it.