A legend for ipyleaflet


Introducing ipyleaflet-legend

ipyleaflet-legend is a leaflet legend to be used in jupyter-notebook. ipyleaflet-legend is based on the information found in the Custom Legend Control section of this leaflet tutorial. We won't go too far into details here, just have in mind that it is both a LeafletControl and an ipywidget. Therefore, ipyleaflet-legend must be instantiated with ipyleaflet. The good news is that since it is a LeafletControl, it can be positioned just like any other ipyleaflet control.

A second Post or series will follow to explain how ipyleaflet-legend was made. This tutorial might help anyone wanting to import leaflet widget on ipyleaflet using ipywidget.

Install

At the command prompt enter:

pip install ipyleaflet-legend
jupyter nbextension enable ipyleaflet_legend --py --sys-prefix

Note: if you are not in a virtual environment, use --user instead of --sys-prefix to enable it.

Basic Use

Since ipyleaflet-legend is a Leaflet Control implementation for ipyleaflet, we need to instantiate a map:

from ipyleaflet import Map
mymap = Map(center=(-10,-45), zoom=4)
mymap

And then add a simple legend:

from ipyleaflet_legend import Legend
my_legend = Legend({"low":"#FAA", "medium":"#A55", "High":"#500"}, name="Legend")
mymap.add_control(my_legend)

This is the output of the result in your notebook: image

More details on repository notebook example

Enjoy!

T.Pouvreau @Weatherforce