Layer control (TOC): Hide or Show layers and/or group layers

Discussion created by a.schaefer-esri-de-esridist on Sep 2, 2010
Latest reply on Mar 13, 2013 by bg3075

I don't know how to handle my layer control with the right JS API statements to the REST API.

I've got a very simple mapservice (called grouped) with a group layer and two sublayers:

World (0) (Grouplayer)
`-> World Country (1) (Layer)
`-> World Timezone (2) (Layer)

The JS-API Samples with the layer control makes use of the  ArcGISDynamicMapServiceLayer.setVisibleLayers() method to define the visible layers. The parameters for that method are the IDs of the layer.

That doesn't work for group-layers, like this layer "World" with the ID 0. If I write this command in the JS API:


I see all layers, even the unchecked layers 1 and 2. What happens, is that the REST interface gets an ExportMap request like this, when I only check the group layer 0 to active:


The result is that all layers are shown: World Country and World Timezone, although they are not in the list of the visible layers!

The logic of checking and unchecking grouplayers works, if I use the HIDE method in the REST API. Hiding layer 0 (the grouplayer) returns an empty map. All combinations work with the HIDE option.

Question: How can I use the HIDE logic with the JS API? Where is the ArcGISDynamicMapServiceLayer.setHiddenLayers() method? ;) How can I make a layerlist control with grouplayers?

Can I set the esri.layers.ImageParameters() at runtime after initialization? The ImageParameters have the layerOptions LAYER_OPTION_HIDE. But they are read out and used at initialization.

How can I achive the logic with the grouplayers?

Thanks in advance,