Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have access to 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 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..

share|improve this question
    
i cant see that map service. I assume its dynamic and not cached? –  Simon Oct 2 '10 at 2:55

2 Answers 2

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

share|improve this answer
    
Zachery,Thanks for the info but I found a way to do what I wanted.. –  Not to be named Oct 5 '10 at 13:24
    
Although, I was unable to access the legend of the mapservice.. –  Not to be named Oct 5 '10 at 13:25
up vote 1 down vote accepted

I learned that the class "featureLayer" can be used to display an individual layer within both a mapservice or a feature service..

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htmt

dojo.require("esri.layers.FeatureLayer");

The feature layer inherits from the graphics layer and can be used to display features from a single layer in either a Map Service or Feature Service. The layer can be either a (spatial) layer or (non-spatial) table. If the underlying layer (or table) is from a Feature Service, its features can be edited. ESRI- Javascript API Reference

Here is the code I now have that utilizes this method.. and it works!!:D

var featureLayer = new esri.layers.FeatureLayer("http://gis.co.frederick.va.us/ArcGIS/rest/services/Fire_and_Rescue/Fire_and_Rescue/MapServer/8",{
          mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
          displayOnPan:false,outFields: ["*"], opacity:.5, tileWidth:150, tileHeight:150, visible:false,
          infoTemplate: infoTemplate
        });
share|improve this answer
    
You can also get the layerInfos of a dynamic layer, which will get you the id of each layer in the service and let you turn them on or off. –  Tim Rourke Oct 13 '10 at 19:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.