Skip to content

maplibregl module

leafmap.maplibregl

The maplibregl module provides the Map class for creating interactive maps using the maplibre.ipywidget module.

Container

Bases: Container

A container widget for displaying a map with an optional sidebar.

This class creates a layout with a map on the left and a sidebar on the right. The sidebar can be toggled on or off and can display additional content.

Attributes:

Name Type Description
sidebar_visible bool

Whether the sidebar is visible.

min_width int

Minimum width of the sidebar in pixels.

max_width int

Maximum width of the sidebar in pixels.

map_container Col

The container for the map.

sidebar_content_box VBox

The container for the sidebar content.

toggle_icon Icon

The icon for the toggle button.

toggle_btn Btn

The button to toggle the sidebar.

sidebar Col

The container for the sidebar.

row Row

The main layout row containing the map and sidebar.

__init__(host_map=None, sidebar_visible=True, min_width=250, max_width=300, sidebar_content=None, *args, **kwargs)

Initializes the Container widget.

Parameters:

Name Type Description Default
host_map Optional[Any]

The map object to display in the container. Defaults to None.

None
sidebar_visible bool

Whether the sidebar is visible. Defaults to True.

True
min_width int

Minimum width of the sidebar in pixels. Defaults to 250.

250
max_width int

Maximum width of the sidebar in pixels. Defaults to 300.

300
sidebar_content Optional[Union[VBox, List[Widget]]]

The content to display in the sidebar. Defaults to None.

None
*args Any

Additional positional arguments for the parent class.

()
**kwargs Any

Additional keyword arguments for the parent class.

{}

add_to_map_container(*items)

Append one or more widgets beneath the map (in insertion order).

add_to_sidebar(widget, add_header=True, widget_icon='mdi-tools', close_icon='mdi-close', label='My Tools', background_color='#f5f5f5', height='40px', expanded=True, host_map=None, **kwargs)

Appends a widget to the sidebar content.

Parameters:

Name Type Description Default
widget Optional[Union[Widget, List[Widget]]]

Initial widget(s) to display in the content box.

required
widget_icon str

Icon for the header. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-tools'
close_icon str

Icon for the close button. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-close'
background_color str

Background color of the header. Defaults to "#f5f5f5".

'#f5f5f5'
label str

Text label for the header. Defaults to "My Tools".

'My Tools'
height str

Height of the header. Defaults to "40px".

'40px'
expanded bool

Whether the panel is expanded by default. Defaults to True.

True
*args Any

Additional positional arguments for the parent class.

required
**kwargs Any

Additional keyword arguments for the parent class.

{}

create_map()

Creates a default map object.

Returns:

Name Type Description
Any Any

A default map object.

remove_from_sidebar(widget=None, name=None)

Removes a widget from the sidebar content.

Parameters:

Name Type Description Default
widget Widget

The widget to remove from the sidebar.

None
name str

The name of the widget to remove from the sidebar.

None

set_sidebar_content(content)

Replaces all content in the sidebar (except the toggle button).

Parameters:

Name Type Description Default
content Union[VBox, List[Widget]]

The new content for the sidebar.

required

set_sidebar_width(min_width=None, max_width=None)

Dynamically updates the sidebar's minimum and maximum width.

Parameters:

Name Type Description Default
min_width int

New minimum width in pixels. If None, keep current.

None
max_width int

New maximum width in pixels. If None, keep current.

None

toggle_sidebar(*args, **kwargs)

Toggles the visibility of the sidebar.

Parameters:

Name Type Description Default
*args Any

Additional positional arguments.

()
**kwargs Any

Additional keyword arguments.

{}

update_sidebar_content()

Updates the content of the sidebar based on its visibility. If the sidebar is visible, it displays the toggle button and the sidebar content. If the sidebar is hidden, it only displays the toggle button.

CustomWidget

Bases: ExpansionPanels

A custom expansion panel widget with dynamic widget management.

This widget allows for the creation of an expandable panel with a customizable header and dynamic content. Widgets can be added, removed, or replaced in the content box.

Attributes:

Name Type Description
content_box VBox

A container for holding the widgets displayed in the panel.

panel ExpansionPanel

The main expansion panel containing the header and content.

expanded property

Returns whether the panel is expanded.

__init__(widget=None, widget_icon='mdi-tools', close_icon='mdi-close', label='My Tools', background_color='#f5f5f5', text_color=SIDEBAR_PANEL_TEXT_COLOR, height='40px', expanded=True, host_map=None, *args, **kwargs)

Initializes the CustomWidget.

Parameters:

Name Type Description Default
widget Optional[Union[Widget, List[Widget]]]

Initial widget(s) to display in the content box.

None
widget_icon str

Icon for the header. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-tools'
close_icon str

Icon for the close button. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-close'
background_color str

Background color of the header. Defaults to "#f5f5f5".

'#f5f5f5'
text_color str

Color used for header text and icons. Defaults to SIDEBAR_PANEL_TEXT_COLOR. Override this when passing a darker background_color so the header stays readable.

SIDEBAR_PANEL_TEXT_COLOR
label str

Text label for the header. Defaults to "My Tools".

'My Tools'
height str

Height of the header. Defaults to "40px".

'40px'
expanded bool

Whether the panel is expanded by default. Defaults to True.

True
*args Any

Additional positional arguments for the parent class.

()
**kwargs Any

Additional keyword arguments for the parent class.

{}

add_widget(widget)

Adds a widget to the content box.

Parameters:

Name Type Description Default
widget Widget

The widget to add to the content box.

required

remove_widget(widget)

Removes a widget from the content box.

Parameters:

Name Type Description Default
widget Widget

The widget to remove from the content box.

required

set_widgets(widgets_list)

Replaces all widgets in the content box.

Parameters:

Name Type Description Default
widgets_list List[Widget]

A list of widgets to set as the content of the content box.

required

DateFilterWidget

Bases: VBox

A widget for filtering data based on time range.

__init__(sources, names=None, styles=None, start_date_col='startDatetime', end_date_col='endDatetime', date_col=None, date_format='%Y-%m-%d', min_date=None, max_date=None, file_index=0, group_col=None, match='partial', freq='D', interval=1, map_widget=None)

Initialize the DateFilterWidget.

Parameters:

Name Type Description Default
sources List[Dict[str, Any]]

List of data sources.

required
names List[str]

List of names for the data sources. Defaults to None.

None
styles Dict[str, Any]

Dictionary of styles for the data sources. Defaults to None.

None
start_date_col str

Name of the column containing the start date. Defaults to "startDatetime".

'startDatetime'
end_date_col str

Name of the column containing the end date. Defaults to "endDatetime".

'endDatetime'
date_col str

Name of the column containing the date. Defaults to None.

None
date_format str

Format of the date. Defaults to "%Y-%m-%d".

'%Y-%m-%d'
min_date str

Minimum date. Defaults to None.

None
max_date str

Maximum date. Defaults to None.

None
file_index int

Index of the main file. Defaults to 0.

0
group_col str

Name of the column containing the group. Defaults to None.

None
match str

Match type. Can be "partial" or "exact". Defaults to "partial".

'partial'
freq str

Frequency of the date range. Defaults to "D".

'D'
interval int

Interval of the date range. Defaults to 1.

1
map_widget Map

Map widget. Defaults to None.

None

LayerManagerWidget

Bases: ExpansionPanels

A widget for managing map layers.

This widget provides controls for toggling the visibility, adjusting the opacity, and removing layers from a map. It also includes a master toggle to turn all layers on or off.

Attributes:

Name Type Description
m Map

The map object to manage layers for.

layer_items Dict[str, Dict[str, Widget]]

A dictionary mapping layer names to their corresponding control widgets (checkbox and slider).

_building bool

A flag indicating whether the widget is currently being built.

master_toggle Checkbox

A checkbox to toggle all layers on or off.

layers_box VBox

A container for individual layer controls.

__init__(m, expanded=True, height='40px', layer_icon='mdi-layers', close_icon='mdi-close', label='Layers', background_color='#f5f5f5', text_color=SIDEBAR_PANEL_TEXT_COLOR, groups=None, *args, **kwargs)

Initializes the LayerManagerWidget.

Parameters:

Name Type Description Default
m Any

The map object to manage layers for.

required
expanded bool

Whether the expansion panel should be expanded by default. Defaults to True.

True
height str

The height of the header. Defaults to "40px".

'40px'
layer_icon str

The icon for the layer manager. Defaults to "mdi-layers".

'mdi-layers'
close_icon str

The icon for the close button. Defaults to "mdi-close".

'mdi-close'
label str

The label for the layer manager. Defaults to "Layers".

'Layers'
background_color str

The background color of the header. Defaults to "#f5f5f5".

'#f5f5f5'
text_color str

The color used for header text and icons. Defaults to SIDEBAR_PANEL_TEXT_COLOR. Override this when passing a darker background_color so the header stays readable.

SIDEBAR_PANEL_TEXT_COLOR
groups dict

A dictionary of layer groups, such as {"Group 1": ["layer1", "layer2"], "Group 2": ["layer3", "layer4"]}. A group layer toggle will be created for each group. Defaults to None.

None
*args Any

Additional positional arguments for the parent class.

()
**kwargs Any

Additional keyword arguments for the parent class.

{}

build_layer_controls()

Builds the controls for individual layers.

This method creates checkboxes for toggling visibility, sliders for adjusting opacity, and buttons for removing layers.

refresh()

Rebuilds the UI to reflect the current layers in the map.

set_layer_opacity(name, opacity)

Sets the opacity of a specific layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
opacity float

The opacity value (0 to 1).

required

set_layer_visibility(name, visible)

Sets the visibility of a specific layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
visible bool

Whether the layer should be visible.

required

toggle_all_layers(change)

Toggles the visibility of all layers.

Parameters:

Name Type Description Default
change Dict[str, Any]

The change event from the master toggle checkbox.

required

toggle_group_layers(change)

Toggles the visibility of a group of layers.

LayerStyleWidget

Bases: VBox

A widget for styling map layers interactively.

Parameters:

Name Type Description Default
layer dict

The layer to style.

required
map_widget Map or Map

The map widget to update.

required
widget_width str

The width of the widget. Defaults to "270px".

'270px'
label_width str

The width of the label. Defaults to "130px".

'130px'

Map

Bases: MapWidget

The Map class inherits from the MapWidget class of the maplibre.ipywidget module.

bounds property

Gets the bounds of the map view state.

Returns:

Name Type Description
tuple tuple

A tuple of two tuples, each containing (lat, lng) coordinates for the southwest and northeast corners of the map view.

first_symbol_layer_id property

Get the ID of the first symbol layer in the map's current style.

layer_names property

Gets layer names as a list.

Returns:

Name Type Description
list list

A list of layer names.

sidebar_widgets property

Returns a dictionary of widgets currently in the sidebar.

Returns:

Type Description
Dict[str, Widget]

Dict[str, widgets.Widget]: A dictionary where keys are the labels of the widgets and values are the widgets themselves.

source_names property

Gets source as a list.

Returns:

Name Type Description
list list

A list of sources.

user_roi property

Gets the first user-drawn ROI feature.

Returns:

Type Description
Optional[dict]

Optional[dict]: The first user-drawn ROI feature or None if no features are drawn.

user_rois property

Gets all user-drawn ROI features.

Returns:

Name Type Description
list list

A list of all user-drawn ROI features.

__init__(center=(0, 20), zoom=1, pitch=0, bearing=0, style='dark-matter', height='600px', controls={'navigation': 'top-right', 'fullscreen': 'top-right', 'scale': 'bottom-left', 'globe': 'top-right'}, projection='mercator', use_message_queue=None, add_sidebar=None, add_floating_sidebar=None, sidebar_visible=False, sidebar_width=360, sidebar_args=None, layer_manager_expanded=True, **kwargs)

Create a Map object.

Parameters:

Name Type Description Default
center tuple

The center of the map (lon, lat). Defaults to (0, 20).

(0, 20)
zoom float

The zoom level of the map. Defaults to 1.

1
pitch float

The pitch of the map. Measured in degrees away from the plane of the screen (0-85) Defaults to 0.

0
bearing float

The bearing of the map. Measured in degrees counter-clockwise from north. Defaults to 0.

0
style str

The style of the map. It can be a string or a URL. If it is a string, it must be one of the following: "dark-matter", "positron", "carto-positron", "voyager", "positron-nolabels", "dark-matter-nolabels", "voyager-nolabels", "demotiles", "liberty", "bright", or "positron2". If a MapTiler API key is set, you can also use any of the MapTiler styles, such as aquarelle, backdrop, basic, bright, dataviz, landscape, ocean, openstreetmap, outdoor, satellite, streets, toner, topo, winter, etc. If it is a URL, it must point to a MapLibre style JSON. Defaults to "dark-matter".

'dark-matter'
height str

The height of the map. Defaults to "600px".

'600px'
controls dict

The controls and their positions on the map. Defaults to {"fullscreen": "top-right", "scale": "bottom-left"}.

{'navigation': 'top-right', 'fullscreen': 'top-right', 'scale': 'bottom-left', 'globe': 'top-right'}
projection str

The projection of the map. It can be "mercator" or "globe". Defaults to "mercator".

'mercator'
use_message_queue bool

Whether to use the message queue. Defaults to None. If None, it will check the environment variable "USE_MESSAGE_QUEUE". If it is set to "True", it will use the message queue, which is needed to export the map to HTML. If it is set to "False", it will not use the message queue, which is needed to display the map multiple times in the same notebook.

None
add_sidebar bool

Whether to add a sidebar to the map. Defaults to False. If True, the map will be displayed in a sidebar.

None
add_floating_sidebar bool

Whether to add a floating sidebar to the map. Defaults to True. If True, the map will be displayed in a floating sidebar.

None
sidebar_visible bool

Whether the sidebar is visible. Defaults to False.

False
sidebar_width int

The width of the sidebar in pixels. Defaults to 360.

360
sidebar_args dict

The arguments for the sidebar. It can be a dictionary with the following keys: "sidebar_visible", "min_width", "max_width", and "sidebar_content". Defaults to None. If None, it will use the default values for the sidebar.

None
layer_manager_expanded bool

Whether the layer manager is expanded. Defaults to True.

True
**kwargs Any

Additional keyword arguments that are passed to the MapOptions class. See https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/ for more information.

{}

Returns:

Type Description

None

add(obj, **kwargs)

Adds a widget or layer to the map based on the type of obj.

If obj is a string and equals "NASA_OPERA", it adds a NASA OPERA data GUI widget to the sidebar. Otherwise, it attempts to add obj as a layer to the map.

Parameters:

Name Type Description Default
obj Union[str, Any]

The object to add to the map. Can be a string or any other type.

required
**kwargs Any

Additional keyword arguments to pass to the widget or layer constructor.

{}

Returns:

Type Description
None

None

add_3d_buildings(name='buildings', min_zoom=15, values=[0, 200, 400], colors=['lightgray', 'royalblue', 'lightblue'], **kwargs)

Adds a 3D buildings layer to the map.

This function creates and adds a 3D buildings layer to the map using fill-extrusion. The buildings' heights are determined by the 'render_height' property, and their colors are interpolated based on specified values. The layer is only visible from a certain zoom level, specified by the 'min_zoom' parameter.

Parameters:

Name Type Description Default
name str

The name of the 3D buildings layer. Defaults to "buildings".

'buildings'
min_zoom int

The minimum zoom level at which the 3D buildings will start to be visible. Defaults to 15.

15
values List[int]

A list of height values (in meters) used for color interpolation. Defaults to [0, 200, 400].

[0, 200, 400]
colors List[str]

A list of colors corresponding to the 'values' list. Each color is applied to the building height range defined by the 'values'. Defaults to ["lightgray", "royalblue", "lightblue"].

['lightgray', 'royalblue', 'lightblue']
**kwargs Any

Additional keyword arguments to pass to the add_layer method.

{}

Raises:

Type Description
ValueError

If the lengths of 'values' and 'colors' lists do not match.

Returns:

Type Description

None

add_alphaearth_gui(start_year=2017, end_year=2024, label='AlphaEarth', widget_icon='mdi-earth', **kwargs)

Adds a AlphaEarth GUI to the map. Earth Engine Dataset: https://developers.google.com/earth-engine/datasets/catalog/GOOGLE_SATELLITE_EMBEDDING_V1_ANNUAL

Parameters:

Name Type Description Default
start_year int

The start year. Defaults to 2017.

2017
end_year int

The end year. Defaults to 2024.

2024
label str

The label of the widget. Defaults to "AlphaEarth".

'AlphaEarth'
widget_icon str

The icon of the widget. Defaults to "mdi-earth".

