Legend Control#
Example#
from ipyleaflet import Map, LegendControl
m = Map(center=(-10,-45), zoom=4)
legend = LegendControl({"low":"#FAA", "medium":"#A55", "High":"#500"}, title="Legend", position="bottomright")
m.add(legend)
m
# Manipulate the legend
# Set/Get legend title
legend.title = "Risk" # Set title
legend.title # Get title
# Set/Get legend content
legend.legend = {"el1":"#FAA", "el2":"#A55", "el3":"#500"} # Set content
legend.legend # Get content
legend.add_legend_element("el5","#000") # Add a legend element
legend.remove_legend_element("el5") # Remove a legend element
# legend position
legend.position = "topright" # Set position
legend.position # Get current position
'topright'
Attributes and methods#
- class ipyleaflet.leaflet.LegendControl(**kwargs: Any)[source]#
LegendControl class, with Control as parent class.
A control which contains a legend.
Deprecated since version 0.17.0: The constructor argument ‘name’ is deprecated, use the ‘title’ argument instead.
- title#
The title of the legend.
- Type:
str, default ‘Legend’
- legend#
A dictionary containing names as keys and CSS colors as values.
- Type:
dict, default ‘Legend’
- add_legend_element(key, value)[source]#
Add a new legend element.
- Parameters:
key (str) – The key for the legend element.
value (CSS Color) – The value for the legend element.
- property legends#
The legend information.
Deprecated since version 0.17.0: Use legend attribute instead.
- property name#
The title of the legend.
Deprecated since version 0.17.0: Use title attribute instead.
- property positioning#
The position information.
Deprecated since version 0.17.0: Use position attribute instead.
- property positionning#
The position information.
Deprecated since version 0.17.0: Use position attribute instead.