ArcGIS JS 4.x get all featurelayers in the map

924
2
05-21-2018 07:25 PM
JustinCarasick
New Contributor III

I am trying to get a list of all featurelayers in the map. Currently i am looping through each layer/sublayers in the map and calling createFeatureLayer() on the sublayer.

Sometimes this returns a featurelayer as expected. other times it returns null or undefined for a group layer for example (which is fine).

The issue i am seeing is when i do get a featurelayer back i am getting them back for RasterLayers that are in the map. if i check the featurelayer.type i do get "feature". I wasn't expecting this. Maybe this is a bug?

 

Is there a way i can find all queryable layers (featurelayer) without having to further call the featurelayer.load() method to further interrogate the fields array to see if it's queryable?

The end goal is for every layer in the map (feature or table) i am trying to provide a function to open a table or set a definition query for example.

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Justin,

   The sublayer class does not give you information on the type of layer (as you have already seen). But you can make one esriRequest call to the rest service to get the types of layers that form that particular map service.

https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/l... 

If you do that you will get info like 

"type": "Group Layer",
"type": "Annotation Layer",
"type": "Feature Layer",
JustinCarasick
New Contributor III

this is probably the best option and probably faster than the way i'm doing it currently. thanks.

0 Kudos