In my application I am adding a webmap where all layers are turned off. I am looking for a way to track the # of layers toggled on and the id/name of the layers. I have not been able to find an event triggered when the layers are toggled on/off. I am doing this because I want to be able to dynamically update the Swipe widget which I could do if I could find the event that fires when the layer is toggled.I also want to limit the number of layers toggled on at some point possibly. I am working in javascript 4.15. Just a note the layer toggle is not linked to the layer added/removed from map events. Also I am using the layerlist idget to toggle the layers on/off visibility.
Solved! Go to Solution.
Jamal,
Here is one way:
view.when(function() {
var layerList = new LayerList({
view: view,
});
setTimeout(function() {
view.layerViews.map(function(item){
item.watch('visible', function(visible){
console.info(visible, item.layer.title);
}, item.layer.title);
});
}, 500);
// Add widget to the top right corner of the view
view.ui.add(layerList, "top-right");
});
Jamal,
Here is one way:
view.when(function() {
var layerList = new LayerList({
view: view,
});
setTimeout(function() {
view.layerViews.map(function(item){
item.watch('visible', function(visible){
console.info(visible, item.layer.title);
}, item.layer.title);
});
}, 500);
// Add widget to the top right corner of the view
view.ui.add(layerList, "top-right");
});
Robert thank you! The item.watch is what I needed.