Cannot find nested sublayers in a MapImageLayer

224
1
01-26-2020 12:44 PM
ae
by
Occasional Contributor

I'm trying to create my own custom layer-list component with an integrated legend (I'm not using the APIs LayerList widget as I need more functionality). When trying to integrate MapImageLayers into my component, I also need to accommodate nested sublayers (sublayers within a sublayer).

However, if I create a MapImageLayer using a service that has nested sublayers, i.e.: 

let layer = new MapImageLayer(...)

and then retrieve the sublayer that I know has nested sublayers:

let sublayer = layer.sublayers.items[1]

then that sublayer does not have any nested sublayers, even though it should: 

let nestedSublayer = sublayer.sublayers.items[0] 

instead, sublayer.sublayers is null. 

Does anyone know how/where I can find the hierarchy of the MapService when loaded into a MapImageLayer? 

edit: Seemingly the sublayers property contain a flat collection of all sublayers in the layer (i.e. they are on the same level regardless of whether they are nested within other sublayers or not). 

0 Kudos
1 Reply
Noah-Sager
Esri Regular Contributor

This should work. I would make sure that you have the correct order when searching for nested sublayers, as this has thrown me for a loop in the past. Here is a working sample that prints out nested sublayer info in the console:

https://codepen.io/noash/pen/WNbWdyO 

Using this MapServer (with a couple levels of nested sublayers):

Military (MapServer) 

Hope this helps. 

0 Kudos