[GIS] Accessing specific layers in ArcGIS Map Service to toggle them on/off

arcgis-javascript-apiarcgis-servermap-service

I have access to a number of ESRI Mapservices and would like to be able to access specific layers within the mapservices in my online map application. I am working on creating this with the ESRI Javascript API.

I have looked, at and hoped that I could use, this sample map:

http://help.arcgis.com/en/webapi/javascript/arcgis/demos/map/map_legendvisible.html

and substitute some of the data I have access to.

When I do substitute mapservices that we have here, the sample map will toggle on and off the entire mapservice and not the specific layer I was hoping it would.

Here is the mapservice I am trying to access with this code:

http://gis1.co.frederick.va.us/ArcGIS/rest/services/Planning/testplanning/MapServer

I would love to hear from someone about a solution. Nothing seems as straight forward as it looks…

Best Answer

In the sample code the quake, fire and base layers are three separate map services.
If you have a specific layer or layers that you want to toggle on/off using this sample, you can publish each layer as it's own map service, then plug them into your sample code.

Alternatively, if you want to have a list of the layers in your service and the ability to turn them off, these samples give examples of pulling a list of the layers in a service.

http://help.arcgis.com/EN/webapi/javascript/arcgis/demos/map/map_dynamiclayerlist.html

http://help.arcgis.com/EN/webapi/javascript/arcgis/demos/map/map_explicitlayerlist.html