I need to listen to layer visibility changes, but can´t figure out how to do it with Javascript 4.x SDK.
LayerList "trigger-action" never triggers on layer visibility changes.
I Tryed like:LayerList.on
But just working on "load" event..
Also triyed to see all events to find the right one, with no success.
Any ideas?
Solved! Go to Solution.
Auto awnser:
layer.watch('visible', (visibility, a, eventName,layer) => {
console.log("visible: ", visibility);
console.log(layer, eventName, a);
});
I don't understand why there is no mention of this in the documentation, watch is not even in the list of methods.
You just have to guess...
Auto awnser:
layer.watch('visible', (visibility, a, eventName,layer) => {
console.log("visible: ", visibility);
console.log(layer, eventName, a);
});
I don't understand why there is no mention of this in the documentation, watch is not even in the list of methods.
You just have to guess...
Have you seen this section in the Programming patterns page that discusses watching for property changes?
No I didn´t 😅, it was quite hidden. 🤔 Thank you for the link! 😜
@davizuco666 there is also a sample that shows how to take advantage of reactiveUtils and watch for when the map's layer visibility changes: https://developers.arcgis.com/javascript/latest/sample-code/watch-for-changes-reactiveutils/
It is recommended to use reactiveUtils - here's a blog that discusses the topic more: https://www.esri.com/arcgis-blog/products/js-api-arcgis/developers/reactiveutils-and-why-you-should-...