Skip to main content
3 of 3
Updated for 2014
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Loading group layer in ArcGIS Map Service?

My ArcGIS JavaScript application is using an ArcGIS Server Map Service that has a bunch of layers. It also has a group layer. The structure is:

Service
    group_layer_0
        layer_1
        layer_2
    layer_3
    layer_4

After the service being loaded, it not only loads group_layer_0 (which shows layer_1 & layer_2), but also loads layer_1 and layer_2 as individual layers. In other words, layer_1 (or layer_2) is loaded twice. When I turned off group_layer_0, layer_1 is still visible because of the visibility of individual layer_1.

how should I do to avoid this? which means, when I turned off group_layer_0, it would turn off all its sub_layers; but when i turned off layer_1, it would only affect layer_1; besides, layer_1 should be loaded once, instead in current case being loaded as part of group layer and also as an individual layer.

I hope I explained this clearly. and thanks for any help!

Update:

e.g.,:

If want to turn off layer_1, i did:

var visibleLayers = mapServiceLayer.visibleLayers;
var newVisibleLayers = removeLayerIDFromLayerList(visibleLayers, 1); 
//remove layer_1's layer ID from current visibleLayers; 
//removeLayerIDFromLayerList is a developer-defined function

mapServiceLayer.setVisibleLayers(newVisibleLayers);
//update visible layers based on new list

In the above example, I turned off layer_1, but the new visible layer list still include group_layer_0, since there is no manipulation on this group layer's visibility. and the outcome is layer_1 is still visible. which doesn't make any sense. layer_1 should be off, even though it's part of a group layer.

but this is not the case, at least in my application.

Simon
  • 1.2k
  • 4
  • 17
  • 29