I have a leaflet map set to change styles based on a category when a user clicks a button.
Live map: http://maneesha.github.io/test_map.html
Source code: https://github.com/maneesha/maneesha.github.io
There is a legend for each style. My problem is I can't get the old legend to disappear when another button is clicked (or that button is clicked again). So you'll see on the map each time you click, a new legend appears.
Putting
map.removeControl(legend);
in the click function does not work and results in this in the js console:
Uncaught TypeError: Cannot read property 'removeFrom' of undefined
Any ideas?
EDIT: Repos above have been changed. Live site no longer exists; source code is at https://github.com/maneesha/leaflet_map_with_styles_and_legends