'mdi-earth'
**kwargs Any

Additional keyword arguments for the add_to_sidebar method.

{}

add_annotation_widget(properties=None, geojson=None, time_format='%Y%m%dT%H%M%S', out_dir=None, filename_prefix='', file_ext='geojson', add_mapillary=False, style='photo', radius=5e-05, width=300, height=420, frame_border=0, download=True, name=None, paint=None, options=None, controls=None, position='top-right', callback=None, add_header=True, widget_icon='mdi-drawing', close_icon='mdi-close', label='Annotation', background_color='#f5f5f5', expanded=True, **kwargs)

Adds an annotation widget to the map.

This method creates a vector data widget for annotations and adds it to the map's sidebar.

Parameters:

Name Type Description Default
properties Optional[Dict[str, List[Any]]]

Properties of the annotation. Defaults to None.

None
time_format str

Format for the timestamp. Defaults to "%Y%m%dT%H%M%S".

'%Y%m%dT%H%M%S'
out_dir Optional[str]

Output directory for the annotation data. Defaults to None.

None
filename_prefix str

Prefix for the filename of the annotation data. Defaults to "".

''
file_ext str

File extension for the annotation data. Defaults to "geojson".

'geojson'
add_mapillary bool

Whether to add Mapillary data. Defaults to False.

False
style str

Style of the annotation. Defaults to "photo".

'photo'
radius float

Radius of the annotation. Defaults to 0.00005.

5e-05
width int

Width of the annotation widget. Defaults to 300.

300
height int

Height of the annotation widget. Defaults to 420.

420
frame_border int

Border width of the annotation widget frame. Defaults to 0.

0
download bool

Whether to allow downloading the annotation data. Defaults to True.

True
name str

Name of the annotation widget. Defaults to None.

None
paint Dict[str, Any]

Paint properties for the annotation. Defaults to None.

None
add_header bool

Whether to add a header to the annotation widget. Defaults to True.

True
widget_icon str

Icon for the annotation widget. Defaults to "mdi-drawing".

'mdi-drawing'
close_icon str

Icon for closing the annotation widget. Defaults to "mdi-close".

'mdi-close'
label str

Label for the annotation widget. Defaults to "Annotation".

'Annotation'
background_color str

Background color of the annotation widget. Defaults to "#f5f5f5".

'#f5f5f5'
expanded bool

Whether the annotation widget is expanded by default. Defaults to True.

True
callback Callable

A callback function to be called when the export button is clicked. Defaults to None.

None
**kwargs Any

Additional keyword arguments for the add_to_sidebar method.

{}

add_arc_layer(data, src_lon, src_lat, dst_lon, dst_lat, src_color=[255, 0, 0], dst_color=[255, 255, 0], line_width=2, layer_id='arc_layer', pickable=True, tooltip=None, **kwargs)

Add a DeckGL ArcLayer to the map.

Parameters:

Name Type Description Default
data Union[str, DataFrame]

The file path or DataFrame containing the data.

required
src_lon str

The source longitude column name.

required
src_lat str

The source latitude column name.

required
dst_lon str

The destination longitude column name.

required
dst_lat str

The destination latitude column name.

required
src_color List[int]

The source color as an RGB list.

[255, 0, 0]
dst_color List[int]

The destination color as an RGB list.

[255, 255, 0]
line_width int

The width of the lines.

2
layer_id str

The ID of the layer.

'arc_layer'
pickable bool

Whether the layer is pickable.

True
tooltip Optional[Union[str, List[str]]]

The tooltip content or list of columns. Defaults to None.

None
**kwargs Any

Additional arguments for the layer.

{}

Returns:

Type Description

None

add_arrow(source, image=None, icon_size=0.1, minzoom=19, name='Arrow', overwrite=False, **kwargs)

Adds an arrow symbol to the map.

Parameters:

Name Type Description Default
source str

The source layer to which the arrow symbol will be added.

required
image Optional[str]

The URL of the arrow image. Defaults to "https://assets.gishub.org/images/right-arrow.png". Find more icons from https://www.veryicon.com.

None
icon_size int

The size of the icon. Defaults to 0.1.

0.1
minzoom Optional[float]

The minimum zoom level at which the arrow symbol will be visible. Defaults to 19.

19
**kwargs Any

Additional keyword arguments to pass to the add_symbol method.

{}

Returns:

Type Description

None

add_basemap(basemap=None, layer_name=None, opacity=1.0, visible=True, attribution=None, before_id=None, **kwargs)

Adds a basemap to the map.

This method adds a basemap to the map. The basemap can be a string from predefined basemaps, an instance of xyzservices.TileProvider, or a key from the basemaps dictionary.

Parameters:

Name Type Description Default
basemap str or TileProvider

The basemap to add. Can be one of the predefined strings, an instance of xyzservices.TileProvider, or a key from the basemaps dictionary. Defaults to None, which adds the basemap widget.

None
opacity float

The opacity of the basemap. Defaults to 1.0.

1.0
visible bool

Whether the basemap is visible or not. Defaults to True.

True
attribution str

The attribution text to display for the basemap. If None, the attribution text is taken from the basemap or the TileProvider. Defaults to None.

None
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
**kwargs Any

Additional keyword arguments that are passed to the RasterTileSource class. See https://bit.ly/4erD2MQ for more information.

{}

Returns:

Type Description

None

Raises:

Type Description
ValueError

If the basemap is not one of the predefined strings, not an instance of TileProvider, and not a key from the basemaps dictionary.

add_cmr_layer(concept_id, datetime=None, backend='rasterio', variable=None, bands=None, bands_regex=None, expression=None, name='CMR Layer', attribution='NASA Earthdata', opacity=1.0, visible=True, rescale=None, colormap_name=None, color_formula=None, titiler_cmr_endpoint=None, fit_bounds=True, before_id=None, overwrite=False, **kwargs)

Adds a NASA Earthdata CMR layer to the map using TiTiler CMR.

This method allows you to visualize NASA Earthdata collections directly on the map using the TiTiler CMR endpoint.

Parameters:

Name Type Description Default
concept_id str

NASA CMR collection concept ID (e.g., 'C2036881735-POCLOUD').

required
datetime str

RFC3339 datetime or range (e.g., '2024-01-15' or '2024-01-01/2024-01-31'). Defaults to None.

None
backend str

Backend to use - 'rasterio' for COGs or 'xarray' for NetCDF/Zarr. Defaults to 'rasterio'.

'rasterio'
variable str

Variable name for xarray backend datasets. Required when using backend='xarray'.

None
bands str | list

Band name(s) for rasterio backend.

None
bands_regex str

Regex pattern for selecting bands (e.g., 'B[0-9][]').

None
expression str

Band math expression (e.g., '(B05-B04)/(B05+B04)').

None
name str

The layer name. Defaults to 'CMR Layer'.

'CMR Layer'
attribution str

Attribution text. Defaults to 'NASA Earthdata'.

'NASA Earthdata'
opacity float

Layer opacity (0.0 to 1.0). Defaults to 1.0.

1.0
visible bool

Whether the layer is visible. Defaults to True.

True
rescale str | list

Min/max values for rescaling (e.g., '270,305' or [[270, 305]]).

None
colormap_name str

Name of colormap (e.g., 'thermal', 'viridis').

None
color_formula str

Color formula (e.g., 'Gamma RGB 3.5 Saturation 1.7').

None
titiler_cmr_endpoint str

TiTiler CMR endpoint URL.

None
fit_bounds bool

Whether to zoom to the layer extent. Defaults to True.

True
before_id str

Layer id to insert before. Defaults to None.

None
overwrite bool

Whether to overwrite an existing layer. Defaults to False.

False
**kwargs Any

Additional arguments passed to the TiTiler CMR endpoint.

{}
Example

import leafmap.maplibregl as leafmap m = leafmap.Map() m.add_cmr_layer( ... concept_id="C2036881735-POCLOUD", ... datetime="2024-01-15", ... backend="xarray", ... variable="analysed_sst", ... rescale="270,305", ... colormap_name="thermal", ... name="Sea Surface Temperature" ... )

add_cog_layer(url, name=None, attribution='', opacity=1.0, visible=True, bands=None, nodata=0, titiler_endpoint=None, fit_bounds=True, before_id=None, overwrite=False, **kwargs)

Adds a Cloud Optimized Geotiff (COG) TileLayer to the map.

This method adds a COG TileLayer to the map. The COG TileLayer is created from the specified URL, and it is added to the map with the specified name, attribution, opacity, visibility, and bands.

Parameters:

Name Type Description Default
url str

The URL of the COG tile layer.

required
name str

The name to use for the layer. If None, a random name is generated. Defaults to None.

None
attribution str

The attribution to use for the layer. Defaults to ''.

''
opacity float

The opacity of the layer. Defaults to 1.0.

1.0
visible bool

Whether the layer should be visible by default. Defaults to True.

True
bands list

A list of bands to use for the layer. Defaults to None.

None
nodata float

The nodata value to use for the layer.

0
titiler_endpoint str

The endpoint of the titiler service. Defaults to "https://titiler.opengeos.org".

None
fit_bounds bool

Whether to adjust the viewport of the map to fit the bounds of the layer. Defaults to True.

True
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Arbitrary keyword arguments, including bidx, expression, nodata, unscale, resampling, rescale, color_formula, colormap, colormap_name, return_mask. See https://developmentseed.org/titiler/endpoints/cog/ and https://cogeotiff.github.io/rio-tiler/colormap/. To select a certain bands, use bidx=[1, 2, 3]. apply a rescaling to multiple bands, use something like rescale=["164,223","130,211","99,212"].

{}

add_colorbar(width=3.0, height=0.2, vmin=0, vmax=1.0, palette=None, vis_params=None, cmap='gray', discrete=False, label=None, label_size=10, label_weight='normal', tick_size=8, bg_color='white', orientation='horizontal', dpi='figure', transparent=False, position='bottom-right', colorbar_args=None, **kwargs)

Add a colorbar to the map.

This function uses matplotlib to generate a colorbar, saves it as a PNG file, and adds it to the map using the Map.add_html() method. The colorbar can be customized in various ways including its size, color palette, label, and orientation.

Parameters:

Name Type Description Default
width Optional[float]

Width of the colorbar in inches. Defaults to 3.0.

3.0
height Optional[float]

Height of the colorbar in inches. Defaults to 0.2.

0.2
vmin Optional[float]

Minimum value of the colorbar. Defaults to 0.

0
vmax Optional[float]

Maximum value of the colorbar. Defaults to 1.0.

1.0
palette Optional[List[str]]

List of colors or a colormap name for the colorbar. Defaults to None.

None
vis_params Optional[Dict[str, Union[str, float, int]]]

Visualization parameters as a dictionary.

None
cmap Optional[str]

Matplotlib colormap name. Defaults to "gray".

'gray'
discrete Optional[bool]

Whether to create a discrete colorbar. Defaults to False.

False
label Optional[str]

Label for the colorbar. Defaults to None.

None
label_size Optional[int]

Font size for the colorbar label. Defaults to 10.

10
label_weight Optional[str]

Font weight for the colorbar label. Defaults to "normal".

'normal'
tick_size Optional[int]

Font size for the colorbar tick labels. Defaults to 8.

8
bg_color Optional[str]

Background color for the colorbar. Defaults to "white".

'white'
orientation Optional[str]

Orientation of the colorbar ("vertical" or "horizontal"). Defaults to "horizontal".

'horizontal'
dpi Optional[Union[str, float]]

Resolution in dots per inch. If 'figure', uses the figure's dpi value. Defaults to "figure".

'figure'
transparent Optional[bool]

Whether the background is transparent. Defaults to False.

False
position str

Position of the colorbar on the map. Defaults to "bottom-right".

'bottom-right'
colorbar_args Optional[Dict[str, Any]]

Additional keyword arguments passed to the colorbar. Can be colorbar_args={"ticks": list(range(0, 101, 10))}. Defaults to None.

None
**kwargs Any

Additional keyword arguments passed to matplotlib.pyplot.savefig().

{}

Returns:

Name Type Description
str str

Path to the generated colorbar image.

add_colorbar_to_sidebar(width=3.0, height=0.2, vmin=0, vmax=1.0, palette=None, vis_params=None, cmap='gray', discrete=False, label=None, label_size=10, label_weight='normal', tick_size=8, bg_color='white', orientation='horizontal', dpi='figure', transparent=False, add_header=True, widget_icon='mdi-format-color-fill', close_icon='mdi-close', header_label='Colorbar', header_color='#f5f5f5', header_height='40px', expanded=True, **kwargs)

Add a colorbar to the sidebar.

This function uses matplotlib to generate a colorbar, saves it as a PNG file, and adds it to the map using the Map.add_html_to_sidebar() method. The colorbar can be customized in various ways including its size, color palette, label, and orientation.

Parameters:

Name Type Description Default
width Optional[float]

Width of the colorbar in inches. Defaults to 3.0.

3.0
height Optional[float]

Height of the colorbar in inches. Defaults to 0.2.

0.2
vmin Optional[float]

Minimum value of the colorbar. Defaults to 0.

0
vmax Optional[float]

Maximum value of the colorbar. Defaults to 1.0.

1.0
palette Optional[List[str]]

List of colors or a colormap name for the colorbar. Defaults to None.

None
vis_params Optional[Dict[str, Union[str, float, int]]]

Visualization parameters as a dictionary.

None
cmap Optional[str]

Matplotlib colormap name. Defaults to "gray".

'gray'
discrete Optional[bool]

Whether to create a discrete colorbar. Defaults to False.

False
label Optional[str]

Label for the colorbar. Defaults to None.

None
label_size Optional[int]

Font size for the colorbar label. Defaults to 10.

10
label_weight Optional[str]

Font weight for the colorbar label. Defaults to "normal".

'normal'
tick_size Optional[int]

Font size for the colorbar tick labels. Defaults to 8.

8
bg_color Optional[str]

Background color for the colorbar. Defaults to "white".

'white'
orientation Optional[str]

Orientation of the colorbar ("vertical" or "horizontal"). Defaults to "horizontal".

'horizontal'
dpi Optional[Union[str, float]]

Resolution in dots per inch. If 'figure', uses the figure's dpi value. Defaults to "figure".

'figure'
transparent Optional[bool]

Whether the background is transparent. Defaults to False.

False
add_header bool

If True, adds a header to the colorbar. Defaults to True.

True
widget_icon str

Icon for the header. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-format-color-fill'
close_icon str

Icon for the close button. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-close'
background_color str

Background color of the header. Defaults to "#f5f5f5".

required
label str

Text label for the header. Defaults to "My Tools".

None
height str

Height of the header. Defaults to "40px".

0.2
expanded bool

Whether the panel is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for the parent class.

{}

Returns:

Name Type Description
str str

Path to the generated colorbar image.

add_control(control, position='top-right', **kwargs)

Adds a control to the map.

This method adds a control to the map. The control can be one of the following: 'scale', 'fullscreen', 'geolocate', 'navigation', "attribution", and "draw". If the control is a string, it is converted to the corresponding control object. If the control is not a string, it is assumed to be a control object.

Parameters:

Name Type Description Default
control str or object

The control to add to the map. Can be one of the following: 'scale', 'fullscreen', 'geolocate', 'navigation', "attribution", and "draw".

required
position str

The position of the control. Defaults to "top-right".

'top-right'
**kwargs Any

Additional keyword arguments that are passed to the control object.

{}

Returns:

Type Description
None

None

Raises:

Type Description
ValueError

If the control is a string and is not one of the following: 'scale', 'fullscreen', 'geolocate', 'navigation', "attribution".

add_data(data, column, cmap=None, colors=None, labels=None, scheme='Quantiles', k=5, add_legend=True, legend_title=None, legend_position='bottom-right', legend_kwds=None, classification_kwds=None, legend_args=None, layer_type=None, extrude=False, scale_factor=1.0, filter=None, paint=None, outline_color='rgba(255, 255, 255, 255)', name=None, fit_bounds=True, visible=True, opacity=1.0, before_id=None, source_args={}, **kwargs)

Add vector data to the map with a variety of classification schemes.

Parameters:

Name Type Description Default
data str | DataFrame | GeoDataFrame

The data to classify. It can be a filepath to a vector dataset, a pandas dataframe, or a geopandas geodataframe.

required
column str

The column to classify.

required
cmap str

The name of a colormap recognized by matplotlib. Defaults to None.

None
colors list

A list of colors to use for the classification. Defaults to None.

None
labels list

A list of labels to use for the legend. Defaults to None.

None
scheme str

