Select to view content in your preferred language

Show only required layers from a map service in ArcGISDynamicMapServiceLayer

815
3
07-24-2013 05:18 AM
PhanindraKuchipudi
Emerging Contributor
Hi,
I have a map service published with 250 layers. I need only 20 layers out of them to work on. When I add this service as ArcGISDynamicMapServiceLayer on map, all 250 layers are shown on map as well as in legend (TOC) also. Can any one help me how to access only required layers (based on name or ID etc.,) from a map service in ArcGISDynamicMapServiceLayer?
I do not want to add each layer separately on map as feature layer and make my map bulky with layers.
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
If your layer is not cached, you can set VisibleLayers with the list of sublayers you want to see.
0 Kudos
PhanindraKuchipudi
Emerging Contributor
Hi Dominique,

Thanks for your reply. I have tried to set the visiblelayers property in the initialization event to view the required layers. But it is overwriting only the default visible layers in map service and all other layers are just invisible on map, not removed from legend (TOC). User can make them visible by checking the check box in legend control. Actually I want all those unwanted layers to be removed from legend (TOC) also, so that I can make user unaware of all those layers.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
It seems you need 3 states for the sublayers:
    - visible
    - unvisible but settable to visible by the user
    - unvisible and locked as unvisible
That use case is not managed out of the box.

One option is to remove the locked sublayers from the legend (in an handler wired to the legendChanged event).

In short:
   - keep wherever you like the initial list of sublayers you authorize to display
   - initialize the VisibleLayers property with this list (or a subset, if some sublayers should be unvisible at startup but activable by the user)
   - in the legendChanged handler, remove all layerItems that are not in the initial list
0 Kudos