Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Legend Dynamically? #3

Open
jfitzpa22 opened this issue Aug 20, 2021 · 1 comment
Open

Update Legend Dynamically? #3

jfitzpa22 opened this issue Aug 20, 2021 · 1 comment

Comments

@jfitzpa22
Copy link

jfitzpa22 commented Aug 20, 2021

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?

@ERS-Long
Copy link

ERS-Long commented Nov 4, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants