lundi 2 juin 2014

Mapbox toggle visibility of multiple layers


Vote count:

0




I'm trying to toggle the visibility of a layer in a Leaflet/Mapbox map with this function:



var showOne = document.getElementById("one");

showOne.onclick = function(e) {
if (this.className='active') {
map.removeLayer(groupOne);
this.className = '';
} else {
map.addLayer(groupOne);
this.className = 'active';
}
};


That toggles one layer off but not back on. How can I toggle the layer back to visible? Then, how can I toggle multiple layers -- will this work:



var showOne = document.getElementById("one");

showOne.onclick = function(e) {
if (this.className='active') {
map.removeLayer(groupOne);
map.removeLayer(groupTwo);
this.className = '';
} else ...


fiddle



asked 27 secs ago






Aucun commentaire:

Enregistrer un commentaire