Hello,
I'm trying to toggle a Layer list widget but the code is not working. It should respond to a click event on a button that switches its value to on/off. So far it creates the widget and adds it to the map. The part that doesn't work is when trying to remove the widget.
Thank you in advance,
var boff=document.getElementById("onoff");
boff.addEventListener('click',function ()
{
currentvalue=boff.value;
if(currentvalue == "Off"){
document.getElementById("onoff").value="On";
view.when(function () {
var layerList = new LayerList({
view: view
});
view.ui.add(layerList, "top-right");
});
}
else{
view.ui.remove('layerList');
document.getElementById("onoff").value="Off";
}
})