Leaflet.Legend
Leaflet.Legend copied to clipboard
Update Legend Dynamically?
Hello, Is it possible to populate the legends array dynamically AND update the legend html?
In my code I first create a legend,
var legend = L.control.Legend({ position: "bottomleft", symbolWidth: 24, opacity: 1, column: 2, legends: [] });
then, in a for/of loop, I listen for a checkbox status change from false to true and perform:
legend.options.legends.push( { label: text, type: "image", url:
icons/${text}.png })
legend.addTo(map);
which adds a blank legend to the html and populates the legends array, but does NOT update the actual html. Have i done something wrong?
what i found out is if you add legend.initialize();
before legend.addTo(map);
it loads legend content just fine