Get layer types for all layers in map service

2559
5
Jump to solution
02-08-2016 06:13 AM
YohanBienvenue
Occasional Contributor II

Good morning,

I'm wondering if there's an easy way to get the layer types for all the layers in a map service. By layer "type" I mean: Group Layer, Raster Layer, Annotation Layer, Annotation SubLayer, Feature Layer, etc..

2016-02-08_9-07-54.png

When I check the layerInfos array of my ArcGISDynamicLayer, it will tell me the layer id, parent id, etc.. but it won't tell me what the layer type is. I know I could create a FeatureLayer for each layer to get this info, but that would generate more then a hundred requests since the map service has several layers.

My goal is to get a list of all the layers with the "Feature Layer" type in the map service.

Thanks,

Yohan

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffJacobson
Occasional Contributor III

Rather than multiple queries, you can use a single query to the All Layers and Tables REST API endpoint.

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Yohan,

   I do not think there is any other way then to submit a esriRequest to each of the sublayers in the map service and check the response type for each result. There is no need to create a FeatureLayer for each when you can use esriRequest to just get the json response from the layer with will include the type.

Here is a thread that has a sample that uses esriRequest: List ArcGIS Server Services and URLs to Services

YohanBienvenue
Occasional Contributor II

You're right about not needing the FeatureLayer of course. I confused this part with another requirement we have in our code to get the feature layer fields for some specific layers.

So since this is the way to do it, I tried your suggestion and I think it will do. It's a lot of requests but I didn't notice any significant difference (performance wise) when we load the web app. Plus the requests are cached and will return 304 when it's been done once already. It pollutes the Network tab a bit, but that is a minor issue.

Great

Thanks Robert

0 Kudos
JeffJacobson
Occasional Contributor III

Rather than multiple queries, you can use a single query to the All Layers and Tables REST API endpoint.

RobertScheitlin__GISP
MVP Emeritus

Jeff,

   Great idea, I forgot about that.

0 Kudos
YohanBienvenue
Occasional Contributor II

Works like a charm, and makes the code cleaner too since:

1) Each layer object has a property for the object of it's parent layer, instead of just the id.

2) No need to check if this is the last request before calling my callback function, since there's only one request

Thanks Jeff

0 Kudos