Select to view content in your preferred language

How Do I Identify The Name of a Layer ID

970
3
Jump to solution
01-23-2012 01:06 PM
ChrisSergent
Deactivated User
I want to evaluate the name of a layer like I did in the Web ADF, but I can't seem to find code similar to that?

Here is a URL with a screen recording of my question:


http://youtu.be/WkR4VBjx2_s

Thanks again.

Chris S.
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Deactivated User
If you're setting up a query task against a layer that's in a map service you've already added to your JS API map, you can use the map service's layerInfos to loop through and match a name to an id.

Otherwise, use esri.request() to make a call to your map service endpoint. The JSON that comes back will have a layers property. Layers is an array of objects where each object corresponds to a layer in the map service. Every layer object will have an id and a name.

And thank you for the video- wish more people would do that :).

View solution in original post

3 Replies
derekswingley1
Deactivated User
If you're setting up a query task against a layer that's in a map service you've already added to your JS API map, you can use the map service's layerInfos to loop through and match a name to an id.

Otherwise, use esri.request() to make a call to your map service endpoint. The JSON that comes back will have a layers property. Layers is an array of objects where each object corresponds to a layer in the map service. Every layer object will have an id and a name.

And thank you for the video- wish more people would do that :).
ChrisSergent
Deactivated User
If you're setting up a query task against a layer that's in a map service you've already added to your JS API map, you can use the map service's layerInfos to loop through and match a name to an id.

Otherwise, use esri.request() to make a call to your map service endpoint. The JSON that comes back will have a layers property. Layers is an array of objects where each object corresponds to a layer in the map service. Every layer object will have an id and a name.

And thank you for the video- wish more people would do that :).


Thanks Derek. This works.

Here is a line of code with my alert: alert(dynamicMapServiceLayer.layerInfos[4].name);

I have found videos to save time in explaining. 😄
0 Kudos
derekswingley1
Deactivated User
I have found videos to save time in explaining. 😄

Indeed they do!

Glad I could help.
0 Kudos