Leaflet.Legend icon indicating copy to clipboard operation
Leaflet.Legend copied to clipboard

Update Legend Dynamically?

Open jfitzpa22 opened this issue 2 years ago • 1 comments

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?

jfitzpa22 avatar Aug 20 '21 17:08 jfitzpa22

what i found out is if you add legend.initialize(); before legend.addTo(map); it loads legend content just fine

ERS-Long avatar Nov 04 '21 19:11 ERS-Long