Name of a choropleth classification scheme (requires mapclassify). Name of a choropleth classification scheme (requires mapclassify). A mapclassify.MapClassifier object will be used under the hood. Supported are all schemes provided by mapclassify (e.g. 'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled', 'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced', 'JenksCaspallSampled', 'MaxP', 'MaximumBreaks', 'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean', 'UserDefined'). Arguments can be passed in classification_kwds.

'Quantiles'
k int

Number of classes (ignored if scheme is None or if column is categorical). Default to 5.

5
add_legend bool

Whether to add a legend to the map. Defaults to True.

True
legend_title str

The title of the legend. Defaults to None.

None
legend_position str

The position of the legend. Can be 'top-left', 'top-right', 'bottom-left', or 'bottom-right'. Defaults to 'bottom-right'.

'bottom-right'
legend_kwds dict

Keyword arguments to pass to :func:matplotlib.pyplot.legend or matplotlib.pyplot.colorbar. Defaults to None. Keyword arguments to pass to :func:matplotlib.pyplot.legend or Additional accepted keywords when scheme is specified: fmt : string A formatting specification for the bin edges of the classes in the legend. For example, to have no decimals: {"fmt": "{:.0f}"}. labels : list-like A list of legend labels to override the auto-generated labblels. Needs to have the same number of elements as the number of classes (k). interval : boolean (default False) An option to control brackets from mapclassify legend. If True, open/closed interval brackets are shown in the legend.

None
classification_kwds dict

Keyword arguments to pass to mapclassify. Defaults to None.

None
legend_args dict

Additional keyword arguments for the add_legend method. Defaults to None.

None
layer_type str

The type of layer to add. Can be 'circle', 'line', or 'fill'. Defaults to None.

None
filter dict

The filter to apply to the layer. If None, no filter is applied.

None
paint dict

The paint properties to apply to the layer. If None, no paint properties are applied.

None
outline_color str

The color of the outline of the layer. Defaults to "rgba(255, 255, 255, 255)".

'rgba(255, 255, 255, 255)'
name str

The name of the layer. If None, a random name is generated.

None
fit_bounds bool

Whether to adjust the viewport of the map to fit the bounds of the GeoJSON data. Defaults to True.

True
visible bool

Whether the layer is visible or not. Defaults to True.

True
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
source_args dict

Additional keyword arguments that are passed to the GeoJSONSource class.

{}
**kwargs Any

Additional keyword arguments to pass to the GeoJSON class, such as fields, which can be a list of column names to be included in the popup.

{}

add_date_filter_widget(sources, names=None, styles=None, start_date_col='startDate', end_date_col='endDate', date_col=None, date_format='%Y-%m-%d', min_date=None, max_date=None, file_index=0, group_col=None, freq='D', interval=1, add_header=True, widget_icon='mdi-filter', close_icon='mdi-close', label='Date Filter', background_color='#f5f5f5', height='40px', expanded=True, **kwargs)

Initialize the DateFilterWidget.

Parameters:

Name Type Description Default
sources List[Dict[str, Any]]

List of data sources.

required
names List[str]

List of names for the data sources. Defaults to None.

None
styles Dict[str, Any]

Dictionary of styles for the data sources. Defaults to None.

None
start_date_col str

Name of the column containing the start date. Defaults to "startDate".

'startDate'
end_date_col str

Name of the column containing the end date. Defaults to "endDate".

'endDate'
date_col str

Name of the column containing the date. Defaults to None.

None
date_format str

Format of the date. Defaults to "%Y-%m-%d".

'%Y-%m-%d'
min_date str

Minimum date. Defaults to None.

None
max_date str

Maximum date. Defaults to None.

None
file_index int

Index of the main file. Defaults to 0.

0
group_col str

Name of the column containing the group. Defaults to None.

None
freq str

Frequency of the date range. Defaults to "D".

'D'
unit str

Unit of the date. Defaults to "ms".

required
interval int

Interval of the date range. Defaults to 1.

1
add_header bool

Whether to add a header to the widget. Defaults to True.

True
widget_icon str

Icon of the widget. Defaults to "mdi-filter".

'mdi-filter'
close_icon str

Icon of the close button. Defaults to "mdi-close".

'mdi-close'
label str

Label of the widget. Defaults to "Date Filter".

'Date Filter'
background_color str

Background color of the widget. Defaults to "#f5f5f5".

'#f5f5f5'
height str

Height of the widget. Defaults to "40px".

'40px'
expanded bool

Whether the widget is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for the add_to_sidebar method.

{}

add_deck_layers(layers, tooltip=None, columns=None)

Add Deck.GL layers to the layer stack

Parameters:

Name Type Description Default
layers list[dict]

A list of dictionaries containing the Deck.GL layers to be added.

required
tooltip str | dict

Either a single mustache template string applied to all layers or a dictionary where keys are layer ids and values are mustache template strings.

None
columns list[str]

A list of column names to be used for the tooltip.

None

add_draw_control(options=None, controls=None, position='top-right', geojson=None, **kwargs)

Adds a drawing control to the map.

This method enables users to add interactive drawing controls to the map, allowing for the creation, editing, and deletion of geometric shapes on the map. The options, position, and initial GeoJSON can be customized.

Parameters:

Name Type Description Default
options Optional[Dict[str, Any]]

Configuration options for the drawing control. Defaults to None.

None
controls Optional[Dict[str, Any]]

The drawing controls to enable. Can be one or more of the following: 'polygon', 'line_string', 'point', 'trash', 'combine_features', 'uncombine_features'. Defaults to None.

None
position str

The position of the control on the map. Defaults to "top-right".

'top-right'
geojson Optional[Dict[str, Any]]

Initial GeoJSON data to load into the drawing control. Defaults to None.

None
**kwargs Any

Additional keyword arguments to be passed to the drawing control.

{}

Returns:

Type Description

None

add_duckdb_layer(data=None, layer_name=None, layer_type='fill', paint=None, layout=None, filter=None, database_path=None, table_name='features', geom_column='geom', properties=None, port=8000, minzoom=0, maxzoom=22, min_zoom=None, visible=True, opacity=1.0, fit_bounds=True, tooltip=True, quiet=False, use_view=False, src_crs=None, **kwargs)

Adds a layer served from a DuckDB database via vector tiles.

This method enables visualization of large vector datasets by serving them as vector tiles through a local Flask server backed by DuckDB. The data can either be loaded from various sources into a new/existing database, or you can connect to an existing database that already contains the data.

Supports all vector formats that DuckDB's ST_Read can handle, including GeoJSON, Shapefile, GeoPackage, FlatGeobuf, GeoParquet, and many more GDAL-supported formats.

For remote Jupyter environments, you need to configure leafmap with your JupyterHub URL:

1
2
import leafmap
leafmap.configure_jupyterhub("https://your-jupyterhub-domain.com")

Parameters:

Name Type Description Default
data optional

