Tuesday 22 August 2017

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.



Answer



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.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...