Skip to content

geohierarchy.maps.folium.legend

Zoom-aware legend rendering: one small fixed-position box per configured layer.

Only the legend belonging to whichever level's zoom range contains the current map zoom is shown, mirroring the vector-tile visibility rule (each level's tiles only render within their own [minZoom, maxZoom]).

HierarchyLegend(entries, position='bottom-right')

Bases: MacroElement

A branca MacroElement rendering one fixed-position legend box per level.

Each box is toggled via a map.on('zoomend', ...) listener so only the box whose level's [min_zoom, max_zoom] contains the current zoom is visible.

Parameters:

Name Type Description Default
entries List[Tuple[str, str, Tuple[int, int]]]

List of (div_id, html, (min_zoom, max_zoom)) tuples, one per level that has a legend.

required
position str

CSS corner: "bottom-right", "bottom-left", "top-right", or "top-left".

'bottom-right'

build_legend(layers, resolutions, gdfs=None)

Build a :class:HierarchyLegend from a mapping of level name -> MapLayer.

Parameters:

Name Type Description Default
layers Dict[str, 'object']

Mapping of level name to :class:~geohierarchy.maps.folium.render.MapLayer.

required
resolutions Dict[str, Tuple[int, int]]

Zoom-range assignment per level, from :func:assign_resolutions.

required
gdfs Optional[Dict]

Optional mapping of level name to its GeoDataFrame, used to infer a ColorSpec's domain/categories when not given explicitly.

None

Returns:

Name Type Description
A Optional[HierarchyLegend]

class:HierarchyLegend, or None if no layer has legend

Optional[HierarchyLegend]

content (no ColorSpec/legend_html).