Add a Legend to LayerList sample with Group Layers and selectionEnabled

908
0
02-18-2021 09:13 AM
NilsBabel1
Occasional Contributor

I'm working with the ArcGIS JavaScript API 4.18 'Add a Legend to LayerList' sample (https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-legend/).  I have group layers and sub group layers in my map and the sample code has a line in it to check for group layers so it doesn't show the legend twice.  This all works fine until you make selectionEnabled = true.  This lets you select layers and drag them to reorder them in your list.  Layers with one group can be reordered without issue.  However, layers in a subgroup (group within a group) lose the legend, and any other actions, you have set on the layer when you reorder them.  If you drag them out of the subgroup the legend and actions will reappear.  This is happening because the listItemCreatedFunction gets called when you reorder the layers but the flag that checks if the layer is a group prevents the layers in the subgroup from building a legend.  You can see an example in these two pens:

So my question is: Is this expected behaviour?  Is this a bug?  When I'm reordering the layer why does it apparently think it's a group layer and not build a legend?  

Thanks for any help

 

0 Kudos
0 Replies