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 ...