4

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.

3
  • You could try to adjust the settings for display by scale for the group layer, as well as the display by scale for the individual layer.
    – JLP Wisc.
    Commented Jan 7, 2013 at 16:50
  • thanks for your help, @JLP Wisc. I added more to the question. hope that makes it easier to understand.
    – Simon
    Commented Jan 7, 2013 at 20:56
  • Is single fused map cache false? See answer here. Commented Jan 9, 2013 at 19:57

1 Answer 1

3

The behavior of groups using the API is different than in ArcMAP TOC. This is how I understand your layerIDs:

a. LayerID0 LayerID1 LayerID2
b. LayerID1
c. LayerID2
d. LayerID3
e. LayerID4

If you turn on group layer (a), then all sublayers will be displayed.
If you turn off group layer (a) but turn on layer (b) or (c) then only layers will display.
If you turn off layers (b) or (c) and group layer (a) then none will display.

Here's an outdated but possibly relevant link to ESRI's forum topic on group layers.

Also, pardon my reiteration from my comment, but because the group layers are treated differently in the UI you could use this to your advantage by using different scale displays depending on how you are using the information in your app.

Hope this helps.

2
  • this explains the logic underlying group layer display. even though not 100% agree with this logic.
    – Simon
    Commented Jan 10, 2013 at 18:24
  • yeah. we don't use groups in map services for this reason.
    – JLP Wisc.
    Commented Jan 10, 2013 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.