jeudi 29 juin 2017

How to add parameters in a function on a AddEventListener

Im trying to create a Web mapping application with some layers, the idea its that i have some checkboxes and when i click them the layer is added or removed (i have already done that) but there are a lot of layers and of course a lot of code, i realize that with a function i can do the work, but after hours and hours of work it still doesnt work an im ready to give up:

function turnon(idlayer, layer) {
  var local = document.getElementById(layer);//verify whick checkbox is the one for the layer
  if (local.checked == true) {
    map.addOverlay(layer);//an OpenLayers method to add the layer to the map
  } else {
    map.removeOverlay(layer);
  }
}
var wmsSector=document.getElementById('sector')//This is the checkbox
wmsSector.addEventListener("click", turnon);

The thing its that i dont know how to add the parameter on the addEventListener Handler i have tried this:

wmsSector.addEventListener("click",turnon('wmsSector',sector))

i appreciate any help u can give me, cause right know the application works but i believe it can be more elegant.

Thanks




Aucun commentaire:

Enregistrer un commentaire