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.
Solved! Go to Solution.
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}`);
});
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}`)
});
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.
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}`);
});
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.