Select to view content in your preferred language

handle/listen Layer visibility events

1326
4
Jump to solution
04-05-2023 02:40 AM
davizuco666
New Contributor II

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.onLayerList.on

But just working on "load" event..

 

Also triyed to see all events to find the right one, with no success.

imagen.png

 

Any ideas?

0 Kudos
1 Solution

Accepted Solutions
davizuco666
New Contributor II

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...

View solution in original post

4 Replies
davizuco666
New Contributor II

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...

KenBuja
MVP Esteemed Contributor

Have you seen this section in the Programming patterns page that discusses watching for property changes?

davizuco666
New Contributor II

No I didn´t 😅, it was quite hidden. 🤔  Thank you for the link! 😜

0 Kudos
LaurenBoyd
Esri Contributor

@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-... 

Lauren