The spatial data to visualize. Can be: - Path to a vector file (any format supported by DuckDB's ST_Read: GeoJSON, Shapefile, GeoPackage, FlatGeobuf, GeoParquet, etc.) - GeoJSON dictionary - GeoDataFrame - None (if using an existing database with data already loaded)

None
layer_name str

Name for the layer. If None, generates a unique name.

None
layer_type str

MapLibre layer type ('fill', 'line', 'circle', 'symbol'). Defaults to 'fill'.

'fill'
paint dict

Paint properties for the layer. If None, uses defaults based on layer_type.

None
layout dict

Layout properties for the layer.

None
filter dict

Filter expression for the layer.

None
database_path str

Path to DuckDB database file. - If None and data is provided: creates a temporary database - If provided with data: loads data into this database - If provided without data: uses existing database (data must already be loaded)

None
table_name str

Name of the table in DuckDB. Defaults to "features".

'features'
geom_column str

Name of geometry column. Defaults to "geom".

'geom'
properties list

List of property columns to include in tiles. If None, includes all columns.

None
port int

Port for the tile server. Defaults to 8000. If port is in use, automatically selects next available port.

8000
minzoom int

Minimum zoom level for the MapLibre layer. Defaults to 0.

0
maxzoom int

Maximum zoom level for the MapLibre layer. Defaults to 22.

22
min_zoom int

Minimum zoom level at which to query and serve tiles. Below this zoom level, empty tiles will be returned, preventing memory issues with large datasets. Use this to defer data loading until users zoom in closer. If None, tiles will be served at all zoom levels. Defaults to None.

None
visible bool

Whether layer is visible initially. Defaults to True.

True
opacity float

Layer opacity (0-1). Defaults to 1.0.

1.0
fit_bounds bool

Whether to zoom to layer extent. Defaults to True.

True
tooltip bool

Whether to add tooltips. Defaults to True.

True
quiet bool

If True, suppress progress messages. Defaults to False.

False
use_view bool

If True and data is a parquet file, create a view instead of a table. Views avoid data duplication but may be slower for tile serving as they query the source file on each tile request. Only applies to parquet files. Defaults to False.

False
src_crs str

Source CRS of the input data as an EPSG code (e.g., 'EPSG:5070', 'EPSG:4326'). If None, will attempt to auto-detect. Specify this parameter if the data is in a projected CRS that is not Web Mercator to ensure proper transformation. Defaults to None.

None
**kwargs Any

Additional arguments passed to the layer configuration.

{}

Returns:

Type Description

None

Raises:

Type Description
ImportError

If duckdb, flask, or flask-cors are not installed.

ValueError

If neither data nor database_path is provided.

Example

import leafmap.maplibregl as leafmap m = leafmap.Map()

Example 1: Load GeoJSON (creates temporary database)

m.add_duckdb_layer( ... data="large_dataset.geojson", ... layer_name="buildings", ... layer_type="fill", ... paint={"fill-color": "#3388ff", "fill-opacity": 0.7} ... )

Example 2: Load Shapefile

m.add_duckdb_layer( ... data="boundaries.shp", ... layer_name="boundaries", ... layer_type="line", ... paint={"line-color": "#ff0000", "line-width": 2} ... )

Example 3: Load GeoPackage

m.add_duckdb_layer( ... data="data.gpkg", ... layer_name="parcels", ... database_path="parcels.db" ... )

Example 4: Load GeoParquet (very efficient for large datasets)

m.add_duckdb_layer( ... data="large_dataset.parquet", ... layer_name="large_layer" ... )

Example 5: Load from GeoDataFrame

import geopandas as gpd gdf = gpd.read_file("data.geojson") m.add_duckdb_layer( ... data=gdf, ... layer_name="from_gdf" ... )

Example 6: Use existing database (no data loading)

m.add_duckdb_layer( ... database_path="existing_data.db", ... table_name="my_table", ... geom_column="geometry", ... layer_name="existing_layer" ... )

Example 7: Large parquet file with min_zoom to prevent memory issues

m.add_duckdb_layer( ... data="huge_dataset.parquet", ... layer_name="huge_layer", ... min_zoom=8, # Only load tiles at zoom level 8 and above ... layer_type="fill", ... paint={"fill-color": "#ff0000", "fill-opacity": 0.5} ... )

add_ee_layer(ee_object=None, vis_params={}, name=None, asset_id=None, opacity=1.0, attribution='Google Earth Engine', visible=True, before_id=None, ee_initialize=False, overwrite=False, **kwargs)

Adds a Google Earth Engine tile layer to the map based on the tile layer URL from https://github.com/opengeos/ee-tile-layers/blob/main/datasets.tsv.

Parameters:

Name Type Description Default
ee_object object

The Earth Engine object to display.

None
vis_params dict

Visualization parameters. For example, {'min': 0, 'max': 100}.

{}
name str

The name of the tile layer. If not provided, the asset ID will be used. Default is None.

None
asset_id str

The ID of the Earth Engine asset.

None
opacity float

The opacity of the tile layer (0 to 1). Default is 1.

1.0
attribution str

The attribution text to be displayed. Default is "Google Earth Engine".

'Google Earth Engine'
visible bool

Whether the tile layer should be shown on the map. Default is True.

True
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
ee_initialize bool

Whether to initialize the Earth Engine account. Default is False.

False
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments to be passed to the underlying add_tile_layer method.

{}

Returns:

Type Description

None

add_floating_sidebar(position='top-left', width='370px', max_height='80vh', expanded=True, sidebar_visible=False, sidebar_content=None, **kwargs)

Adds a floating sidebar panel overlaid on the map with a toggle button.

This method creates a floating sidebar that appears as an overlay on the map canvas. The sidebar includes a toggle button to show/hide it, along with the layer manager and any additional content you specify.

Parameters:

Name Type Description Default
position str

Position on the map. Can be "top-right", "top-left", "bottom-right", or "bottom-left". Defaults to "top-left".

'top-left'
width str

Width of the sidebar (e.g., "370px", "25%"). Defaults to "370px".

'370px'
max_height str

Maximum height of the sidebar (e.g., "80vh", "500px"). Defaults to "80vh".

'80vh'
expanded bool

Whether the layer manager starts expanded. Defaults to True.

True
sidebar_visible bool

Whether the sidebar content is initially visible. Defaults to False. The toggle button is always visible.

False
sidebar_content Optional[List[Widget]]

Additional widgets to include in the sidebar. Defaults to None (only layer manager).

None
**kwargs Any

Additional keyword arguments passed to LayerManagerWidget.

{}

Returns:

Type Description
Widget

widgets.Widget: A widget containing the map with the floating sidebar overlay. Display this instead of the map object.

Example

m = leafmap.Map() m.add_basemap("Esri.WorldImagery") widget = m.add_floating_sidebar(position="top-left", width="360px") widget # Display the returned widget

add_gdf(gdf, layer_type=None, filter=None, paint=None, name=None, fit_bounds=True, visible=True, before_id=None, source_args={}, overwrite=False, **kwargs)

Adds a vector layer to the map.

This method adds a GeoDataFrame to the map as a vector layer.

Parameters:

Name Type Description Default
gdf GeoDataFrame

The GeoDataFrame to add to the map.

required
layer_type str

The type of the layer. If None, the type is inferred from the GeoJSON data.

None
filter dict

The filter to apply to the layer. If None, no filter is applied.

None
paint dict

The paint properties to apply to the layer. If None, no paint properties are applied.

None
name str

The name of the layer. If None, a random name is generated.

None
fit_bounds bool

Whether to adjust the viewport of the map to fit the bounds of the GeoJSON data. Defaults to True.

True
visible bool

Whether the layer is visible or not. Defaults to True.

True
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
source_args dict

Additional keyword arguments that are passed to the GeoJSONSource class.

{}
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments that are passed to the Layer class.

{}

Returns:

Type Description

None

Raises:

Type Description
ValueError

If the data is not a URL or a GeoJSON dictionary.

add_geojson(data, layer_type=None, filter=None, paint=None, name=None, fit_bounds=True, visible=True, before_id=None, source_args={}, fit_bounds_options=None, overwrite=False, **kwargs)

Adds a GeoJSON layer to the map.

This method adds a GeoJSON layer to the map. The GeoJSON data can be a URL to a GeoJSON file or a GeoJSON dictionary. If a name is provided, it is used as the key to store the layer in the layer dictionary. Otherwise, a random name is generated.

Parameters:

Name Type Description Default
data str | dict

The GeoJSON data. This can be a URL to a GeoJSON file or a GeoJSON dictionary.

required
layer_type str

The type of the layer. It can be one of the following: 'circle', 'fill', 'fill-extrusion', 'line', 'symbol', 'raster', 'background', 'heatmap', 'hillshade'. If None, the type is inferred from the GeoJSON data.

None
filter dict

The filter to apply to the layer. If None, no filter is applied.

None
paint dict

The paint properties to apply to the layer. If None, no paint properties are applied.

None
name str

The name of the layer. If None, a random name is generated.

None
fit_bounds bool

Whether to adjust the viewport of the map to fit the bounds of the GeoJSON data. Defaults to True.

True
visible bool

Whether the layer is visible or not. Defaults to True.

True
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
source_args dict

Additional keyword arguments that are passed to the GeoJSONSource class.

{}
fit_bounds_options dict

Additional options for fitting the bounds. See https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/FitBoundsOptions for more information.

None
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments that are passed to the Layer class. See https://maplibre.org/maplibre-style-spec/layers/ for more info.

{}

Returns:

Type Description

None

Raises:

Type Description
ValueError

If the data is not a URL or a GeoJSON dictionary.

add_globe_control(position='top-right', **kwargs)

Adds a globe control to the map.

This method adds a globe control to the map, allowing users to switch between 2D and 3D views. The position of the control can be customized.

Parameters:

Name Type Description Default
position str

The position of the control on the map. Defaults to "top-right".

'top-right'
**kwargs Any

Additional keyword arguments to be passed to the globe control.

{}

Returns:

Type Description
None

None

add_gps_trace(data, x=None, y=None, columns=None, ann_column=None, colormap=None, radius=5, circle_color=None, stroke_color='#ffffff', opacity=1.0, paint=None, name='GPS Trace', add_line=True, sort_column=None, line_args=None, add_draw_control=True, draw_control_args=None, add_legend=True, legend_args=None, **kwargs)

Adds a GPS trace to the map.

Parameters:

Name Type Description Default
data Union[str, List[Dict[str, Any]]]

The GPS trace data. It can be a GeoJSON file path or a list of coordinates.

required
x str

The column name for the x coordinates. Defaults to None, which assumes the x coordinates are in the "longitude", "lon", or "x" column.

None
y str

The column name for the y coordinates. Defaults to None, which assumes the y coordinates are in the "latitude", "lat", or "y" column.

None
columns Optional[List[str]]

The list of columns to include in the GeoDataFrame. Defaults to None.

None
ann_column Optional[str]

The column name to use for coloring the GPS trace points. Defaults to None.

None
colormap Optional[Dict[str, str]]

The colormap for the GPS trace. Defaults to None.

None
radius int

The radius of the GPS trace points. Defaults to 5.

5
circle_color Optional[Union[str, List[Any]]]

The color of the GPS trace points. Defaults to None.

None
stroke_color str

The stroke color of the GPS trace points. Defaults to "#ffffff".

'#ffffff'
opacity float

The opacity of the GPS trace points. Defaults to 1.0.

1.0
paint Optional[Dict[str, Any]]

The paint properties for the GPS trace points. Defaults to None.

None
name str

The name of the GPS trace layer. Defaults to "GPS Trace".

'GPS Trace'
add_line bool

If True, adds a line connecting the GPS trace points. Defaults to True.

True
sort_column Optional[str]

The column name to sort the points before connecting them as a line. Defaults to None.

None
line_args Optional[Dict[str, Any]]

Additional keyword arguments for the add_gdf method for the line layer. Defaults to None.

None
add_draw_control bool

If True, adds a draw control to the map. Defaults to True.

True
draw_control_args Optional[Dict[str, Any]]

Additional keyword arguments for the add_draw_control method. Defaults to None.

None
add_legend bool

If True, adds a legend to the map. Defaults to True.

True
legend_args Optional[Dict[str, Any]]

Additional keyword arguments for the add_legend method. Defaults to None.

None
**kwargs Any

Additional keyword arguments to pass to the add_geojson method.

{}

Returns:

Type Description

None

add_html(html, bg_color='white', position='bottom-right', **kwargs)

Add HTML content to the map.

This method allows for the addition of arbitrary HTML content to the map, which can be used to display custom information or controls. The background color and position of the HTML content can be customized.

Parameters:

Name Type Description Default
html str

The HTML content to add.

required
bg_color str

The background color of the HTML content. Defaults to "white". To make the background transparent, set this to "transparent". To make the background half transparent, set this to "rgba(255, 255, 255, 0.5)".

'white'
position str

The position of the HTML content on the map. Can be one of "top-left", "top-right", "bottom-left", "bottom-right". Defaults to "bottom-right".

'bottom-right'
**kwargs Union[str, int, float]

Additional keyword arguments for future use.

{}

Returns:

Type Description
None

None

add_html_to_sidebar(html, add_header=True, widget_icon='mdi-language-html5', close_icon='mdi-close', label='HTML', background_color='#f5f5f5', height='40px', expanded=True, **kwargs)

Add HTML content to the map.

This method allows for the addition of arbitrary HTML content to the sidebar, which can be used to display custom information or controls.

Parameters:

Name Type Description Default
html str

The HTML content to add.

required
widget_icon str

Icon for the header. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-language-html5'
close_icon str

Icon for the close button. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-close'
background_color str

Background color of the header. Defaults to "#f5f5f5".

'#f5f5f5'
label str

Text label for the header. Defaults to "My Tools".

'HTML'
height str

Height of the header. Defaults to "40px".

'40px'
expanded bool

Whether the panel is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for the parent class.

{}

Returns:

Type Description

None

add_image(id=None, image=None, width=None, height=None, coordinates=None, position=None, icon_size=1.0, **kwargs)

Add an image to the map.

Parameters:

Name Type Description Default
id str

The layer ID of the image.

None
image Union[str, Dict, ndarray]

The URL or local file path to the image, or a dictionary containing image data, or a numpy array representing the image.

None
width int

The width of the image. Defaults to None.

None
height int

The height of the image. Defaults to None.

None
coordinates List[float]

The longitude and latitude coordinates to place the image.

None
position str

The position of the image. Defaults to None. Can be one of 'top-right', 'top-left', 'bottom-right', 'bottom-left'.

None
icon_size float

The size of the icon. Defaults to 1.0.

1.0

Returns:

Type Description

None

add_image_to_sidebar(image=None, width=None, height=None, add_header=True, widget_icon='mdi-image', close_icon='mdi-close', label='Image', background_color='#f5f5f5', header_height='40px', expanded=True, **kwargs)

Add an image to the map.

Parameters:

Name Type Description Default
id str

The layer ID of the image.

required
image Union[str, Dict, ndarray]

The URL or local file path to the image, or a dictionary containing image data, or a numpy array representing the image.

None
width int

The width of the image. Defaults to None.

None
height int

The height of the image. Defaults to None.

None
widget_icon str

Icon for the header. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-image'
close_icon str

Icon for the close button. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-close'
background_color str

Background color of the header. Defaults to "#f5f5f5".

'#f5f5f5'
label str

Text label for the header. Defaults to "My Tools".

'Image'
header_height str

Height of the header. Defaults to "40px".

'40px'
expanded bool

Whether the panel is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for the parent class.

{}

Returns:

Type Description

None

add_labels(source, column, name=None, text_size=14, text_anchor='center', text_color='black', min_zoom=None, max_zoom=None, layout=None, paint=None, before_id=None, opacity=1.0, visible=True, **kwargs)

Adds a label layer to the map.

This method adds a label layer to the map using the specified source and column for text values.

Parameters:

Name Type Description Default
source Union[str, Dict[str, Any]]

The data source for the labels. It can be a GeoJSON file path or a dictionary containing GeoJSON data.

required
column str

The column name in the source data to use for the label text.

required
name Optional[str]

The name of the label layer. If None, a random name is generated. Defaults to None.

None
text_size int

The size of the label text. Defaults to 14.

14
text_anchor str

The anchor position of the text. Can be "center", "left", "right", etc. Defaults to "center".

'center'
text_color str

The color of the label text. Defaults to "black".

'black'
min_zoom Optional[float]

The minimum zoom level at which the labels are visible. Defaults to None.

None
max_zoom Optional[float]

The maximum zoom level at which the labels are visible. Defaults to None.

None
layout Optional[Dict[str, Any]]

Additional layout properties for the label layer. Defaults to None. For more information, refer to https://maplibre.org/maplibre-style-spec/layers/#symbol.

None
paint Optional[Dict[str, Any]]

Additional paint properties for the label layer. Defaults to None.

None
before_id Optional[str]

The ID of an existing layer before which the new layer should be inserted. Defaults to None.

None
opacity float

The opacity of the label layer. Defaults to 1.0.

1.0
visible bool

Whether the label layer is visible by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments to customize the label layer.

{}

Returns:

Type Description

None

add_layer(layer, before_id=None, name=None, opacity=1.0, visible=True, overwrite=False)

Adds a layer to the map.

This method adds a layer to the map. If a name is provided, it is used as the key to store the layer in the layer dictionary. Otherwise, the layer's ID is used as the key. If a before_id is provided, the layer is inserted before the layer with that ID.

Parameters:

Name Type Description Default
layer Layer

The layer object to add to the map.

required
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
name str

The name to use as the key to store the layer in the layer dictionary. If None, the layer's ID is used as the key.

None
opacity float

The opacity of the layer. Defaults to 1.0.

1.0
visible bool

Whether the layer is visible by default.

True
overwrite bool

If True, the function will return the original name even if it exists in the list. Defaults to False.

False

Returns:

Type Description
None

None

add_layer_control(layer_ids=None, theme='default', css_text=None, position='top-left', bg_layers=False)

Adds a layer control to the map.

This function creates and adds a layer switcher control to the map, allowing users to toggle the visibility of specified layers. The appearance and functionality of the layer control can be customized with parameters such as theme, CSS styling, and position on the map.

Parameters:

Name Type Description Default
layer_ids Optional[List[str]]

A list of layer IDs to include in the control. If None, all layers in the map will be included. Defaults to None.

None
theme str

The theme for the layer switcher control. Can be "default" or other custom themes. Defaults to "default".

'default'
css_text Optional[str]

Custom CSS text for styling the layer control. If None, a default style will be applied. Defaults to None.

None
position str

The position of the layer control on the map. Can be "top-left", "top-right", "bottom-left", or "bottom-right". Defaults to "top-left".

'top-left'
bg_layers bool

If True, background layers will be included in the control. Defaults to False.

False

Returns:

Type Description
None

None

add_legend(title='Legend', legend_dict=None, labels=None, colors=None, fontsize=15, bg_color='white', position='bottom-right', builtin_legend=None, shape_type='rectangle', **kwargs)

Adds a legend to the map.

This method allows for the addition of a legend to the map. The legend can be customized with a title, labels, colors, and more. A built-in legend can also be specified.

Parameters:

Name Type Description Default
title str

The title of the legend. Defaults to "Legend".

'Legend'
legend_dict Optional[Dict[str, str]]

A dictionary with legend items as keys and colors as values. If provided, labels and colors will be ignored. Defaults to None.

None
labels Optional[List[str]]

A list of legend labels. Defaults to None.

None
colors Optional[List[str]]

A list of colors corresponding to the labels. Defaults to None.

None
fontsize int

The font size of the legend text. Defaults to 15.

15
bg_color str

The background color of the legend. Defaults to "white". To make the background transparent, set this to "transparent". To make the background half transparent, set this to "rgba(255, 255, 255, 0.5)".

'white'
position str

The position of the legend on the map. Can be one of "top-left", "top-right", "bottom-left", "bottom-right". Defaults to "bottom-right".

'bottom-right'
builtin_legend Optional[str]

The name of a built-in legend to use. Defaults to None.

None
shape_type str

The shape type of the legend items. Can be one of "rectangle", "circle", or "line".

'rectangle'
**kwargs Union[str, int, float]

Additional keyword arguments for future use.

{}

Returns:

Type Description
None

None

add_legend_to_sidebar(title='Legend', legend_dict=None, labels=None, colors=None, builtin_legend=None, shape_type='rectangle', add_header=True, widget_icon='mdi-view-sequential', close_icon='mdi-close', label='Legend', background_color='#f5f5f5', height='40px', expanded=True, **kwargs)

Adds a legend to the map.

This method allows for the addition of a legend to the map. The legend can be customized with a title, labels, colors, and more. A built-in legend can also be specified.

Parameters:

Name Type Description Default
title str

The title of the legend. Defaults to "Legend".

'Legend'
legend_dict Optional[Dict[str, str]]

A dictionary with legend items as keys and colors as values. If provided, labels and colors will be ignored. Defaults to None.

None
labels Optional[List[str]]

A list of legend labels. Defaults to None.

None
colors Optional[List[str]]

A list of colors corresponding to the labels. Defaults to None.

None
builtin_legend Optional[str]

The name of a built-in legend to use. Defaults to None.

None
shape_type str

The shape type of the legend items. Can be one of "rectangle", "circle", or "line".

'rectangle'
add_header bool

If True, adds a header to the legend. Defaults to True.

True
widget_icon str

The icon for the legend widget. Defaults to "mdi-view-sequential".

'mdi-view-sequential'
close_icon str

The icon for the close button. Defaults to "mdi-close".

'mdi-close'
label str

The label for the legend widget. Defaults to "Legend".

'Legend'
background_color str

The background color of the legend widget. Defaults to "#f5f5f5".

'#f5f5f5'
height str

The height of the legend widget. Defaults to "40px".

'40px'
expanded bool

If True, the legend widget is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for future use.

{}

Returns:

Type Description

None

add_mapillary(minzoom=6, maxzoom=14, sequence_lyr_name='sequence', image_lyr_name='image', before_id=None, sequence_paint=None, image_paint=None, image_minzoom=17, add_popup=True, access_token=None, opacity=1.0, visible=True, add_to_sidebar=False, style='photo', radius=5e-05, height=420, frame_border=0, default_message='No Mapillary image found', widget_icon='mdi-image', widget_label='Mapillary StreetView', **kwargs)

Adds Mapillary layers to the map.

Parameters:

Name Type Description Default
minzoom int

Minimum zoom level for the Mapillary tiles. Defaults to 6.

6
maxzoom int

Maximum zoom level for the Mapillary tiles. Defaults to 14.

14
sequence_lyr_name str

Name of the sequence layer. Defaults to "sequence".

'sequence'
image_lyr_name str

Name of the image layer. Defaults to "image".

'image'
before_id str

The ID of an existing layer to insert the new layer before. Defaults to None.

None
sequence_paint dict

Paint properties for the sequence layer. Defaults to None.

None
image_paint dict

Paint properties for the image layer. Defaults to None.

None
image_minzoom int

Minimum zoom level for the image layer. Defaults to 17.

17
add_popup bool

Whether to add popups to the layers. Defaults to True.

True
access_token str

Access token for Mapillary API. Defaults to None.

None
opacity float

Opacity of the Mapillary layers. Defaults to 1.0.

1.0
visible bool

Whether the Mapillary layers are visible. Defaults to True.

True

Raises:

Type Description
ValueError

If no access token is provided.

Returns:

Type Description

None

add_marker(marker=None, lng_lat=[], popup={}, options={})

Adds a marker to the map.

Parameters:

Name Type Description Default
marker Marker

A Marker object. Defaults to None.

None
lng_lat List[Union[float, float]]

A list of two floats representing the longitude and latitude of the marker.

[]
popup Optional[str]

The text to display in a popup when the marker is clicked. Defaults to None.

{}
options Optional[Dict]

A dictionary of options to customize the marker. Defaults to None.

{}

Returns:

Type Description
None

None

add_nlcd(years=[2023], add_legend=True, **kwargs)

Adds National Land Cover Database (NLCD) data to the map.

Parameters:

Name Type Description Default
years list

A list of years to add. It can be any of 1985-2023. Defaults to [2023].

[2023]
add_legend bool

Whether to add a legend to the map. Defaults to True.

True
**kwargs

Additional keyword arguments to pass to the add_cog_layer method.

{}

Returns:

Type Description
None

None

add_nwi(data, name='NWI Wetlands', **kwargs)

Adds a National Wetlands Inventory (NWI) layer to the map.

Parameters:

Name Type Description Default
data Union[str, Dict]

The data to add. It can be a URL or a dictionary.

required
name str

The name of the layer. Defaults to "NWI Wetlands".

'NWI Wetlands'
**kwargs

Additional keyword arguments to pass to the add_vector method.

{}

Returns:

Type Description

None

add_nwi_basemap(name='NWI Wetlands', format='image/png', attribution='USFWS', opacity=1.0, visible=True, tile_size=256, before_id=None, overwrite=False, **kwargs)

Adds a NWI Wetlands basemap to the map.

This method adds a NWI Wetlands basemap to the map. The NWI Wetlands basemap is created from the specified URL, and it is added to the map with the specified name, attribution, visibility, and tile size.

Parameters:

Name Type Description Default
name str

The name to use for the layer. Defaults to 'NWI Wetlands'.

'NWI Wetlands'
format str

The format of the tiles in the layer.

'image/png'
attribution str

The attribution to use for the layer. Defaults to ''.

'USFWS'
visible bool

Whether the layer should be visible by default. Defaults to True.

True
tile_size int

The size of the tiles in the layer. Defaults to 256.

256
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments that are passed to the Layer class. See https://eodagmbh.github.io/py-maplibregl/api/layer/ for more information.

{}

Returns:

Type Description

None

add_overture_3d_buildings(release=None, style=None, values=None, colors=None, visible=True, opacity=1.0, tooltip=True, template='simple', fit_bounds=False, **kwargs)

Add 3D buildings from Overture Maps to the map.

Parameters:

Name Type Description Default
release Optional[str]

The release date of the Overture Maps data. Defaults to the latest release. For more info, see https://github.com/OvertureMaps/overture-tiles.

None
style Optional[Dict[str, Any]]

The style dictionary for the buildings. Defaults to None.

None
values Optional[List[int]]

List of height values for color interpolation. Defaults to None.

None
colors Optional[List[str]]

List of colors corresponding to the height values. Defaults to None.

None
visible bool

Whether the buildings layer is visible. Defaults to True.

True
opacity float

The opacity of the buildings layer. Defaults to 1.0.

1.0
tooltip bool

Whether to show tooltips on the buildings. Defaults to True.

True
template str

The template for the tooltip. It can be "simple" or "all". Defaults to "simple".

'simple'
fit_bounds bool

Whether to fit the map bounds to the buildings layer. Defaults to False.

False

Raises:

Type Description
ValueError

If the length of values and colors lists are not the same.

add_overture_buildings(release=None, style=None, type='line', visible=True, opacity=1.0, tooltip=True, fit_bounds=False, **kwargs)

Add Overture Maps data to the map.

Parameters:

Name Type Description Default
release str

The release date of the data. Defaults to "2024-12-18". For more info, see https://github.com/OvertureMaps/overture-tiles

None
style Optional[Dict[str, Any]]

The style dictionary for the data. Defaults to None.

None
type str

The type of the data. It can be "line" or "fill".

'line'
visible bool

Whether the data layer is visible. Defaults to True.

True
opacity float

The opacity of the data layer. Defaults to 1.0.

1.0
tooltip bool

Whether to show tooltips on the data. Defaults to True.

True
fit_bounds bool

Whether to fit the map bounds to the data layer. Defaults to False.

False
**kwargs Any

Additional keyword arguments for the paint properties.

{}

add_overture_data(release=None, theme='buildings', style=None, visible=True, opacity=1.0, tooltip=True, fit_bounds=False, **kwargs)

Add Overture Maps data to the map.

Parameters:

Name Type Description Default
release str

The release date of the data. Defaults to "2024-12-28". For more info, see https://github.com/OvertureMaps/overture-tiles

None
theme str

The theme of the data. It can be one of the following: "addresses", "base", "buildings", "divisions", "places", "transportation". Defaults to "buildings".

'buildings'
style Optional[Dict[str, Any]]

The style dictionary for the data. Defaults to None.

None
visible bool

Whether the data layer is visible. Defaults to True.

True
opacity float

The opacity of the data layer. Defaults to 1.0.

1.0
tooltip bool

Whether to show tooltips on the data. Defaults to True.

True
fit_bounds bool

Whether to fit the map bounds to the data layer. Defaults to False.

False
**kwargs Any

Additional keyword arguments for the add_pmtiles method.

{}

Raises:

Type Description
ValueError

If the theme is not one of the allowed themes.

add_pmtiles(url, style=None, visible=True, opacity=1.0, exclude_mask=False, tooltip=True, properties=None, template=None, attribution='PMTiles', fit_bounds=True, **kwargs)

Adds a PMTiles layer to the map.

Parameters:

Name Type Description Default
url str

The URL of the PMTiles file.

required
style dict

The CSS style to apply to the layer. Defaults to None. See https://docs.mapbox.com/style-spec/reference/layers/ for more info.

None
visible bool

Whether the layer should be shown initially. Defaults to True.

True
opacity float

The opacity of the layer. Defaults to 1.0.

1.0
exclude_mask bool

Whether to exclude the mask layer. Defaults to False.

False
tooltip bool

Whether to show tooltips on the layer. Defaults to True.

True
properties dict

The properties to use for the tooltips. Defaults to None.

None
template str

The template to use for the tooltips. Defaults to None.

None
attribution str

The attribution to use for the layer. Defaults to 'PMTiles'.

'PMTiles'
fit_bounds bool

Whether to zoom to the layer extent. Defaults to True.

True
**kwargs Any

Additional keyword arguments to pass to the PMTilesLayer constructor.

{}

Returns:

Type Description

None

add_polars(df, geometry='geometry', crs=None, layer_type=None, filter=None, paint=None, name=None, fit_bounds=True, visible=True, before_id=None, source_args={}, overwrite=False, **kwargs)

Adds a Polars DataFrame with geometry to the map.

This method supports Polars-ST DataFrames with spatial geometry columns and enables direct visualization of Polars-based geospatial data without manual conversion to GeoPandas.

Parameters:

Name Type Description Default
df

A Polars DataFrame with a geometry column (e.g., from Polars-ST).

required
geometry str

The name of the geometry column. Defaults to "geometry".

'geometry'
crs str

The CRS of the geometry data (e.g., "EPSG:4326"). If None, will try to detect from Polars-ST metadata or default to EPSG:4326.

None
layer_type str

The type of the layer. If None, the type is inferred from the GeoJSON data.

None
filter dict

The filter to apply to the layer. If None, no filter is applied.

None
paint dict

The paint properties to apply to the layer. If None, no paint properties are applied.

None
name str

The name of the layer. If None, a random name is generated.

None
fit_bounds bool

Whether to adjust the viewport of the map to fit the bounds of the GeoJSON data. Defaults to True.

True
visible bool

Whether the layer is visible or not. Defaults to True.

True
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
source_args dict

Additional keyword arguments that are passed to the GeoJSONSource class.

{}
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments that are passed to the Layer class.

{}

Raises:

Type Description
ImportError

If polars or required dependencies are not installed.

ValueError

If the specified geometry column is not found.

TypeError

If the input is not a Polars DataFrame.

Examples:

1
2
3
4
5
>>> import polars as pl
>>> # With Polars-ST
>>> df = pl.read_parquet("data.geoparquet")
>>> m = leafmap.Map()
>>> m.add_polars(df, geometry="geometry", crs="EPSG:4326")

add_raster(source, indexes=None, colormap=None, vmin=None, vmax=None, nodata=None, name='Raster', before_id=None, fit_bounds=True, visible=True, opacity=1.0, array_args={}, client_args={'cors_all': True}, overwrite=True, **kwargs)

Add a local raster dataset to the map. If you are using this function in JupyterHub on a remote server (e.g., Binder, Microsoft Planetary Computer) and if the raster does not render properly, try installing jupyter-server-proxy using pip install jupyter-server-proxy, then running the following code before calling this function. For more info, see https://bit.ly/3JbmF93.

1
2
import os
os.environ['LOCALTILESERVER_CLIENT_PREFIX'] = 'proxy/{port}'

Parameters:

Name Type Description Default
source str

The path to the GeoTIFF file or the URL of the Cloud Optimized GeoTIFF.

required
indexes int

The band(s) to use. Band indexing starts at 1. Defaults to None.

None
colormap str

The name of the colormap from matplotlib to use when plotting a single band. See https://matplotlib.org/stable/gallery/color/colormap_reference.html. Default is greyscale.

None
vmin float

The minimum value to use when colormapping the palette when plotting a single band. Defaults to None.

None
vmax float

The maximum value to use when colormapping the palette when plotting a single band. Defaults to None.

None
nodata float

The value from the band to use to interpret as not valid data. Defaults to None.

None
name str

The layer name to use. Defaults to 'Raster'.

'Raster'
before_id str

The layer id to insert the layer before. Defaults to None.

None
fit_bounds bool

Whether to zoom to the extent of the layer. Defaults to True.

True
visible bool

Whether the layer is visible. Defaults to True.

True
opacity float

The opacity of the layer. Defaults to 1.0.

1.0
array_args dict

Additional arguments to pass to array_to_memory_file when reading the raster. Defaults to {}.

{}
client_args dict

Additional arguments to pass to localtileserver.TileClient. Defaults to { "cors_all": False }.

{'cors_all': True}
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to True.

True
**kwargs Any

Additional keyword arguments to be passed to the underlying add_tile_layer method.

{}

add_search_control(position='top-right', api_key=None, collapsed=True, **kwargs)

Adds a search control to the map.

Parameters:

Name Type Description Default
position str

The position of the control on the map. Defaults to "top-right".

'top-right'
api_key str

The API key for the search control. Defaults to None. If not provided, it will be retrieved from the environment variable MAPTILER_KEY.

None
collapsed bool

Whether the control is collapsed. Defaults to True.

True
**kwargs Any

Additional keyword arguments to be passed to the search control. See https://eoda-dev.github.io/py-maplibregl/api/controls/#maplibre.controls.MapTilerGeocodingControl

{}

add_select_data_widget(default_path='.', widget_width='360px', callback=None, reset_callback=None, add_header=True, widget_icon='mdi-folder', close_icon='mdi-close', label='Data Selection', background_color='#f5f5f5', height='40px', expanded=True, **kwargs)

Adds a select data widget to the map.

This method creates a widget for selecting and uploading data to be added to a map. It includes a folder chooser, a file uploader, and buttons to apply or reset the selection.

Parameters:

Name Type Description Default
default_path str

The default path for the folder chooser. Defaults to ".".

'.'
widget_width str

The width of the widget. Defaults to "360px".

'360px'
callback Optional[Callable[[str], None]]

A callback function to be called when data is applied. Defaults to None.

None
reset_callback Optional[Callable[[], None]]

A callback function to be called when the selection is reset. Defaults to None.

None
add_header bool

Whether to add a header to the widget. Defaults to True.

True
widget_icon str

The icon for the widget. Defaults to "mdi-folder".

'mdi-folder'
close_icon str

The icon for the close button. Defaults to "mdi-close".

'mdi-close'
label str

The label for the widget. Defaults to "Data Selection".

'Data Selection'
background_color str

The background color of the widget. Defaults to "#f5f5f5".

'#f5f5f5'
height str

The height of the widget. Defaults to "40px".

'40px'
expanded bool

Whether the widget is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for the add_to_sidebar method.

{}

Adds a similarity search widget to the map.

Parameters:

Name Type Description Default
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
widget_icon str

The icon for the widget. Defaults to "mdi-map-search".

'mdi-map-search'
widget_label str

The label for the widget. Defaults to "Similarity Search".

'Similarity Search'
**kwargs Any

Additional keyword arguments to be passed to the add_to_sidebar method.

{}

add_source(id, source)

Adds a source to the map.

Parameters:

Name Type Description Default
id str

The ID of the source.

required
source str or dict

The source data. .

required

Returns:

Type Description
None

None

add_stac_gui(label='STAC Search', widget_icon='mdi-search-web', sidebar_width='515px', **kwargs)

Adds a STAC GUI to the map.

add_stac_layer(url=None, collection=None, item=None, assets=None, bands=None, nodata=0, titiler_endpoint=None, name='STAC Layer', attribution='', opacity=1.0, visible=True, fit_bounds=True, before_id=None, overwrite=False, **kwargs)

Adds a STAC TileLayer to the map.

This method adds a STAC TileLayer to the map. The STAC TileLayer is created from the specified URL, collection, item, assets, and bands, and it is added to the map with the specified name, attribution, opacity, visibility, and fit bounds.

Parameters:

Name Type Description Default
url str

HTTP URL to a STAC item, e.g., https://bit.ly/3VlttGm. Defaults to None.

None
collection str

The Microsoft Planetary Computer STAC collection ID, e.g., landsat-8-c2-l2. Defaults to None.

None
item str

The Microsoft Planetary Computer STAC item ID, e.g., LC08_L2SP_047027_20201204_02_T1. Defaults to None.

None
assets str | list

The Microsoft Planetary Computer STAC asset ID, e.g., ["SR_B7", "SR_B5", "SR_B4"]. Defaults to None.

None
bands list

A list of band names, e.g., ["SR_B7", "SR_B5", "SR_B4"]. Defaults to None.

None
nodata int | float

The nodata value to use for the layer.

0
titiler_endpoint str

TiTiler endpoint, e.g., "https://titiler.opengeos.org", "https://planetarycomputer.microsoft.com/api/data/v1", "planetary-computer", "pc". Defaults to None.

None
name str

The layer name to use for the layer. Defaults to 'STAC Layer'.

'STAC Layer'
attribution str

The attribution to use. Defaults to ''.

''
opacity float

The opacity of the layer. Defaults to 1.

1.0
visible bool

A flag indicating whether the layer should be on by default. Defaults to True.

True
fit_bounds bool

A flag indicating whether the map should be zoomed to the layer extent. Defaults to True.

True
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Arbitrary keyword arguments, including bidx, expression, nodata, unscale, resampling, rescale, color_formula, colormap, colormap_name, return_mask. See https://developmentseed.org/titiler/endpoints/cog/ and https://cogeotiff.github.io/rio-tiler/colormap/. To select a certain bands, use bidx=[1, 2, 3]. apply a rescaling to multiple bands, use something like rescale=["164,223","130,211","99,212"].

{}

Returns:

Type Description

None

add_symbol(source, image, icon_size=1, symbol_placement='line', minzoom=None, maxzoom=None, filter=None, name='Symbols', overwrite=False, **kwargs)

Adds a symbol to the map.

Parameters:

Name Type Description Default
source Union[str, Dict]

The source of the symbol.

required
image str

The URL or local file path to the image. Default to the arrow image. at https://assets.gishub.org/images/right-arrow.png. Find more icons from https://www.veryicon.com.

required
icon_size int

The size of the symbol. Defaults to 1.

1
symbol_placement str

The placement of the symbol. Defaults to "line".

'line'
minzoom Optional[float]

The minimum zoom level for the symbol. Defaults to None.

None
maxzoom Optional[float]

The maximum zoom level for the symbol. Defaults to None.

None
filter Optional[Any]

A filter to apply to the symbol. Defaults to None.

None
name Optional[str]

The name of the symbol layer. Defaults to None.

'Symbols'
**kwargs Any

Additional keyword arguments to pass to the layer layout. For more info, see https://maplibre.org/maplibre-style-spec/layers/#symbol

{}

Returns:

Type Description

None

add_text(text, fontsize=20, fontcolor='black', bold=False, padding='5px', bg_color='white', border_radius='5px', position='bottom-right', **kwargs)

Adds text to the map with customizable styling.

This method allows adding a text widget to the map with various styling options such as font size, color, background color, and more. The text's appearance can be further customized using additional CSS properties passed through kwargs.

Parameters:

Name Type Description Default
text str

The text to add to the map.

required
fontsize int

The font size of the text. Defaults to 20.

20
fontcolor str

The color of the text. Defaults to "black".

'black'
bold bool

If True, the text will be bold. Defaults to False.

False
padding str

The padding around the text. Defaults to "5px".

'5px'
bg_color str

The background color of the text widget. Defaults to "white". To make the background transparent, set this to "transparent". To make the background half transparent, set this to "rgba(255, 255, 255, 0.5)".

'white'
border_radius str

The border radius of the text widget. Defaults to "5px".

'5px'
position str

The position of the text widget on the map. Defaults to "bottom-right".

'bottom-right'
**kwargs Any

Additional CSS properties to apply to the text widget.

{}

Returns:

Type Description

None

add_text_to_sidebar(text, add_header=True, widget_icon='mdi-format-text', close_icon='mdi-close', label='Text', background_color='#f5f5f5', height='40px', expanded=True, widget_args=None, **kwargs)

Adds text to the sidebar.

Parameters:

Name Type Description Default
text str

The text to add to the sidebar.

required
widget_icon str

Icon for the header. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-format-text'
close_icon str

Icon for the close button. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-close'
background_color str

Background color of the header. Defaults to "#f5f5f5".

'#f5f5f5'
label str

Text label for the header. Defaults to "My Tools".

'Text'
height str

Height of the header. Defaults to "40px".

'40px'
expanded bool

Whether the panel is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for the parent class.

{}

add_tile_layer(url, name='Tile Layer', attribution='', opacity=1.0, visible=True, tile_size=256, before_id=None, source_args={}, overwrite=False, **kwargs)

Adds a TileLayer to the map.

This method adds a TileLayer to the map. The TileLayer is created from the specified URL, and it is added to the map with the specified name, attribution, visibility, and tile size.

Parameters:

Name Type Description Default
url str

The URL of the tile layer.

required
name str

The name to use for the layer. Defaults to ' Tile Layer'.

'Tile Layer'
attribution str

The attribution to use for the layer. Defaults to ''.

''
visible bool

Whether the layer should be visible by default. Defaults to True.

True
tile_size int

The size of the tiles in the layer. Defaults to 256.

256
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
source_args dict

Additional keyword arguments that are passed to the RasterTileSource class.

{}
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments that are passed to the Layer class. See https://eodagmbh.github.io/py-maplibregl/api/layer/ for more information.

{}

Returns:

Type Description

None

add_time_slider(images=None, labels=None, time_interval=1, label_width='150px', slider_width='150px', button_width='45px', layer_name='Image', before_id=None, default_index=0, zoom_to_layer=True, widget_icon='mdi-image', close_icon='mdi-close', label='Time Slider', background_color='#f5f5f5', height='40px', expanded=True, **kwargs)

Adds a time slider to the map.

Parameters:

Name Type Description Default
images dict

The dictionary containing a set of images.

None
labels list

The list of labels to be used for the time series. Defaults to None.

None
time_interval int

Time interval in seconds. Defaults to 1.

1
layer_name str

The name of the layer. Defaults to "Image".

'Image'
before_id str

The ID of an existing layer before which the new layer should be inserted. Defaults to None.

None
default_index int

The index of the default layer. Defaults to 0.

0
zoom_to_layer bool

Whether to zoom to the extent of the layer. Defaults to False.

True
label_width str

Width of the label. Defaults to "150px".

'150px'
slider_width str

Width of the slider. Defaults to "150px".

'150px'
button_width str

Width of the buttons. Defaults to "45px".

'45px'
widget_icon str

The icon for the widget. Defaults to "mdi-image".

'mdi-image'
close_icon str

The icon for the close button. Defaults to "mdi-close".

'mdi-close'
label str

The label for the widget. Defaults to "Time Slider".

'Time Slider'
background_color str

The background color of the widget. Defaults to "#f5f5f5".

'#f5f5f5'
height str

The height of the widget. Defaults to "40px".

'40px'
expanded bool

Whether the widget is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments to be passed to the add_raster or add_cog_layer function.

{}

add_to_map_container(*items)

Append one or more widgets beneath the map (in insertion order).

This method adds widgets to the map container while ensuring the sidebar remains visible and properly positioned.

Parameters:

Name Type Description Default
*items Union[Widget, Iterable[Widget], None]

One or more widgets to add beneath the map. Can be individual widgets or iterables of widgets. None values are ignored.

()
Example

import ipywidgets as widgets m = leafmap.Map() button = widgets.Button(description="Click me") slider = widgets.IntSlider(value=5, min=0, max=10) m.add_to_map_container(button, slider)

add_to_sidebar(widget, add_header=True, widget_icon='mdi-tools', close_icon='mdi-close', label='My Tools', background_color='#f5f5f5', height='40px', expanded=True, **kwargs)

Appends a widget to the sidebar content.

Parameters:

Name Type Description Default
widget Optional[Union[Widget, List[Widget]]]

Initial widget(s) to display in the content box.

required
widget_icon str

Icon for the header. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-tools'
close_icon str

Icon for the close button. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-close'
background_color str

Background color of the header. Defaults to "#f5f5f5".

'#f5f5f5'
label str

Text label for the header. Defaults to "My Tools".

'My Tools'
height str

Height of the header. Defaults to "40px".

'40px'
expanded bool

Whether the panel is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for the parent class.

{}

add_vector(data, layer_type=None, filter=None, paint=None, name=None, fit_bounds=True, visible=True, before_id=None, source_args={}, overwrite=False, **kwargs)

Adds a vector layer to the map.

This method adds a vector layer to the map. The vector data can be a URL or local file path to a vector file. If a name is provided, it is used as the key to store the layer in the layer dictionary. Otherwise, a random name is generated.

Parameters:

Name Type Description Default
data str | dict

The vector data. This can be a URL or local file path to a vector file.

required
layer_type str

The type of the layer. If None, the type is inferred from the GeoJSON data.

None
filter dict

The filter to apply to the layer. If None, no filter is applied.

None
paint dict

The paint properties to apply to the layer. If None, no paint properties are applied.

None
name str

The name of the layer. If None, a random name is generated.

None
fit_bounds bool

Whether to adjust the viewport of the map to fit the bounds of the GeoJSON data. Defaults to True.

True
visible bool

Whether the layer is visible or not. Defaults to True.

True
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
source_args dict

Additional keyword arguments that are passed to the GeoJSONSource class.

{}
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments that are passed to the Layer class.

{}

Returns:

Type Description

None

Raises:

Type Description
ValueError

If the data is not a URL or a GeoJSON dictionary.

add_vector_editor(filename=None, properties=None, time_format='%Y%m%dT%H%M%S', out_dir=None, filename_prefix='', file_ext='geojson', add_mapillary=False, style='photo', radius=5e-05, width=300, height=420, frame_border=0, controls=None, position='top-right', fit_bounds_options=None, **kwargs)

Generates a widget-based interface for creating and managing vector data on a map.

This function creates an interactive widget interface that allows users to draw features (points, lines, polygons) on a map, assign properties to these features, and export them as GeoJSON files. The interface includes a map, a sidebar for property management, and buttons for saving, exporting, and resetting the data.

Parameters:

Name Type Description Default
m Map

An existing Map object. If not provided, a default map with basemaps and drawing controls will be created. Defaults to None.

required
filename str or GeoDataFrame

The path to a GeoJSON file or a GeoDataFrame containing the vector data to be edited. Defaults to None.

None
properties Dict[str, List[Any]]

A dictionary where keys are property names and values are lists of possible values for each property. These properties can be assigned to the drawn features. Defaults to None.

None
time_format str

The format string for the timestamp used in the exported filename. Defaults to "%Y%m%dT%H%M%S".

'%Y%m%dT%H%M%S'
column_widths Optional[List[int]]

A list of two integers specifying the relative widths of the map and sidebar columns. Defaults to (9, 3).

required
map_height str

The height of the map widget. Defaults to "600px".

required
out_dir str

The directory where the exported GeoJSON files will be saved. If not provided, the current working directory is used. Defaults to None.

None
filename_prefix str

A prefix to be added to the exported filename. Defaults to "".

''
file_ext str

The file extension for the exported file. Defaults to "geojson".

'geojson'
add_mapillary bool

Whether to add a Mapillary image widget that displays the nearest image to the clicked point on the map. Defaults to False.

False
style str

The style of the Mapillary image widget. Can be "classic", "photo", or "split". Defaults to "photo".

'photo'
radius float

The radius (in degrees) used to search for the nearest Mapillary image. Defaults to 0.00005 degrees.

5e-05
width int

The width of the Mapillary image widget. Defaults to 300.

300
height int

The height of the Mapillary image widget. Defaults to 420.

420
frame_border int

The width of the frame border for the Mapillary image widget. Defaults to 0.

0
controls Optional[List[str]]

The drawing controls to be added to the map. Defaults to ["point", "polygon", "line_string", "trash"].

None
position str

The position of the drawing controls on the map. Defaults to "top-right".

'top-right'
**kwargs Any

Additional keyword arguments that may be passed to the function.

{}

Returns:

Type Description
VBox

widgets.VBox: A vertical box widget containing the map, sidebar, and control buttons.

add_vector_tile(url, layer_id, layer_type='fill', source_layer=None, name=None, paint=None, layout=None, filter=None, minzoom=None, maxzoom=None, visible=True, opacity=1.0, add_popup=True, before_id=None, source_args={}, overwrite=False, **kwargs)

Adds a vector tile layer to the map.

This method adds a vector tile layer to the map using a vector tile source. Vector tiles are a data format for efficiently storing and transmitting vector map data.

Parameters:

Name Type Description Default
url str

The URL template for the vector tiles. Should contain {z}, {x}, and {y} placeholders for tile coordinates.

required
layer_id str

The ID of the layer within the vector tile source.

required
layer_type str

The type of layer to create. Can be 'fill', 'line', 'symbol', 'circle', etc. Defaults to 'fill'.

'fill'
source_layer str

The name of the source layer within the vector tiles. If None, uses layer_id.

None
name str

The name to use for the layer. If None, uses layer_id.

None
paint dict

Paint properties for the layer. If None, uses default styling based on layer_type.

None
layout dict

Layout properties for the layer.

None
filter dict

Filter expression for the layer.

None
minzoom int

Minimum zoom level for the layer.

None
maxzoom int

Maximum zoom level for the layer.

None
visible bool

Whether the layer should be visible by default. Defaults to True.

True
opacity float

The opacity of the layer. Defaults to 1.0.

1.0
add_popup bool

Whether to add a popup to the layer. Defaults to True.

True
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
source_args dict

Additional keyword arguments passed to the vector tile source.

{}
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments passed to the Layer class.

{}

Returns:

Type Description

None

Example

m = Map() m.add_vector_tile( ... url="https://api.maptiler.com/tiles/contours/tiles.json?key={api_key}", ... layer_id="contour-lines", ... layer_type="line", ... source_layer="contour", ... paint={"line-color": "#ff69b4", "line-width": 1} ... )

add_video(urls, coordinates, layer_id='video', before_id=None)

Adds a video layer to the map.

This method allows embedding a video into the map by specifying the video URLs and the geographical coordinates that the video should cover. The video will be stretched and fitted into the specified coordinates.

Parameters:

Name Type Description Default
urls Union[str, List[str]]

A single video URL or a list of video URLs. These URLs must be accessible from the client's location.

required
coordinates List[List[float]]

A list of four coordinates in [longitude, latitude] format, specifying the corners of the video. The coordinates order should be top-left, top-right, bottom-right, bottom-left.

required
layer_id str

The ID for the video layer. Defaults to "video".

'video'
before_id Optional[str]

The ID of an existing layer to insert the new layer before. If None, the layer will be added on top. Defaults to None.

None

Returns:

Type Description
None

None

add_video_to_sidebar(src, width=600, add_header=True, widget_icon='mdi-video', close_icon='mdi-close', label='Video', background_color='#f5f5f5', height='40px', expanded=True, **kwargs)

Adds a video to the sidebar.

Parameters:

Name Type Description Default
src str

The URL of the video to be added.

required
width int

Width of the video in pixels. Defaults to 600.

600
add_header bool

If True, adds a header to the video. Defaults to True.

True
widget_icon str

Icon for the header. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-video'
close_icon str

Icon for the close button. See https://pictogrammers.github.io/@mdi/font/2.0.46/ for available icons.

'mdi-close'
background_color str

Background color of the header. Defaults to "#f5f5f5".

'#f5f5f5'
label str

Text label for the header. Defaults to "My Tools".

'Video'
height str

Height of the header. Defaults to "40px".

'40px'
expanded bool

Whether the panel is expanded by default. Defaults to True.

True
**kwargs Any

Additional keyword arguments for the parent class.

{}

add_wayback_layer(date=None, name=None, attribution='Esri', before_id=None, quiet=False, **kwargs)

Adds a Wayback layer to the map.

Parameters:

Name Type Description Default
date str

The date of the layer. Defaults to None.

None
name str

The name of the layer. Defaults to None.

None
attribution str

The attribution of the layer. Defaults to "Esri".

'Esri'
**kwargs

Additional keyword arguments to pass to the add_tile_layer method.

{}

add_wayback_time_slider(default_index=0, **kwargs)

Add a time slider for Wayback layers.

add_wms_layer(url, layers, format='image/png', name='WMS Layer', attribution='', opacity=1.0, visible=True, tile_size=256, before_id=None, source_args={}, overwrite=False, **kwargs)

Adds a WMS layer to the map.

This method adds a WMS layer to the map. The WMS is created from the specified URL, and it is added to the map with the specified name, attribution, visibility, and tile size.

Parameters:

Name Type Description Default
url str

The URL of the tile layer.

required
layers str

The layers to include in the WMS request.

required
format str

The format of the tiles in the layer.

'image/png'
name str

The name to use for the layer. Defaults to 'WMS Layer'.

'WMS Layer'
attribution str

The attribution to use for the layer. Defaults to ''.

''
visible bool

Whether the layer should be visible by default. Defaults to True.

True
tile_size int

The size of the tiles in the layer. Defaults to 256.

256
before_id str

The ID of an existing layer before which the new layer should be inserted.

None
source_args dict

Additional keyword arguments that are passed to the RasterTileSource class.

{}
overwrite bool

Whether to overwrite an existing layer with the same name. Defaults to False.

False
**kwargs Any

Additional keyword arguments that are passed to the Layer class. See https://eodagmbh.github.io/py-maplibregl/api/layer/ for more information.

{}

Returns:

Type Description

None

add_zarr(url, variable=None, name='Zarr Layer', attribution='', opacity=1.0, visible=True, titiler_endpoint=None, fit_bounds=True, before_id=None, group=None, decode_times=False, time_index=0, overwrite=False, **kwargs)

Adds a Zarr dataset to the map as a tile layer.

This method uses titiler-xarray to dynamically serve tiles from Zarr datasets (local or remote). It supports both single-variable and multi-variable datasets.

Parameters:

Name Type Description Default
url str

URL to a Zarr dataset (HTTP, S3, or local path). Examples: - "https://example.com/data.zarr" - "s3://bucket/data.zarr"

required
variable str

The variable name to visualize. Required for multi-variable datasets. Defaults to None.

None
name str

The layer name. Defaults to "Zarr Layer".

'Zarr Layer'
attribution str

Attribution for the layer. Defaults to "".

''
opacity float

Layer opacity (0.0 to 1.0). Defaults to 1.0.

1.0
visible bool

Whether the layer is visible. Defaults to True.

True
titiler_endpoint str

TiTiler endpoint that supports xarray. If not provided, the function first checks the TITILER_XARRAY_ENDPOINT environment variable; if that is not set, it falls back to the default endpoint resolved by check_titiler_endpoint.

None
fit_bounds bool

Zoom to layer extent. Defaults to True.

True
before_id str

Layer id to insert before. Defaults to None.

None
group str

Zarr group path within the dataset. Defaults to None.

None
decode_times bool

Whether to decode times. Defaults to False.

False
time_index int

Index of the time dimension to visualize. Required for datasets with a time dimension. Defaults to 0 (first time step). Set to None if the dataset has no time dimension.

0
overwrite bool

Whether to overwrite an existing layer. Defaults to False.

False
**kwargs Any

Additional arguments passed to the titiler endpoint: - rescale (str): Value range, e.g., "0,255" - colormap_name (str): Colormap name, e.g., "viridis", "terrain" - colormap (str): JSON-encoded custom colormap - nodata (float): Nodata value - resampling (str): Resampling method (nearest, bilinear, etc.) - sel (str): Custom dimension selection, e.g., "time=5"

{}
Example

import leafmap.maplibregl as leafmap m = leafmap.Map() url = "https://example.com/temperature.zarr" m.add_zarr(url, variable="temperature", colormap_name="viridis")

close_db_connections(database_path=None, quiet=False)

Close DuckDB connections for databases used by this map.

This method closes all connections in the connection pool for the specified database or all databases used by this map instance, allowing other programs to access the database files. This is useful when you're done using the database and want to release the file lock.

Parameters:

Name Type Description Default
database_path str

Path to the DuckDB database file. If None, closes connections for all databases used by this map. Defaults to None.

None
quiet bool

If True, suppress status messages. Defaults to False.

False

Returns:

Type Description

None

Example

import leafmap.maplibregl as leafmap m = leafmap.Map() m.add_duckdb_layer("tiles.db")

Later, close the connections

m.close_db_connections()

Or close connections for a specific database

m.close_db_connections("tiles.db")

create_container(sidebar_visible=None, min_width=None, max_width=None, expanded=None, **kwargs)

Creates a container widget for the map with an optional sidebar.

This method initializes a LayerManagerWidget and a Container widget to display the map alongside a sidebar. The sidebar can be customized with visibility, width, and additional content.

Parameters:

Name Type Description Default
sidebar_visible bool

Whether the sidebar is visible. Defaults to False.

None
min_width int

Minimum width of the sidebar in pixels. Defaults to 360.

None
max_width int

Maximum width of the sidebar in pixels. Defaults to 360.

None
expanded bool

Whether the LayerManagerWidget is expanded by default. Defaults to True.

None
**kwargs Any

Additional keyword arguments passed to the Container widget.

{}

Returns:

Type Description
Container

v.Container: The created container widget with the map and sidebar.

create_mapillary_widget(lon=None, lat=None, radius=5e-05, bbox=None, image_id=None, style='classic', width=560, height=600, frame_border=0, link=True, container=True, column_widths=[8, 1], **kwargs)

Creates a Mapillary widget.

Parameters:

Name Type Description Default
lon Optional[float]

Longitude of the location. Defaults to None.

None
lat Optional[float]

Latitude of the location. Defaults to None.

None
radius float

Search radius for Mapillary images. Defaults to 0.00005.

5e-05
bbox Optional[Union[str, List[float]]]

Bounding box for the search. Defaults to None.

None
image_id Optional[str]

ID of the Mapillary image. Defaults to None.

None
style str

Style of the Mapillary image. Can be "classic", "photo", and "split". Defaults to "classic".

'classic'
height int

Height of the iframe. Defaults to 600.

600
frame_border int

Frame border of the iframe. Defaults to 0.

0
link bool

Whether to link the widget to map clicks. Defaults to True.

True
container bool

Whether to return the widget in a container. Defaults to True.

True
column_widths List[int]

Widths of the columns in the container. Defaults to [8, 1].

[8, 1]
**kwargs Any

Additional keyword arguments for the widget.

{}

Returns:

Type Description
Union[HTML, Row]

Union[widgets.HTML, v.Row]: The Mapillary widget or a container with the widget.

find_first_symbol_layer()

Find the first symbol layer in the map's current style.

Returns:

Type Description
Optional[Dict]

Optional[Dict]: The first symbol layer as a dictionary if found, otherwise None.

find_style_layer(id)

Searches for a style layer in the map's current style by its ID and returns it if found.

Parameters:

Name Type Description Default
id str

The ID of the style layer to find.

required

Returns:

Type Description
Optional[Dict]

Optional[Dict]: The style layer as a dictionary if found, otherwise None.

fit_bounds(bounds, options=None)

Adjusts the viewport of the map to fit the specified geographical bounds in the format of [[lon_min, lat_min], [lon_max, lat_max]] or [lon_min, lat_min, lon_max, lat_max].

This method adjusts the viewport of the map so that the specified geographical bounds are visible in the viewport. The bounds are specified as a list of two points, where each point is a list of two numbers representing the longitude and latitude.

Parameters:

Name Type Description Default
bounds list

A list of two points representing the geographical bounds that should be visible in the viewport. Each point is a list of two numbers representing the longitude and latitude. For example, [[32.958984, -5.353521],[43.50585, 5.615985]]

required
options dict

Additional options for fitting the bounds. See https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/FitBoundsOptions/.

None

Returns:

Type Description
None

None

fly_to(lon, lat, zoom=None, speed=None, essential=True, **kwargs)

Makes the map fly to a specified location.

Parameters:

Name Type Description Default
lon float

The longitude of the location to fly to.

required
lat float

The latitude of the location to fly to.

required
zoom Optional[float]

The zoom level to use when flying to the location. Defaults to None.

None
speed Optional[float]

The speed of the fly animation. Defaults to None.

None
essential bool

Whether the flyTo animation is considered essential and not affected by prefers-reduced-motion. Defaults to True.

True
**kwargs Any

Additional keyword arguments to pass to the flyTo function.

{}

Returns:

Type Description

None

get_deck_layer(layer_id)

Get a Deck.GL layer from the map.

Parameters:

Name Type Description Default
layer_id str

The ID of the layer to get.

required

get_layer_names()

Gets layer names as a list.

Returns:

Name Type Description
list list

A list of layer names.

get_style()

Get the style of the map.

Returns:

Name Type Description
Dict Dict

The style of the map.

get_style_layers(return_ids=False, sorted=True)

Get the names of the basemap layers.

Returns:

Type Description
List[str]

List[str]: The names of the basemap layers.

jump_to(options={}, **kwargs)

Jumps the map to a specified location.

This function jumps the map to the specified location with the specified options. Additional keyword arguments can be provided to control the jump. For more information, see https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#jumpto

Parameters:

Name Type Description Default
options Dict[str, Any]

Additional options to control the jump. Defaults to {}.

{}
**kwargs Any

Additional keyword arguments to control the jump.

{}

Returns:

Type Description
None

None

layer_interact(name=None)

Create a layer widget for changing the visibility and opacity of a layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

None

Returns:

Type Description
Widget

ipywidgets.Widget: The layer widget.

observe_mapillary(html_widget, style='photo', radius=5e-05, height=420, frame_border=0, default_message='No Mapillary image found')

Observes the mapillary data and updates the html widget.

Parameters:

Name Type Description Default
html_widget HTML

The html widget to display the mapillary data.

required
style str

The style of the Mapillary image widget. Can be "classic", "photo", or "split". Defaults to "photo".

'photo'
radius float

The radius (in degrees) used to search for the nearest Mapillary image. Defaults to 0.00005 degrees.

5e-05
height int

The height of the Mapillary image widget. Defaults to 420.

420
frame_border int

The width of the frame border for the Mapillary image widget. Defaults to 0.

0
default_message str

The message to display when no Mapillary image is found.

'No Mapillary image found'

open_geojson(**kwargs)

Creates a file uploader widget to upload a GeoJSON file. When a file is uploaded, it is written to a temporary file and added to the map.

Parameters:

Name Type Description Default
**kwargs Any

Additional keyword arguments to pass to the add_geojson method.

{}

Returns:

Type Description
FileUpload

widgets.FileUpload: The file uploader widget.

pan_to(lnglat, options={}, **kwargs)

Pans the map to a specified location.

This function pans the map to the specified longitude and latitude coordinates. Additional options and keyword arguments can be provided to control the panning. For more information, see https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#panto

Parameters:

Name Type Description Default
lnglat List[float, float]

The longitude and latitude coordinates to pan to.

required
options Dict[str, Any]

Additional options to control the panning. Defaults to {}.

{}
**kwargs Any

Additional keyword arguments to control the panning.

{}

Returns:

Type Description

None

remove_deck_layers(layer_ids=None, tooltip=None)

Remove a list of Deck.GL layers from the map.

Parameters:

Name Type Description Default
layer_ids List[str]

A list of layer IDs to remove.

None
tooltip bool

Tooltip for the remaining layers.

None

remove_from_sidebar(widget=None, name=None)

Removes a widget from the sidebar content.

Parameters:

Name Type Description Default
widget Widget

The widget to remove from the sidebar.

None
name str

The name of the widget to remove from the sidebar.

None

remove_layer(name, **kwargs)

Removes a layer from the map.

This method removes a layer from the map using the layer's name.

Parameters:

Name Type Description Default
name str

The name of the layer to remove.

required

Returns:

Type Description
None

None

remove_source(id)

Removes a source from the map.

remove_terrain()

Remove terrain visualization from the map.

rotate_to(bearing, options={}, **kwargs)

Rotate the map to a specified bearing.

This function rotates the map to a specified bearing. The bearing is specified in degrees counter-clockwise from true north. If the bearing is not specified, the map will rotate to true north. Additional options and keyword arguments can be provided to control the rotation. For more information, see https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#rotateto

Parameters:

Name Type Description Default
bearing float

The bearing to rotate to, in degrees counter-clockwise from true north.

required
options Dict[str, Any]

Additional options to control the rotation. Defaults to {}.

{}
**kwargs Any

Additional keyword arguments to control the rotation.

{}

Returns:

Type Description
None

None

save_draw_features(filepath, indent=4, **kwargs)

Saves the drawn features to a file.

This method saves all features created with the drawing control to a specified file in GeoJSON format. If there are no features to save, the file will not be created.

Parameters:

Name Type Description Default
filepath str

The path to the file where the GeoJSON data will be saved.

required
**kwargs Any

Additional keyword arguments to be passed to json.dump for custom serialization.

{}

Returns:

Type Description
None

None

Raises:

Type Description
ValueError

If the feature collection is empty.

set_center(lon, lat, zoom=None)

Sets the center of the map.

This method sets the center of the map to the specified longitude and latitude. If a zoom level is provided, it also sets the zoom level of the map.

Parameters:

Name Type Description Default
lon float

The longitude of the center of the map.

required
lat float

The latitude of the center of the map.

required
zoom int

The zoom level of the map. If None, the zoom level is not changed.

None

Returns:

Type Description
None

None

set_color(name, color)

Set the color of a layer.

This method sets the color of the specified layer to the specified value.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
color str

The color value to set.

required

Returns:

Type Description
None

None

set_data(id, data)

Sets the data for a source.

Parameters:

Name Type Description Default
id str

The ID of the source.

required
data str or dict

The data to set for the source.

required

Returns:

Type Description
None

None

set_deck_layer_opacity(layer_id, opacity)

Set the opacity of a Deck.GL layer.

Parameters:

Name Type Description Default
layer_id str

The ID of the layer to set the opacity of.

required
opacity float

The opacity of the layer.

required

set_deck_layer_properties(layer_id, properties)

Set the properties of a Deck.GL layer.

Parameters:

Name Type Description Default
layer_id str

The ID of the layer to set the properties of.

required
properties dict

The properties to set.

required

set_deck_layer_property(layer_id, property, value)

Set the property of a Deck.GL layer.

Parameters:

Name Type Description Default
layer_id str

The ID of the layer to set the property of.

required
property str

The property to set.

required
value Any

The value of the property.

required

set_layout_property(name, prop, value)

Set the layout property of a layer.

This method sets the layout property of the specified layer to the specified value.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
prop str

The layout property to set.

required
value Any

The value to set.

required

Returns:

Type Description
None

None

set_opacity(name, opacity)

Set the opacity of a layer.

This method sets the opacity of the specified layer to the specified value.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
opacity float

The opacity value to set.

required

Returns:

Type Description
None

None

set_paint_property(name, prop, value)

Set the paint property of a layer.

This method sets the opacity of the specified layer to the specified value.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
prop str

The paint property to set.

required
value Any

The value to set.

required

Returns:

Type Description
None

None

set_pitch(pitch, **kwargs)

Sets the pitch of the map.

This function sets the pitch of the map to the specified value. The pitch is the angle of the camera measured in degrees where 0 is looking straight down, and 60 is looking towards the horizon. Additional keyword arguments can be provided to control the pitch. For more information, see https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#setpitch

Parameters:

Name Type Description Default
pitch float

The pitch value to set.

required
**kwargs Any

Additional keyword arguments to control the pitch.

{}

Returns:

Type Description
None

None

set_sidebar_content(content)

Replaces all content in the sidebar (except the toggle button).

Parameters:

Name Type Description Default
content Union[VBox, List[Widget]]

The new content for the sidebar.

required

set_sidebar_width(min_width=None, max_width=None)

Dynamically updates the sidebar's minimum and maximum width.

Parameters:

Name Type Description Default
min_width int

New minimum width in pixels. If None, keep current.

None
max_width int

New maximum width in pixels. If None, keep current.

None

set_terrain(source='https://elevation-tiles-prod.s3.amazonaws.com/terrarium/{z}/{x}/{y}.png', exaggeration=1.0, tile_size=256, encoding='terrarium', source_id='terrain-dem')

Add terrain visualization to the map.

Parameters:

Name Type Description Default
source str

URL template for terrain tiles. Defaults to AWS elevation tiles.

'https://elevation-tiles-prod.s3.amazonaws.com/terrarium/{z}/{x}/{y}.png'
exaggeration float

Terrain exaggeration factor. Defaults to 1.0.

1.0
tile_size int

Tile size in pixels. Defaults to 256.

256
encoding str

Encoding for the terrain tiles. Defaults to "terrarium".

'terrarium'
source_id str

Unique identifier for the terrain source. Defaults to "terrain-dem".

'terrain-dem'

set_visibility(name, visible)

Set the visibility of a layer.

This method sets the visibility of the specified layer to the specified value.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
visible bool

The visibility value to set.

required

Returns:

Type Description
None

None

set_zoom(zoom=None)

Sets the zoom level of the map.

This method sets the zoom level of the map to the specified value.

Parameters:

Name Type Description Default
zoom int

The zoom level of the map.

None

Returns:

Type Description
None

None

show(sidebar_visible=False, min_width=360, max_width=360, sidebar_content=None, **kwargs)

Displays the map with an optional sidebar.

Parameters:

Name Type Description Default
sidebar_visible bool

Whether the sidebar is visible. Defaults to False.

False
min_width int

Minimum width of the sidebar in pixels. Defaults to 250.

360
max_width int

Maximum width of the sidebar in pixels. Defaults to 300.

360
sidebar_content Optional[Any]

Content to display in the sidebar. Defaults to None.

None
**kwargs Any

Additional keyword arguments.

{}

Returns:

Type Description

None

style_layer_interact(id=None)

Create a layer widget for changing the visibility and opacity of a style layer.

Parameters:

Name Type Description Default
id str

The is of the layer.

None

Returns:

Type Description
Widget

ipywidgets.Widget: The layer widget.

to_html(output=None, title='My Awesome Map', width='100%', height='100%', replace_key=False, remove_port=True, preview=False, overwrite=False, **kwargs)

Render the map to an HTML page.

Parameters:

Name Type Description Default
output str

The output HTML file. If None, the HTML content is returned as a string. Defaults

None
title str

The title of the HTML page. Defaults to 'My Awesome Map'.

'My Awesome Map'
width str

The width of the map. Defaults to '100%'.

'100%'
height str

The height of the map. Defaults to '100%'.

'100%'
replace_key bool

Whether to replace the API key in the HTML. If True, the API key is replaced with the public API key. The API key is read from the environment variable MAPTILER_KEY. The public API key is read from the environment variable MAPTILER_KEY_PUBLIC. Defaults to False.

False
remove_port bool

Whether to remove the port number from the HTML.

True
preview bool

Whether to preview the HTML file in a web browser. Defaults to False.

False
overwrite bool

Whether to overwrite the output file if it already exists.

False
**kwargs Any

Additional keyword arguments that are passed to the maplibre.ipywidget.MapWidget.to_html() method.

{}

Returns:

Name Type Description
str str

The HTML content of the map.

to_solara(map_only=False, **kwargs)

Converts the widget to a Solara widget.

Parameters:

Name Type Description Default
map_only bool

Whether to only return the map widget. Defaults to False.

False

to_streamlit(width=None, height=600, scrolling=False, **kwargs)

Convert the map to a Streamlit component.

This function converts the map to a Streamlit component by encoding the HTML representation of the map as base64 and embedding it in an iframe. The width, height, and scrolling parameters control the appearance of the iframe.

Parameters:

Name Type Description Default
width Optional[int]

The width of the iframe. If None, the width will be determined by Streamlit.

None
height Optional[int]

The height of the iframe. Default is 600.

600
scrolling Optional[bool]

Whether the iframe should be scrollable. Default is False.

False
**kwargs Any

Additional arguments to pass to the Streamlit iframe function.

{}

Returns:

Name Type Description
Any Any

The Streamlit component.

Raises:

Type Description
Exception

If there is an error in creating the Streamlit component.

unobserve_mapillary()

Unobserves the mapillary street view.

user_roi_bounds(decimals=4)

Gets the bounds of the user drawn ROI as a tuple of (minx, miny, maxx, maxy).

Parameters:

Name Type Description Default
decimals int

The number of decimals to round the coordinates to. Defaults to 4.

4

Returns:

Type Description
Optional[list]

Optional[list]: The bounds of the user drawn ROI as a tuple of (minx, miny, maxx, maxy), or None if no ROI is drawn.

zoom_to(zoom, options={}, **kwargs)

Zooms the map to a specified zoom level.

This function zooms the map to the specified zoom level. Additional options and keyword arguments can be provided to control the zoom. For more information, see https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#zoomto

Parameters:

Name Type Description Default
zoom float

The zoom level to zoom to.

required
options Dict[str, Any]

Additional options to control the zoom. Defaults to {}.

{}
**kwargs Any

Additional keyword arguments to control the zoom.

{}

Returns:

Type Description
None

None

SelectDataWidget

Bases: VBox

A widget for selecting and uploading data to be added to a map.

This widget allows users to select a folder or upload files to be added to a map. It includes a folder chooser, a file uploader, and buttons to apply or reset the selection.

__init__(default_path='.', widget_width='360px', callback=None, reset_callback=None, map_widget=None)

Initializes the SelectDataWidget.

Parameters:

Name Type Description Default
default_path str

The default path for the folder chooser. Defaults to ".".

'.'
widget_width str

The width of the widget. Defaults to "360px".

'360px'
callback Optional[Callable[[str], None]]

A callback function to be called when data is applied. Defaults to None.

None
reset_callback Optional[Callable[[], None]]

A callback function to be called when the selection is reset. Defaults to None.

None
map_widget Optional[Map]

The map widget to which the data will be added. Defaults to None.

None

TimeSliderWidget(m, images=None, labels=None, time_interval=1, layer_name='Image', before_id=None, default_index=0, zoom_to_layer=True, label_width='150px', slider_width='150px', button_width='45px', **kwargs)

Adds a time slider to the map.

Parameters:

Name Type Description Default
images dict

The dictionary containing a set of images.

None
labels list

The list of labels to be used for the time series. Defaults to None.

None
time_interval int

Time interval in seconds. Defaults to 1.

1
layer_name str

The name of the layer. Defaults to "Image".

'Image'
before_id str

The ID of an existing layer before which the new layer should be inserted. Defaults to None.

None
default_index int

The index of the default layer. Defaults to 0.

0
zoom_to_layer bool

Whether to zoom to the extent of the layer. Defaults to False.

True
label_width str

Width of the label. Defaults to "150px".

'150px'
slider_width str

Width of the slider. Defaults to "150px".

'150px'
button_width str

Width of the buttons. Defaults to "45px".

'45px'
**kwargs

Additional keyword arguments to be passed to the add_raster or add_cog_layer function.

{}

construct_amazon_style(map_style='standard', region='us-east-1', api_key=None, token='AWS_MAPS_API_KEY')

Constructs a URL for an Amazon Map style.

Parameters:

Name Type Description Default
map_style str

The name of the MapTiler style to be accessed. It can be one of the following: standard, monochrome, satellite, hybrid.

'standard'
region str

The region of the Amazon Map. It can be one of the following: us-east-1, us-west-2, eu-central-1, eu-west-1, ap-northeast-1, ap-northeast-2, ap-southeast-1, etc.

'us-east-1'
api_key str

The API key for the Amazon Map. If None, the function attempts to retrieve the API key using a predefined method.

None
token str

The token for the Amazon Map. If None, the function attempts to retrieve the API key using a predefined method.

'AWS_MAPS_API_KEY'

Returns:

Name Type Description
str str

The URL for the requested Amazon Map style.

construct_maptiler_style(style, api_key=None)

Constructs a URL for a MapTiler style with an optional API key.

This function generates a URL for accessing a specific MapTiler map style. If an API key is not provided, it attempts to retrieve one using a predefined method. If the request to MapTiler fails, it defaults to a "liberty" style.

Parameters:

Name Type Description Default
style str

The name of the MapTiler style to be accessed. It can be one of the following: aquarelle, backdrop, basic, bright, dataviz, landscape, ocean, openstreetmap, outdoor, satellite, streets, toner, topo, winter, etc.

required
api_key Optional[str]

An optional API key for accessing MapTiler services. If None, the function attempts to retrieve the API key using a predefined method. Defaults to None.

None

Returns:

Name Type Description
str str

The URL for the requested MapTiler style. If the request fails, returns a URL for the "liberty" style.

Raises:

Type Description
RequestException

If the request to the MapTiler API fails.

create_arc_layer(data, src_lon, src_lat, dst_lon, dst_lat, src_color=[255, 0, 0], dst_color=[255, 255, 0], line_width=2, layer_id='arc_layer', pickable=True, tooltip=None, **kwargs)

Create a DeckGL ArcLayer.

Parameters:

Name Type Description Default
data Union[str, DataFrame]

The file path or DataFrame containing the data.

required
src_lon str

The source longitude column name.

required
src_lat str

The source latitude column name.

required
dst_lon str

The destination longitude column name.

required
dst_lat str

The destination latitude column name.

required
src_color List[int]

The source color as an RGB list.

[255, 0, 0]
dst_color List[int]

The destination color as an RGB list.

[255, 255, 0]
line_width int

The width of the lines.

2
layer_id str

The ID of the layer.

'arc_layer'
pickable bool

Whether the layer is pickable.

True
tooltip Optional[Union[str, List[str]]]

The tooltip content or list of columns. Defaults to None.

None
**kwargs Any

Additional arguments for the layer.

{}

Returns:

Type Description
dict

None

create_vector_data(m=None, properties=None, geojson=None, time_format='%Y%m%dT%H%M%S', column_widths=(9, 3), map_height='600px', out_dir=None, filename_prefix='', file_ext='geojson', add_mapillary=False, style='photo', radius=5e-05, width=300, height=420, frame_border=0, download=True, name=None, paint=None, options=None, controls=None, position='top-right', callback=None, return_sidebar=False, **kwargs)

Generates a widget-based interface for creating and managing vector data on a map.

This function creates an interactive widget interface that allows users to draw features (points, lines, polygons) on a map, assign properties to these features, and export them as GeoJSON files. The interface includes a map, a sidebar for property management, and buttons for saving, exporting, and resetting the data.

Parameters:

Name Type Description Default
m Map

An existing Map object. If not provided, a default map with basemaps and drawing controls will be created. Defaults to None.

None
properties Dict[str, List[Any]]

A dictionary where keys are property names and values are lists of possible values for each property. These properties can be assigned to the drawn features. Defaults to None.

None
time_format str

The format string for the timestamp used in the exported filename. Defaults to "%Y%m%dT%H%M%S".

'%Y%m%dT%H%M%S'
column_widths Optional[List[int]]

A list of two integers specifying the relative widths of the map and sidebar columns. Defaults to (9, 3).

(9, 3)
map_height str

The height of the map widget. Defaults to "600px".

'600px'
out_dir str

The directory where the exported GeoJSON files will be saved. If not provided, the current working directory is used. Defaults to None.

None
filename_prefix str

A prefix to be added to the exported filename. Defaults to "".

''
file_ext str

The file extension for the exported file. Defaults to "geojson".

'geojson'
add_mapillary bool

Whether to add a Mapillary image widget that displays the nearest image to the clicked point on the map. Defaults to False.

False
style str

The style of the Mapillary image widget. Can be "classic", "photo", or "split". Defaults to "photo".

'photo'
radius float

The radius (in degrees) used to search for the nearest Mapillary image. Defaults to 0.00005 degrees.

5e-05
width int

The width of the Mapillary image widget. Defaults to 300.

300
height int

The height of the Mapillary image widget. Defaults to 420.

420
frame_border int

The width of the frame border for the Mapillary image widget. Defaults to 0.

0
download bool

Whether to generate a download link for the exported file. Defaults to True.

True
name str

The name of the drawn feature layer to be added to the map. Defaults to None.

None
paint Dict[str, Any]

A dictionary specifying the paint properties for the drawn features. This can include properties like "circle-radius", "circle-color", "circle-opacity", "circle-stroke-color", and "circle-stroke-width". Defaults to None.

None
callback Callable

A callback function to be called when the export button is clicked. Defaults to None.

None
return_sidebar bool

Whether to return the sidebar widget. Defaults to False.

False
**kwargs Any

Additional keyword arguments that may be passed to the add_geojson method.

{}

Returns:

Type Description
VBox

widgets.VBox: A vertical box widget containing the map, sidebar, and control buttons.

Example

properties = { ... "Type": ["Residential", "Commercial", "Industrial"], ... "Area": [100, 200, 300], ... } widget = create_vector_data(properties=properties) display(widget) # Display the widget in a Jupyter notebook

edit_gps_trace(filename, m, ann_column, colormap, layer_name, default_features=None, ann_options=None, rows=11, fig_width='1550px', fig_height='300px', time_format='%Y%m%dT%H%M%S', stroke_color='lightgray', circle_size=48, webGL=False, download=False, sync_plots=False, column_widths=(9, 3), **kwargs)

Edits a GPS trace on the map and allows for annotation and export.

Parameters:

Name Type Description Default
filename str

The path to the GPS trace CSV file.

required
m Any

The map object containing the GPS trace.

required
ann_column str

The annotation column in the GPS trace.

required
colormap Dict[str, str]

The colormap for the GPS trace annotations.

required
layer_name str

The name of the GPS trace layer.

required
default_features Optional[str]

The default features to display. The first numerical column will be used if None. Defaults to None.

None
ann_options Optional[List[str]]

The annotation options for the dropdown. Defaults to None.

None
rows int

The number of rows to display in the table. Defaults to 11.

11
fig_width str

The width of the figure. Defaults to "1550px".

'1550px'
fig_height str

The height of the figure. Defaults to "300px".

'300px'
time_format str

The time format for the timestamp. Defaults to "%Y-%m-%d %H:%M:%S".

'%Y%m%dT%H%M%S'
stroke_color str

The stroke color of the GPS trace points. Defaults to "lightgray".

'lightgray'
circle_size int

The size of the GPS trace points. Defaults to 48.

48
webGL bool

Whether to use WebGL (bqplot-gl) for rendering. Defaults to False.

False
download bool

Whether to generate links for downloading the edited GPS traces. Defaults to False.

False
sync_plots bool

Whether to synchronize the zoom and pan of the plots. Defaults to False.

False
column_widths Optional[List[int]]

The column widths for the output widget. Defaults to (9, 3).

(9, 3)
**kwargs

Additional keyword arguments.

{}

Returns:

Name Type Description
Any Any

The main widget containing the map and the editing interface.

edit_vector_data(m=None, filename=None, properties=None, time_format='%Y%m%dT%H%M%S', column_widths=(9, 3), map_height='600px', out_dir=None, filename_prefix='', file_ext='geojson', add_mapillary=False, style='photo', radius=5e-05, width=300, height=420, frame_border=0, controls=None, position='top-right', fit_bounds_options=None, **kwargs)

Generates a widget-based interface for creating and managing vector data on a map.

This function creates an interactive widget interface that allows users to draw features (points, lines, polygons) on a map, assign properties to these features, and export them as GeoJSON files. The interface includes a map, a sidebar for property management, and buttons for saving, exporting, and resetting the data.

Parameters:

Name Type Description Default
m Map

An existing Map object. If not provided, a default map with basemaps and drawing controls will be created. Defaults to None.

None
filename str or GeoDataFrame

The path to a GeoJSON file or a GeoDataFrame containing the vector data to be edited. Defaults to None.

None
properties Dict[str, List[Any]]

A dictionary where keys are property names and values are lists of possible values for each property. These properties can be assigned to the drawn features. Defaults to None.

None
time_format str

The format string for the timestamp used in the exported filename. Defaults to "%Y%m%dT%H%M%S".

'%Y%m%dT%H%M%S'
column_widths Optional[List[int]]

A list of two integers specifying the relative widths of the map and sidebar columns. Defaults to (9, 3).

(9, 3)
map_height str

The height of the map widget. Defaults to "600px".

'600px'
out_dir str

The directory where the exported GeoJSON files will be saved. If not provided, the current working directory is used. Defaults to None.

None
filename_prefix str

A prefix to be added to the exported filename. Defaults to "".

''
file_ext str

The file extension for the exported file. Defaults to "geojson".

'geojson'
add_mapillary bool

Whether to add a Mapillary image widget that displays the nearest image to the clicked point on the map. Defaults to False.

False
style str

The style of the Mapillary image widget. Can be "classic", "photo", or "split". Defaults to "photo".

'photo'
radius float

The radius (in degrees) used to search for the nearest Mapillary image. Defaults to 0.00005 degrees.

5e-05
width int

The width of the Mapillary image widget. Defaults to 300.

300
height int

The height of the Mapillary image widget. Defaults to 420.

420
frame_border int

The width of the frame border for the Mapillary image widget. Defaults to 0.

0
controls Optional[List[str]]

The drawing controls to be added to the map. Defaults to ["point", "polygon", "line_string", "trash"].

None
position str

The position of the drawing controls on the map. Defaults to "top-right".

'top-right'
**kwargs Any

Additional keyword arguments that may be passed to the function.

{}

Returns:

Type Description
VBox

widgets.VBox: A vertical box widget containing the map, sidebar, and control buttons.

maptiler_3d_style(style='satellite', exaggeration=1, tile_size=512, tile_type=None, max_zoom=24, hillshade=True, token='MAPTILER_KEY', api_key=None)

Get the 3D terrain style for the map.

This function generates a style dictionary for the map that includes 3D terrain features. The terrain exaggeration and API key can be specified. If the API key is not provided, it will be retrieved using the specified token.

Parameters:

Name Type Description Default
style str

The name of the MapTiler style to be accessed. It can be one of the following: aquarelle, backdrop, basic, bright, dataviz, hillshade, landscape, ocean, openstreetmap, outdoor, satellite, streets, toner, topo, winter, etc.

'satellite'
exaggeration float

The terrain exaggeration. Defaults to 1.

1
tile_size int

The size of the tiles. Defaults to 512.

512
tile_type str

The type of the tiles. It can be one of the following: webp, png, jpg. Defaults to None.

None
max_zoom int

The maximum zoom level. Defaults to 24.

24
hillshade bool

Whether to include hillshade. Defaults to True.

True
token str

The token to use to retrieve the API key. Defaults to "MAPTILER_KEY".

'MAPTILER_KEY'
api_key Optional[str]

The API key. If not provided, it will be retrieved using the token.

None

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: The style dictionary for the map.

Raises:

Type Description
ValueError

If the API key is not provided and cannot be retrieved using the token.

open_gps_trace(columns=None, ann_column=None, colormap=None, layer_name='GPS Trace', default_features=None, ann_options=None, rows=11, fig_width='1550px', fig_height='300px', time_format='%Y%m%dT%H%M%S', radius=4, stroke_color='lightgray', circle_size=48, webGL=False, download=False, sync_plots=False, column_widths=(9, 3), add_layer_args=None, arrow_args=None, map_height='600px', **kwargs)

Creates a widget for uploading and displaying a GPS trace on a map.

Parameters:

Name Type Description Default
columns List[str]

The columns to display in the GPS trace popup. Defaults to None.

None
ann_column str

The annotation column in the GPS trace.

None
colormap Dict[str, str]

The colormap for the GPS trace annotations.

None
layer_name str

The name of the GPS trace layer.

'GPS Trace'
default_features Optional[str]

The default features to display. The first numerical column will be used if None. Defaults to None.

None
ann_options Optional[List[str]]

The annotation options for the dropdown. Defaults to None.

None
rows int

The number of rows to display in the table. Defaults to 11.

11
fig_width str

The width of the figure. Defaults to "1550px".

'1550px'
fig_height str

The height of the figure. Defaults to "300px".

'300px'
time_format str

The time format for the timestamp. Defaults to "%Y-%m-%d %H:%M:%S".

'%Y%m%dT%H%M%S'
stroke_color str

The stroke color of the GPS trace points. Defaults to "lightgray".

'lightgray'
circle_size int

The size of the GPS trace points. Defaults to 48.

48
webGL bool

Whether to use WebGL (bqplot-gl) for rendering. Defaults to False.

False
download bool

Whether to generate links for downloading the edited GPS traces. Defaults to False.

False
sync_plots bool

Whether to synchronize the zoom and pan of the plots. Defaults to False.

False
column_widths Optional[List[int]]

The column widths for the output widget. Defaults to (9, 3).

(9, 3)
add_layer_args Dict[str, Any]

Additional keyword arguments to pass to the add_gps_trace method. Defaults to None.

None
arrow_args Dict[str, Any]

Additional keyword arguments to pass to the add_arrow method. Defaults to None.

None
map_height str

The height of the map. Defaults to "600px".

'600px'
**kwargs Any

Additional keyword arguments to pass to the edit_gps_trace method.

{}

Returns:

Type Description
VBox

widgets.VBox: The widget containing the GPS trace upload and display interface.

open_gps_traces(filepaths, dirname=None, widget_width='500px', columns=None, ann_column=None, colormap=None, layer_name='GPS Trace', default_features=None, ann_options=None, rows=11, fig_width='1550px', fig_height='300px', time_format='%Y%m%dT%H%M%S', radius=4, stroke_color='lightgray', circle_size=48, webGL=False, download=False, sync_plots=False, column_widths=(9, 3), add_layer_args=None, arrow_args=None, map_height='600px', **kwargs)

Creates a widget for uploading and displaying multiple GPS traces on a map.

Parameters:

Name Type Description Default
filepaths List[str]

A list of file paths to the GPS traces.

required
dirname str

The directory name for the GPS traces. Defaults to None.

None
widget_width str

The width of the dropdown file path widget. Defaults to "500px".

'500px'
columns List[str]

The columns to display in the GPS trace popup. Defaults to None.

None
ann_column str

The annotation column in the GPS trace.

None
colormap Dict[str, str]

The colormap for the GPS trace annotations.

None
layer_name str

The name of the GPS trace layer.

'GPS Trace'
default_features Optional[str]

The default features to display. The first numerical column will be used if None. Defaults to None.

None
ann_options Optional[List[str]]

The annotation options for the dropdown. Defaults to None.

None
rows int

The number of rows to display in the table. Defaults to 11.

11
fig_width str

The width of the figure. Defaults to "1550px".

'1550px'
fig_height str

The height of the figure. Defaults to "300px".

'300px'
time_format str

The time format for the timestamp. Defaults to "%Y-%m-%d %H:%M:%S".

'%Y%m%dT%H%M%S'
stroke_color str

The stroke color of the GPS trace points. Defaults to "lightgray".

'lightgray'
circle_size int

The size of the GPS trace points. Defaults to 48.

48
webGL bool

Whether to use WebGL (bqplot-gl) for rendering. Defaults to False.

False
download bool

Whether to generate links for downloading the edited GPS traces. Defaults to False.

False
sync_plots bool

Whether to synchronize the zoom and pan of the plots. Defaults to False.

False
column_widths Optional[List[int]]

The column widths for the output widget. Defaults to (9, 3).

(9, 3)
add_layer_args Dict[str, Any]

Additional keyword arguments to pass to the add_gps_trace method. Defaults to None.

None
arrow_args Dict[str, Any]

Additional keyword arguments to pass to the add_arrow method. Defaults to None.

None
map_height str

The height of the map. Defaults to "600px".

'600px'
**kwargs Any

Additional keyword arguments to pass to the edit_gps_trace method.

{}

Returns:

Type Description
VBox

widgets.VBox: The widget containing the GPS traces upload and display interface.