I have a function which removes all my layers from the map individually:
function resetMap() {
map.removeLayer(Frog1Layer);
map.removeLayer(Frog2Layer);
map.removeLayer(Frog3Layer);
map.removeLayer(Frog4Layer);
map.removeLayer(Frog5Layer);
map.removeLayer(Frog6Layer);
map.removeLayer(Frog7Layer);
map.removeLayer(Frog8Layer);
}
I assume there's a better way? I tried making them into a group but the issue is, I have already added them to the map separately so they can be triggered by buttons on my page, and I don't know how to group them without adding them to the map as a group.
I tried the following:
function resetMap() {
var allLayers = L.layerGroup([Frog1Layer, Frog2Layer, Frog3Layer,
Frog4Layer, Frog5Layer, Frog6Layer, Frog7Layer, Frog8Layer])
map.removeLayer(allLayers);
}
and it doesn't work. The Web Console says "t is not defined" but I don't know what this means? What is t and why does L.layerGroup not work? How do I do this? Sorry, I'm new to Javascript.