Skip to content

Update Legend Dynamically?  #3

@jfitzpa22

Description

@jfitzpa22

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions