Skip to content

map_widgets module

leafmap.map_widgets

Colorbar

Bases: Output

A matplotlib colorbar widget that can be added to the map.

__init__(vmin=0, vmax=1, cmap='gray', discrete=False, label=None, orientation='horizontal', transparent_bg=False, font_size=9, axis_off=False, max_width=None, **kwargs)

Add a matplotlib colorbar to the map.

Parameters:

Name Type Description Default
vis_params dict

Visualization parameters as a dictionary. See https://developers.google.com/earth-engine/guides/image_visualization # noqa for options.

required
cmap str

Matplotlib colormap. Defaults to "gray". See https://matplotlib.org/3.3.4/tutorials/colors/colormaps.html#sphx-glr-tutorials-colors-colormaps-py # noqa for options.

'gray'
discrete bool

Whether to create a discrete colorbar. Defaults to False.

False
label str

Label for the colorbar. Defaults to None.

None
orientation str

Orientation of the colorbar, such as "vertical" and "horizontal". Defaults to "horizontal".

'horizontal'
transparent_bg bool

Whether to use transparent background. Defaults to False.

False
font_size int

Font size for the colorbar. Defaults to 9.

9
axis_off bool

Whether to turn off the axis. Defaults to False.

False
max_width str

Maximum width of the colorbar in pixels. Defaults to None.

None

Raises:

Type Description
TypeError

If the vis_params is not a dictionary.

ValueError

If the orientation is not either horizontal or vertical.

ValueError

If the provided min value is not convertible to float.

ValueError

If the provided max value is not convertible to float.

ValueError

If the provided opacity value is not convertible to float.

ValueError

If cmap or palette is not provided.

LayerEditor

Bases: VBox

Widget for displaying and editing layer visualization properties.

__init__(host_map, layer_dict)

Initializes a layer editor widget.

Parameters:

Name Type Description Default
host_map Map

The geemap.Map object.

required
layer_dict dict

The layer object to edit.

required

Legend

Bases: VBox

A legend widget that can be added to the map.

__init__(title='Legend', legend_dict=None, keys=None, colors=None, position='bottomright', builtin_legend=None, add_header=True, shape_type='rectangle', widget_args={}, **kwargs)

Adds a customized legend to the map.

Args: title (str, optional): Title of the legend. Defaults to 'Legend'. legend_dict (dict, optional): A dictionary containing legend items as keys and color as values. If provided, keys and colors will be ignored. Defaults to None. keys (list, optional): A list of legend keys. Defaults to None. colors (list, optional): A list of legend colors. Defaults to None. position (str, optional): Position of the legend. Defaults to 'bottomright'. builtin_legend (str, optional): Name of the builtin legend to add to the map. Defaults to None. add_header (bool, optional): Whether the legend can be closed or not. Defaults to True. shape_type (str, optional): The shape type of the legend item. widget_args (dict, optional): Additional arguments passed to the widget_template() function. Defaults to {}.

Raises:

Type Description
TypeError

If the keys are not a list.

TypeError

If the colors are not list.

TypeError

If the colors are not a list of tuples.

TypeError

If the legend_dict is not a dictionary.

ValueError

If the legend template does not exist.

ValueError

If a rgb value cannot to be converted to hex.

ValueError

If the keys and colors are not the same length.

ValueError

If the builtin_legend is not allowed.

ValueError

If the position is not allowed.

RasterLayerEditor

Bases: VBox

Widget for displaying and editing layer visualization properties for raster layers.

__init__(host_map, layer_dict)

Initializes a raster layer editor widget.

Parameters:

Name Type Description Default
host_map Map

The geemap.Map object.

required
layer_dict dict

The layer object to edit.

required

SimilaritySearch

Bases: VBox

A widget for similarity search.

__init__(m, before_id=None, default_year=2024, default_color='#0000ff', default_threshold=0.8)

A widget for similarity search.

Parameters:

Name Type Description Default
m Map

The map to add the widget to.

required
before_id str

The ID of the layer to add the widget to.

None
default_year int

The default year to use for the widget. Defaults to 2024.

2024
default_color str

The default color to use for the widget. Defaults to "#0000ff".

'#0000ff'
default_threshold float

The default threshold to use for the widget. Defaults to 0.8.

0.8

Returns:

Type Description

None

TabWidget

Reusable ipyvuetify tab widget.

  • Optional tab header bar
  • Optional per-panel titles (bold text inside each card)
  • Toolbar with title and working Refresh/Help buttons
  • Built‑in Help dialog; provide your own content via set_help_content()
  • Add/remove/rename tabs, set content, observe selection

panel_titles_visible property writable

Get the visibility of the panel titles.

tab_header_visible property writable

Get the visibility of the tab header.

__init__(title='Dashboard', tabs=('Overview', 'Data', 'Settings'), icons=('mdi-view-dashboard', 'mdi-table', 'mdi-cog'), contents=None, dark_topbar=True, show_tab_header=True, show_panel_titles=True, wrap_in_card=True, elevation=2, on_refresh=None, on_help=None)

Initialize the TabWidget.

Parameters:

Name Type Description Default
title str

The title of the dashboard.

'Dashboard'
tabs Iterable[str]

The tabs to display.

('Overview', 'Data', 'Settings')
icons Iterable[str]

The icons to display.

('mdi-view-dashboard', 'mdi-table', 'mdi-cog')
contents Optional[Iterable[Widget]]

The contents of the tabs.

None
dark_topbar bool

Whether to use a dark topbar.

True
show_tab_header bool

Whether to show the tab header.

True
show_panel_titles bool

Whether to show the panel titles.

True
wrap_in_card bool

Whether to wrap the contents in a card.

True
elevation int

The elevation of the tabs.

2
on_refresh Optional[Callable[[], None]]

The function to call when the refresh button is clicked.

None
on_help Optional[Callable[[], None]]

The function to call when the help button is clicked.

None

add_tab(label, icon='mdi-tab', content=None, index=None)

Add a tab to the dashboard.

Parameters:

Name Type Description Default
label str

The label of the tab.

required
icon str

The icon of the tab.

'mdi-tab'
content Optional[Widget]

The content of the tab.

None
index Optional[int]

The index of the tab.

None

close_help_dialog()

Close the help dialog.

open_help_dialog()

Open the help dialog.

remove_tab(index)

Remove a tab from the dashboard.

Parameters:

Name Type Description Default
index int

The index of the tab.

required

set_help_content(content)

Set the content of the help dialog.

Parameters:

Name Type Description Default
content Widget

The content of the help dialog.

required

set_help_title(title)

Set the title of the help dialog.

Parameters:

Name Type Description Default
title str

The title of the help dialog.

required

set_panel_titles_visible(visible)

Set the visibility of the panel titles.

Parameters:

Name Type Description Default
visible bool

Whether to show the panel titles.

required

set_tab_content(index, content)

Set the content of a tab.

Parameters:

Name Type Description Default
index int

The index of the tab.

required
content Widget

The content of the tab.

required

set_tab_header_visible(visible)

Set the visibility of the tab header.

Parameters:

Name Type Description Default
visible bool

Whether to show the tab header.

required

set_tab_icon(index, icon)

Set the icon of a tab.

Parameters:

Name Type Description Default
index int

The index of the tab.

required
icon Optional[str]

The icon of the tab.

required

set_tab_label(index, label)

Set the label of a tab.

Parameters:

Name Type Description Default
index int

The index of the tab.

required
label str

The label of the tab.

required