Select to view content in your preferred language

LayerList widget list to order changes

821
4
Jump to solution
04-10-2023 04:25 AM
Aeseir
by
Frequent Contributor

When setting up LayerList widget I've set selectionEnabled to true, which allows the layers to be reordered including placing layers as sublayers.

 

What i want to be able to do is listen for any event that will tell me the order/hierarchy has changed and what the new structure looks like.

 

There is no documentation explaining if there is a event to even listen for.

0 Kudos
1 Solution

Accepted Solutions
RamaniGanason
Occasional Contributor

Just to add on on the answer that was provided by @Sage_Wall, you can also add reactiveUtils to all the operationalLayers of the LayerList widget. You can maybe store the initial arrange of the layers somewhere and compare every time it changes. The function below will list down all the layers ID  when operational layers are modified.

reactiveUtils.watch(
          () => layerList.operationalItems.map(item => item.layer.id),
          (ids) => {
            console.log(`FeatureLayer IDs ${ids}`);
          });

 

View solution in original post

4 Replies
Sage_Wall
Esri Contributor

Hi @Aeseir ,

Thanks for the question.  There are probably a few different ways to go about this, but I'd suggest using reactiveUtils  to watch the map allLayers property as shown in this sample.  This sample shows how watch for  Collection changes.

https://developers.arcgis.com/javascript/latest/sample-code/watch-for-changes-reactiveutils/

// Use reactiveUtils to check when a Collection has changed
reactiveUtils.watch(
    () => view.map.allLayers.every((layer) => layer.visible),
    (allVisible) => {
        console.log(`All layers are visible = ${allVisible}`)
    });
0 Kudos
Aeseir
by
Frequent Contributor

This doesn't solve my challenge. Sure if i show/hide the layer, but I want to see hierarchy that is displayed in the layerlist.

0 Kudos
RamaniGanason
Occasional Contributor

Just to add on on the answer that was provided by @Sage_Wall, you can also add reactiveUtils to all the operationalLayers of the LayerList widget. You can maybe store the initial arrange of the layers somewhere and compare every time it changes. The function below will list down all the layers ID  when operational layers are modified.

reactiveUtils.watch(
          () => layerList.operationalItems.map(item => item.layer.id),
          (ids) => {
            console.log(`FeatureLayer IDs ${ids}`);
          });

 

Aeseir
by
Frequent Contributor

This is closer to the potential solution. Doesn't quiet work tho if you move a layer as a sublayer, in which case you need to export entire layer tree.

0 Kudos