BindColormap¶
- class pyhelpers.viz.BindColormap(layer, colormap, display=True)[source]¶
Binds a colormap to a Folium layer with visibility synchronization.
This class creates a connection between a Folium map layer and a color scale, showing/hiding the colormap legend when the layer visibility changes.
- Parameters:
layer (folium.FeatureGroup | folium.GeoJson) – Folium layer object (
FeatureGroup
,GeoJson
, etc.) to bind with.colormap (branca.colormap.ColorMap) – Color scale to display and synchronize with layer visibility.
display (bool) – Initial visibility state of the colormap legend; when
display=True
(default), the legend will be visible by default; valid options are'block'
(visible) or'none'
(hidden).
Note
Requires Folium’s
LayerControl
to be enabled for automatic visibility toggling.Examples:
>>> from pyhelpers.viz import BindColormap >>> import folium >>> import branca >>> m = folium.Map() >>> test_feature_group = folium.FeatureGroup(name='Test') >>> test_feature_cm = branca.colormap.LinearColormap( ... colors=branca.colormap.linear.RdYlGn_06.colors[::-1], ... vmin=0.0, ... vmax=1.0, ... caption="Test", ... ) >>> m.add_child(BindColormap(test_feature_group, test_feature_cm)) >>> m
See also
Example usages: Exploration of UK’s Food Hygiene Rating data
Reference: [VIZ-BC-1].