AnsweredAssumed Answered

Leaflet using a variable for addTo(map)

Question asked by on Nov 28, 2016
Latest reply on Nov 29, 2016 by fcbassongis

OK, I have a simple cancer web map in Leaflet and I'm stumped on a problem.

1. I have an HTML check box which when clicked turns on a layer. (Layer switcher is not an option) this basically calls a function and passes the cancer layer name. i.e.updateLayerVis("lung")


2. I have different types of cancer defined by name. i.e. var throat = new L.GeoJSON(data .....


3. So the function listed above passes the value 'lung' to 'a' below. It appears to be passing a dumb string called 'lung' while addTo is looking for a layer. Is it possible to use this string to add the appropriate layer to the map?



function updateLayerVis(a){

console.log(a); // lung

a.value.addTo(map); // returns an error "a.addTo is not a function"

a.addTo(map); // returns an error "a.addTo is not a function"

lung.addTo(map); //works but with 15 check boxes, I'd need a large switch function.