Hey,
i just tried to add some actions to my layerlist widget. (increase/decrease opacity, zoom to extent)
In this example they called a special layer by name but i want to use this actions on each layer in my map.
Isn't there an easy way to define the selected Layer in the layerList widget?
I didn't find anything easy like "var layer = layerlist.selectedLayer"
Thank you
The LayerList has selectedItems Collection you can watch for change events. The Item has a layer property you can reference.
Thanks for your reply @ReneRubalcava
I tried with the following snippet;
layerList.on("trigger-action", (event) => {
layerList.selectedItems.watch("ListItem",layer =>{
console.log("do something");
});
});
But the console.log doesn't return anything.
selectedItems is a Collection, so you can use ".on()" to listen for events, like this sample.
Thanks again for your fast reply @ReneRubalcava
The Solution that works for me is;
layerList.on("trigger-action", (event) => {
var activeLayer = event.item.layer.name;
console.log(activeLayer);
});
Defining the 'name" in the layer definition...
I was looking to do the same thing, but your excerpt didnt work for me. Would you be able to provide the exact syntax you used?
Thanks