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 am trying to fetch the names of the layers in the MapService, so that I can populate them in the dijit.form.select. I am able to get the layerInfo when the ArcGISDynamicMapServiceLayer is added to the map by using,

map.getLayer(map.layerIds[0]).layerInfos[0].name

But this is only after the layer has been added to the map. Is there some way by which I can get the layerInfo names directly from the URL?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Yes, send a request to the layer's URL to retrieve info as JSON and then pull out what you need. The Request Layer Info sample shows how to do this.

Edit: Here's a link to a tweaked version of the sample that shows querying a service for layer names: http://jsfiddle.net/Cuef5/ Note that the URL being used is for a map service:

http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Energy/Geology/MapServer

As opposed to using a URL for a single layer like:

http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Energy/Geology/MapServer/3
share|improve this answer
    
thanks for the reply @Derek but this gives all the details of the attributes in the layer. I simply want the layer name, which we get from map.getLayer(map.layerIds[0]).layerInfos[0].name –  Sam007 Nov 7 '12 at 6:30
    
@Sam007 there's no way to request only the names of the layers in a map service– you have to get all map service info, then navigate the returned object to access layer names. This is a quick, relatively cheap operation since it's a single request for not much data. –  Derek Swingley Nov 7 '12 at 15:17
    
The reason I need it is I am having a dijit.form.select where I am adding the map service names in the items and on selection of a map service, another dijit.select will be populated with the names of the layers in the selected map service. So I have the URL but not sure how to obtain only the layer names to populate them in the dropdown. This is my application, msgist2011.grd.arizona.edu/project/tp_dock.html, if u click on the Mapping the Data docked floating pane and then change selection u can see the layer list but I am not able to populate it with the appropriate name –  Sam007 Nov 7 '12 at 17:04
    
I am getting the returned object but not sure how to navigate to the layer names? The link, help.arcgis.com/en/webapi/javascript/arcgis/samples/…, gives the info of the layer's attribute table not the name –  Sam007 Nov 7 '12 at 17:45
    
@Sam007 you'll need to query the map service endpoint instead of the endpoint for a particular layer. I've edited my answer with a link to a jsfiddle showing how to do this. –  Derek Swingley Nov 7 '12 at 19:47
show 3 more comments

Your Answer

 
discard

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

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