foliumap module¶
leafmap.foliumap
¶
CustomControl
¶
Bases: MacroElement
Put any HTML on the map as a Leaflet Control. Adopted from https://github.com/python-visualization/folium/pull/1662
__init__(html, position='bottomleft')
¶
FloatText
¶
Bases: MacroElement
Adds a floating image in HTML canvas on top of the map.
GeoTIFFLayer
¶
Bases: JSCSSMixin, Layer
Leaflet layer that renders Cloud Optimized GeoTIFFs client-side.
__init__(url, name=None, attribution='', opacity=1.0, overlay=True, control=True, show=True, fit_bounds=True, resolution=128, georaster_options=None, palette=None, value_range=None, nodata_color=None, indexes=None, sequence=0, **kwargs)
¶
Initialize the layer.
Map
¶
Bases: Map
The Map class inherits folium.Map. By default, the Map will add OpenStreetMap as the basemap.
Returns:
| Name | Type | Description |
|---|---|---|
object |
folium map object. |
add(object, **kwargs)
¶
Adds something to the map. This method is not implemented in folium.
add_basemap(basemap='HYBRID', show=True, **kwargs)
¶
Adds a basemap to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
basemap
|
str
|
Can be one of string from ee_basemaps. Defaults to 'HYBRID'. |
'HYBRID'
|
show
|
bool
|
Whether to show the basemap. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments to pass to folium.TileLayer. |
{}
|
add_census_data(wms, layer, census_dict=None, **kwargs)
¶
Adds a census data layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wms
|
str
|
The wms to use. For example, "Current", "ACS 2021", "Census 2020". See the complete list at https://tigerweb.geo.census.gov/tigerwebmain/TIGERweb_wms.html |
required |
layer
|
str
|
The layer name to add to the map. |
required |
census_dict
|
dict
|
A dictionary containing census data. Defaults to None. It can be obtained from the get_census_dict() function. |
None
|
add_circle_markers_from_xy(data, x='longitude', y='latitude', radius=10, popup=None, tooltip=None, min_width=100, max_width=200, font_size=2, **kwargs)
¶
Adds a marker cluster to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | DataFrame
|
A csv or Pandas DataFrame containing x, y, z values. |
required |
x
|
str
|
The column name for the x values. Defaults to "longitude". |
'longitude'
|
y
|
str
|
The column name for the y values. Defaults to "latitude". |
'latitude'
|
radius
|
int
|
The radius of the circle. Defaults to 10. |
10
|
popup
|
list
|
A list of column names to be used as the popup. Defaults to None. |
None
|
tooltip
|
list
|
A list of column names to be used as the tooltip. Defaults to None. |
None
|
min_width
|
int
|
The minimum width of the popup. Defaults to 100. |
100
|
max_width
|
int
|
The maximum width of the popup. Defaults to 200. |
200
|
font_size
|
int
|
The font size of the popup. Defaults to 2. |
2
|
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, shown=True, rescale=None, colormap_name=None, color_formula=None, titiler_cmr_endpoint=None, zoom_to_layer=True, **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
|
shown
|
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
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer extent. Defaults to True. |
True
|
**kwargs
|
Additional arguments passed to the TiTiler CMR endpoint. |
{}
|
Examples:
1 2 3 4 5 6 7 8 9 10 11 | |
add_cog_layer(url, name='Untitled', attribution='.', opacity=1.0, shown=True, bands=None, titiler_endpoint=None, zoom_to_layer=True, **kwargs)
¶
Adds a COG TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the COG tile layer. |
required |
name
|
str
|
The layer name to use for the layer. Defaults to 'Untitled'. |
'Untitled'
|
attribution
|
str
|
The attribution to use. Defaults to '.'. |
'.'
|
opacity
|
float
|
The opacity of the layer. Defaults to 1. |
1.0
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
bands
|
list
|
A list of bands to use. Defaults to None. |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://titiler.opengeos.org". |
None
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer extent. Defaults to True. |
True
|
**kwargs
|
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 |
{}
|
add_colorbar(colors, vmin=0, vmax=1, index=None, caption='', categorical=False, step=None, **kwargs)
¶
Add a colorbar to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colors
|
list
|
The set of colors to be used for interpolation. Colors can be provided in the form: * tuples of RGBA ints between 0 and 255 (e.g: (255, 255, 0) or (255, 255, 0, 255)) * tuples of RGBA floats between 0. and 1. (e.g: (1.,1.,0.) or (1., 1., 0., 1.)) * HTML-like string (e.g: “#ffff00) * a color name or shortcut (e.g: “y” or “yellow”) |
required |
vmin
|
int
|
The minimal value for the colormap. Values lower than vmin will be bound directly to colors[0].. Defaults to 0. |
0
|
vmax
|
float
|
The maximal value for the colormap. Values higher than vmax will be bound directly to colors[-1]. Defaults to 1.0. |
1
|
index
|
list
|
The values corresponding to each color. It has to be sorted, and have the same length as colors. If None, a regular grid between vmin and vmax is created.. Defaults to None. |
None
|
caption
|
str
|
The caption for the colormap. Defaults to "". |
''
|
categorical
|
bool
|
Whether or not to create a categorical colormap. Defaults to False. |
False
|
step
|
int
|
The step to split the LinearColormap into a StepColormap. Defaults to None. |
None
|
add_colormap(width=4.0, height=0.3, vmin=0, vmax=1.0, palette=None, vis_params=None, cmap='gray', discrete=False, label=None, label_size=12, label_weight='normal', tick_size=10, bg_color='white', orientation='horizontal', dpi='figure', transparent=False, position=(70, 5), **kwargs)
¶
Add a colorbar to the map. Under the hood, it uses matplotlib to generate the colorbar, save it as a png file, and add it to the map using m.add_image().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Width of the colorbar in inches. Default is 4.0. |
4.0
|
height
|
float
|
Height of the colorbar in inches. Default is 0.3. |
0.3
|
vmin
|
float
|
Minimum value of the colorbar. Default is 0. |
0
|
vmax
|
float
|
Maximum value of the colorbar. Default is 1.0. |
1.0
|
palette
|
list
|
List of colors to use for the colorbar. It can also be a cmap name, such as ndvi, ndwi, dem, coolwarm. Default is None. |
None
|
vis_params
|
dict
|
Visualization parameters as a dictionary. See https://developers.google.com/earth-engine/guides/image_visualization for options. |
None
|
cmap
|
str
|
Matplotlib colormap. Defaults to "gray". See https://matplotlib.org/3.3.4/tutorials/colors/colormaps.html#sphx-glr-tutorials-colors-colormaps-py for options. |
'gray'
|
discrete
|
bool
|
Whether to create a discrete colorbar. Defaults to False. |
False
|
label
|
str
|
Label for the colorbar. Defaults to None. |
None
|
label_size
|
int
|
Font size for the colorbar label. Defaults to 12. |
12
|
label_weight
|
str
|
Font weight for the colorbar label, can be "normal", "bold", etc. Defaults to "normal". |
'normal'
|
tick_size
|
int
|
Font size for the colorbar tick labels. Defaults to 10. |
10
|
bg_color
|
str
|
Background color for the colorbar. Defaults to "white". |
'white'
|
orientation
|
str
|
Orientation of the colorbar, such as "vertical" and "horizontal". Defaults to "horizontal". |
'horizontal'
|
dpi
|
float | str
|
The resolution in dots per inch. If 'figure', use the figure's dpi value. Defaults to "figure". |
'figure'
|
transparent
|
bool
|
Whether to make the background transparent. Defaults to False. |
False
|
position
|
tuple
|
The position of the colormap in the format of (x, y), the percentage ranging from 0 to 100, starting from the lower-left corner. Defaults to (0, 0). |
(70, 5)
|
**kwargs
|
Other keyword arguments to pass to matplotlib.pyplot.savefig(). |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Path to the output image. |
add_data(data, column, cmap=None, colors=None, labels=None, scheme='Quantiles', k=5, add_legend=True, legend_title=None, legend_position='bottomright', legend_kwds=None, classification_kwds=None, style_function=None, highlight_function=None, layer_name='Untitled', info_mode='on_hover', encoding='utf-8', opacity=1.0, **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 'topleft', 'topright', 'bottomleft', or 'bottomright'. Defaults to 'bottomright'. |
'bottomright'
|
legend_kwds
|
dict
|
Keyword arguments to pass to :func: |
None
|
classification_kwds
|
dict
|
Keyword arguments to pass to mapclassify. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style_function
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. style_callback is a function that takes the feature as argument and should return a dictionary of the following form: style_callback = lambda feat: {"fillColor": feat["properties"]["color"]} style is a dictionary of the following form: style = { "stroke": False, "color": "#ff0000", "weight": 1, "opacity": 1, "fill": True, "fillColor": "#ffffff", "fillOpacity": 1.0, "dashArray": "9" "clickable": True, } |
None
|
hightlight_function
|
function
|
Highlighting function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. highlight_function is a function that takes the feature as argument and should return a dictionary of the following form: highlight_function = lambda feat: {"fillColor": feat["properties"]["color"]} |
required |
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
encoding
|
str
|
The encoding of the GeoJSON file. Defaults to "utf-8". |
'utf-8'
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
**kwargs
|
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_ee_layer(ee_object=None, vis_params={}, asset_id=None, name=None, attribution='Google Earth Engine', shown=True, opacity=1.0, **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}. |
{}
|
asset_id
|
str
|
The ID of the Earth Engine asset. |
None
|
name
|
str
|
The name of the tile layer. If not provided, the asset ID will be used. Default is None. |
None
|
attribution
|
str
|
The attribution text to be displayed. Default is "Google Earth Engine". |
'Google Earth Engine'
|
shown
|
bool
|
Whether the tile layer should be shown on the map. Default is True. |
True
|
opacity
|
float
|
The opacity of the tile layer. Default is 1.0. |
1.0
|
**kwargs
|
Additional keyword arguments to be passed to the underlying |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
add_fire_data(data=None, bbox=None, place=None, collection='snapshot_perimeter_nrt', datetime=None, farea_min=None, layer_name='Fire Perimeters', style=None, style_callback=None, info_mode='on_hover', zoom_to_layer=True, **kwargs)
¶
Add NASA fire perimeter data to the map.
This method fetches and displays fire perimeter data from the NASA Fire Event Data Suite (FEDs) via the OpenVEDA OGC API Features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Optional[Union[str, GeoDataFrame]]
|
Pre-loaded fire data as a file path or GeoDataFrame. If provided, bbox and place are ignored. |
None
|
bbox
|
Optional[List[float]]
|
Bounding box [west, south, east, north] in EPSG:4326. |
None
|
place
|
Optional[str]
|
Place name to geocode (e.g., "California"). |
None
|
collection
|
str
|
Fire collection ID. Options: - "snapshot_perimeter_nrt": 20-day recent fire perimeters (default) - "lf_perimeter_nrt": Current year large fires (>5 km²) - "lf_perimeter_archive": 2018-2021 Western US archived fires - "lf_fireline_nrt": Active fire lines - "lf_newfirepix_nrt": New fire pixels |
'snapshot_perimeter_nrt'
|
datetime
|
Optional[str]
|
ISO 8601 date/time or interval (e.g., "2024-07-01/2024-07-31"). |
None
|
farea_min
|
Optional[float]
|
Minimum fire area in km² to filter results. |
None
|
layer_name
|
str
|
Name for the layer. Defaults to "Fire Perimeters". |
'Fire Perimeters'
|
style
|
Optional[Dict]
|
Style dictionary for the fire perimeters. Defaults to orange/red. |
None
|
style_callback
|
Optional[Callable]
|
Styling function called for each feature. |
None
|
info_mode
|
str
|
Display attributes "on_hover" or "on_click". |
'on_hover'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer bounds. |
True
|
**kwargs
|
Additional keyword arguments for add_gdf(). |
{}
|
Example
m = leafmap.Map() m.add_fire_data(place="California", datetime="2024-07-01/2024-07-31") m
add_fire_perimeters(bbox=None, place=None, collection='snapshot_perimeter_nrt', datetime=None, farea_min=None, color_column='farea', cmap='YlOrRd', layer_name='Fire Perimeters', style=None, info_mode='on_hover', zoom_to_layer=True, add_legend=True, legend_title='Fire Area (km²)', **kwargs)
¶
Add fire perimeters with color scaling based on fire attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Optional[List[float]]
|
Bounding box [west, south, east, north] in EPSG:4326. |
None
|
place
|
Optional[str]
|
Place name to geocode (e.g., "California"). |
None
|
collection
|
str
|
Fire collection ID. Defaults to "snapshot_perimeter_nrt". |
'snapshot_perimeter_nrt'
|
datetime
|
Optional[str]
|
ISO 8601 date/time or interval. |
None
|
farea_min
|
Optional[float]
|
Minimum fire area in km² to filter results. |
None
|
color_column
|
Optional[str]
|
Column to use for color scaling. Defaults to "farea". |
'farea'
|
cmap
|
str
|
Colormap name for color scaling. Defaults to "YlOrRd". |
'YlOrRd'
|
layer_name
|
str
|
Name for the layer. |
'Fire Perimeters'
|
style
|
Optional[Dict]
|
Base style dictionary (color will be overridden by colormap). |
None
|
info_mode
|
str
|
Display attributes "on_hover" or "on_click". |
'on_hover'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer bounds. |
True
|
add_legend
|
bool
|
Whether to add a legend. Defaults to True. |
True
|
legend_title
|
str
|
Title for the legend. |
'Fire Area (km²)'
|
**kwargs
|
Additional keyword arguments for add_gdf(). |
{}
|
Example
m = leafmap.Map() m.add_fire_perimeters( ... place="California", ... datetime="2024-07-01/2024-07-31", ... color_column="farea" ... ) m
add_fire_timeseries(fire_id, collection='snapshot_perimeter_nrt', datetime=None, time_column='t', layer_name='Fire Evolution', style=None, **kwargs)
¶
Add fire perimeter evolution over time.
Note: Time slider functionality is not supported in the folium backend. This method displays all perimeters as a single layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fire_id
|
str
|
The fire ID to track over time. |
required |
collection
|
str
|
Fire collection ID. Defaults to "snapshot_perimeter_nrt". |
'snapshot_perimeter_nrt'
|
datetime
|
Optional[str]
|
ISO 8601 date/time or interval to filter by. |
None
|
time_column
|
str
|
Column containing timestamps. Defaults to "t". |
't'
|
layer_name
|
str
|
Name for the layer. |
'Fire Evolution'
|
style
|
Optional[Dict]
|
Style dictionary for the fire perimeters. |
None
|
**kwargs
|
Additional keyword arguments for add_gdf(). |
{}
|
Example
m = leafmap.Map() m.add_fire_timeseries(fire_id="2024_CA_001") m
add_gdf(gdf, layer_name='Untitled', zoom_to_layer=True, info_mode='on_hover', opacity=1.0, **kwargs)
¶
Adds a GeoPandas GeoDataFrameto the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoPandas GeoDataFrame. |
required |
layer_name
|
str
|
The layer name to be used. Defaults to "Untitled". |
'Untitled'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer. |
True
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
add_gdf_from_postgis(sql, con, layer_name='Untitled', zoom_to_layer=True, info_mode='on_hover', **kwargs)
¶
Adds a GeoPandas GeoDataFrameto the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
SQL query to execute in selecting entries from database, or name of the table to read from the database. |
required |
con
|
Engine
|
Active connection to the database to query. |
required |
layer_name
|
str
|
The layer name to be used. Defaults to "Untitled". |
'Untitled'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer. |
True
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
add_geojson(in_geojson, layer_name='Untitled', encoding='utf-8', info_mode='on_hover', opacity=1.0, zoom_to_layer=True, **kwargs)
¶
Adds a GeoJSON file to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str
|
The input file path to the GeoJSON. |
required |
layer_name
|
str
|
The layer name to be used. Defaults to "Untitled". |
'Untitled'
|
encoding
|
str
|
The encoding of the GeoJSON file. Defaults to "utf-8". |
'utf-8'
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The provided GeoJSON file could not be found. |
add_geotiff(url, name='GeoTIFF', attribution='', opacity=1.0, shown=True, overlay=True, control=True, fit_bounds=True, resolution=128, georaster_options=None, palette=None, nodata_color=None, indexes=None, vmin=None, vmax=None, **kwargs)
¶
Adds a remote Cloud Optimized GeoTIFF (COG) directly to the map.
The layer is rendered client-side with the georaster-layer-for-leaflet plugin, letting Leaflet read and display Cloud Optimized GeoTIFFs without relying on an intermediate tiling service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to the GeoTIFF/COG resource. |
required |
name
|
str
|
Name for the layer control entry. Defaults to "GeoTIFF". |
'GeoTIFF'
|
attribution
|
str
|
Attribution text for the layer. Defaults to "". |
''
|
opacity
|
float
|
Layer opacity between 0.0 and 1.0. Defaults to 1.0. |
1.0
|
shown
|
bool
|
Whether the layer is visible on load. Defaults to True. |
True
|
overlay
|
bool
|
Whether the layer is an overlay (True) or base layer (False). Defaults to True. |
True
|
control
|
bool
|
Whether to register the layer with the map's layer control. Defaults to True. |
True
|
fit_bounds
|
bool
|
Fit the map view to the layer bounds once loaded. Defaults to True. |
True
|
resolution
|
int
|
Internal resolution passed to the GeoRaster layer. Defaults to 128. |
128
|
georaster_options
|
Dict[str, Any]
|
Extra options forwarded to GeoRasterLayer. |
None
|
palette
|
str | Sequence[str]
|
Name of a built-in palette or a sequence of color hex strings to visualize single-band rasters. |
None
|
value_range
|
Sequence[float]
|
Two values defining the data range mapped to the palette. Defaults to the GeoTIFF min/max. |
required |
nodata_color
|
str
|
Color used when encountering nodata or NaN values. Defaults to transparent. |
None
|
indexes
|
Sequence[int]
|
List of band indexes to visualize (e.g., [1, 2, 3] for RGB or [4, 3, 2] for false color). Band indexes are 1-based. Defaults to None (all bands). |
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
|
kwargs
|
dict
|
Additional arguments to pass to the GeoTIFFLayer. Defaults to {}. |
{}
|
add_heatmap(data, latitude='latitude', longitude='longitude', value='value', name='Heat map', radius=25, **kwargs)
¶
Adds a heat map to the map. Reference: https://stackoverflow.com/a/54756617
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | list | DataFrame
|
File path or HTTP URL to the input file or a list of data points in the format of [[x1, y1, z1], [x2, y2, z2]]. For example, https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/world_cities.csv |
required |
latitude
|
str
|
The column name of latitude. Defaults to "latitude". |
'latitude'
|
longitude
|
str
|
The column name of longitude. Defaults to "longitude". |
'longitude'
|
value
|
str
|
The column name of values. Defaults to "value". |
'value'
|
name
|
str
|
Layer name to use. Defaults to "Heat map". |
'Heat map'
|
radius
|
int
|
Radius of each “point” of the heatmap. Defaults to 25. |
25
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is not a list. |
add_html(html, position='bottomright', **kwargs)
¶
Add HTML to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html
|
str
|
The HTML to add. |
required |
position
|
str
|
The position of the widget. Defaults to "bottomright". |
'bottomright'
|
add_image(image, position=(0, 0), **kwargs)
¶
Add an image to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str | Image
|
The image to add. |
required |
position
|
tuple
|
The position of the image in the format of (x, y), the percentage ranging from 0 to 100, starting from the lower-left corner. Defaults to (0, 0). |
(0, 0)
|
add_kml(in_kml, layer_name='Untitled', info_mode='on_hover', **kwargs)
¶
Adds a KML file to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_kml
|
str
|
The input file path to the KML. |
required |
layer_name
|
str
|
The layer name to be used. Defaults to "Untitled". |
'Untitled'
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The provided KML file could not be found. |
add_labels(data, column, font_size='12pt', font_color='black', font_family='arial', font_weight='normal', x='longitude', y='latitude', draggable=True, layer_name='Labels', **kwargs)
¶
Adds a label layer to the map. Reference: https://python-visualization.github.io/folium/modules.html#folium.features.DivIcon
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame | GeoDataFrame | str
|
The input data to label. |
required |
column
|
str
|
The column name of the data to label. |
required |
font_size
|
str
|
The font size of the labels. Defaults to "12pt". |
'12pt'
|
font_color
|
str
|
The font color of the labels. Defaults to "black". |
'black'
|
font_family
|
str
|
The font family of the labels. Defaults to "arial". |
'arial'
|
font_weight
|
str
|
The font weight of the labels, can be normal, bold. Defaults to "normal". |
'normal'
|
x
|
str
|
The column name of the longitude. Defaults to "longitude". |
'longitude'
|
y
|
str
|
The column name of the latitude. Defaults to "latitude". |
'latitude'
|
draggable
|
bool
|
Whether the labels are draggable. Defaults to True. |
True
|
layer_name
|
str
|
The name of the layer. Defaults to "Labels". |
'Labels'
|
add_layer(layer)
¶
Adds a layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
TileLayer
|
A TileLayer instance. |
required |
add_layer_control()
¶
Adds layer control to the map.
add_legend(title='Legend', labels=None, colors=None, legend_dict=None, builtin_legend=None, opacity=1.0, position='bottomright', draggable=True, style={}, shape_type='rectangle')
¶
Adds a customized legend to the map. Reference: https://bit.ly/3oV6vnH.
If you want to add multiple legends to the map, you need to set the draggable argument to False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title of the legend. Defaults to 'Legend'. Defaults to "Legend". |
'Legend'
|
colors
|
list
|
A list of legend colors. Defaults to None. |
None
|
labels
|
list
|
A list of legend labels. Defaults to None. |
None
|
legend_dict
|
dict
|
A dictionary containing legend items as keys and color as values. If provided, legend_keys and legend_colors will be ignored. Defaults to None. |
None
|
builtin_legend
|
str
|
Name of the builtin legend to add to the map. Defaults to None. |
None
|
opacity
|
float
|
The opacity of the legend. Defaults to 1.0. |
1.0
|
position
|
str
|
The position of the legend, can be one of the following: "topleft", "topright", "bottomleft", "bottomright". Defaults to "bottomright". Note that position is only valid when draggable is False. |
'bottomright'
|
draggable
|
bool
|
If True, the legend can be dragged to a new position. Defaults to True. |
True
|
style
|
Optional[Dict]
|
Additional keyword arguments to style the legend, such as position, bottom, right, z-index, border, background-color, border-radius, padding, font-size, etc. The default style is: style = { 'position': 'fixed', 'z-index': '9999', 'border': '2px solid grey', 'background-color': 'rgba(255, 255, 255, 0.8)', 'border-radius': '5px', 'padding': '10px', 'font-size': '14px', 'bottom': '20px', 'right': '5px' } |
{}
|
shape_type
|
str
|
The shape type of the legend item. It can be either "rectangle", "line" or "circle". Defaults to "rectangle". |
'rectangle'
|
add_marker(location, popup=None, tooltip=None, icon=None, draggable=False, **kwargs)
¶
Adds a marker to the map. More info about marker options at https://python-visualization.github.io/folium/modules.html#folium.map.Marker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
list | tuple
|
The location of the marker in the format of [lat, lng]. |
required |
popup
|
str
|
The popup text. Defaults to None. |
None
|
tooltip
|
str
|
The tooltip text. Defaults to None. |
None
|
icon
|
str
|
The icon to use. Defaults to None. |
None
|
draggable
|
bool
|
Whether the marker is draggable. Defaults to False. |
False
|
add_markers_from_xy(data, x='longitude', y='latitude', popup=None, min_width=100, max_width=200, layer_name='Markers', icon=None, icon_shape='circle-dot', border_width=3, border_color='#0000ff', **kwargs)
¶
Adds markers to the map from a csv or Pandas DataFrame containing x, y values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | DataFrame
|
A csv or Pandas DataFrame containing x, y, z values. |
required |
x
|
str
|
The column name for the x values. Defaults to "longitude". |
'longitude'
|
y
|
str
|
The column name for the y values. Defaults to "latitude". |
'latitude'
|
popup
|
list
|
A list of column names to be used as the popup. Defaults to None. |
None
|
min_width
|
int
|
The minimum width of the popup. Defaults to 100. |
100
|
max_width
|
int
|
The maximum width of the popup. Defaults to 200. |
200
|
layer_name
|
str
|
The name of the layer. Defaults to "Marker Cluster". |
'Markers'
|
icon
|
str
|
The Font-Awesome icon name to use to render the marker. Defaults to None. |
None
|
icon_shape
|
str
|
The shape of the marker, such as "retangle-dot", "circle-dot". Defaults to 'circle-dot'. |
'circle-dot'
|
border_width
|
int
|
The width of the border. Defaults to 3. |
3
|
border_color
|
str
|
The color of the border. Defaults to '#0000ff'. |
'#0000ff'
|
kwargs
|
dict
|
Additional keyword arguments to pass to BeautifyIcon. See https://python-visualization.github.io/folium/plugins.html#folium.plugins.BeautifyIcon. |
{}
|
add_minimap(zoom=5, position='bottomright')
¶
Adds a minimap (overview) to the ipyleaflet map.
add_mosaic_layer(url, titiler_endpoint=None, name='Mosaic Layer', attribution='.', opacity=1.0, shown=True, **kwargs)
¶
Adds a STAC TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a MosaicJSON. |
required |
titiler_endpoint
|
str
|
TiTiler endpoint, e.g., "https://titiler.opengeos.org". Defaults to None. |
None
|
name
|
str
|
The layer name to use for the layer. Defaults to 'Mosaic Layer'. |
'Mosaic Layer'
|
attribution
|
str
|
The attribution to use. Defaults to ''. |
'.'
|
opacity
|
float
|
The opacity of the layer. Defaults to 1. |
1.0
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
add_netcdf(filename, variables=None, port='default', palette=None, vmin=None, vmax=None, nodata=None, attribution=None, layer_name='NetCDF layer', shift_lon=True, lat='lat', lon='lon', **kwargs)
¶
Generate an ipyleaflet/folium TileLayer from a netCDF file. If you are using this function in JupyterHub on a remote server (e.g., Binder, Microsoft Planetary Computer), try adding to following two lines to the beginning of the notebook if the raster does not render properly.
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
File path or HTTP URL to the netCDF file. |
required |
variables
|
int
|
The variable/band names to extract data from the netCDF file. Defaults to None. If None, all variables will be extracted. |
None
|
port
|
str
|
The port to use for the server. Defaults to "default". |
'default'
|
palette
|
str
|
The name of the color palette from |
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
|
attribution
|
str
|
Attribution for the source raster. This defaults to a message about it being a local file.. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to use. Defaults to "netCDF layer". |
'NetCDF layer'
|
shift_lon
|
bool
|
Flag to shift longitude values from [0, 360] to the range [-180, 180]. Defaults to True. |
True
|
lat
|
str
|
Name of the latitude variable. Defaults to 'lat'. |
'lat'
|
lon
|
str
|
Name of the longitude variable. Defaults to 'lon'. |
'lon'
|
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, col_name='WETLAND_TY', add_legend=True, style_callback=None, layer_name='Wetlands', **kwargs)
¶
Adds National Wetlands Inventory (NWI) data to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, GeoDataFrame]
|
The NWI data to add. It can be a file path or a GeoDataFrame. |
required |
col_name
|
str
|
The column name to use for styling. Defaults to "WETLAND_TY". |
'WETLAND_TY'
|
add_legend
|
bool
|
Whether to add a legend to the map. Defaults to True. |
True
|
style_callback
|
Optional[Callable[[dict], dict]]
|
A callback function to style the features. Defaults to None. |
None
|
layer_name
|
str
|
The name of the layer to add. Defaults to "Wetlands". |
'Wetlands'
|
**kwargs
|
Additional keyword arguments to pass to the add_vector or add_gdf method. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
add_opacity_control(layer=None, position='bottomright', min_opacity=0.0, max_opacity=1.0, step=0.05)
¶
Adds a Leaflet-based opacity control for Folium layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str
|
Name of the layer to preselect. Defaults to the first available layer. |
None
|
position
|
str
|
Leaflet control position. Defaults to |
'bottomright'
|
min_opacity
|
float
|
Minimum slider value. Defaults to 0.0. |
0.0
|
max_opacity
|
float
|
Maximum slider value. Defaults to 1.0. |
1.0
|
step
|
float
|
Slider step. Defaults to 0.05. |
0.05
|
add_osm_from_address(address, tags, dist=1000, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=['black'], info_mode='on_hover')
¶
Adds OSM entities within some distance N, S, E, W of address to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The address to geocode and use as the central point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
['black']
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
add_osm_from_bbox(north, south, east, west, tags, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=['black'], info_mode='on_hover')
¶
Adds OSM entities within a N, S, E, W bounding box to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
north
|
float
|
Northern latitude of bounding box. |
required |
south
|
float
|
Southern latitude of bounding box. |
required |
east
|
float
|
Eastern longitude of bounding box. |
required |
west
|
float
|
Western longitude of bounding box. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
['black']
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
add_osm_from_geocode(query, which_result=None, by_osmid=False, buffer_dist=None, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=['black'], info_mode='on_hover')
¶
Adds OSM data of place(s) by name or ID to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
by_osmid
|
bool
|
If True, handle query as an OSM ID for lookup rather than text search. Defaults to False. |
False
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
['black']
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
add_osm_from_place(query, tags, which_result=None, buffer_dist=None, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=['black'], info_mode='on_hover')
¶
Adds OSM entities within boundaries of geocodable place(s) to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
['black']
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
add_osm_from_point(center_point, tags, dist=1000, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=['black'], info_mode='on_hover')
¶
Adds OSM entities within some distance N, S, E, W of a point to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_point
|
tuple
|
The (lat, lng) center point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
['black']
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
add_osm_from_polygon(polygon, tags, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=['black'], info_mode='on_hover')
¶
Adds OSM entities within boundaries of a (multi)polygon to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Geographic boundaries to fetch geometries within |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
['black']
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
add_osm_from_view(tags, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=['black'], info_mode='on_hover')
¶
Adds OSM entities within the current map view to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
['black']
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
add_planet_by_month(year=2016, month=1, layer_name=None, api_key=None, token_name='PLANET_API_KEY', **kwargs)
¶
Adds a Planet global mosaic by month to the map. To get a Planet API key, see https://developers.planet.com/quickstart/apis
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The year of Planet global mosaic, must be >=2016. Defaults to 2016. |
2016
|
month
|
int
|
The month of Planet global mosaic, must be 1-12. Defaults to 1. |
1
|
layer_name
|
str
|
The layer name to use. Defaults to None. |
None
|
api_key
|
str
|
The Planet API key. Defaults to None. |
None
|
token_name
|
str
|
The environment variable name of the API key. Defaults to "PLANET_API_KEY". |
'PLANET_API_KEY'
|
add_planet_by_quarter(year=2016, quarter=1, layer_name=None, api_key=None, token_name='PLANET_API_KEY', **kwargs)
¶
Adds a Planet global mosaic by quarter to the map. To get a Planet API key, see https://developers.planet.com/quickstart/apis
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The year of Planet global mosaic, must be >=2016. Defaults to 2016. |
2016
|
quarter
|
int
|
The quarter of Planet global mosaic, must be 1-12. Defaults to 1. |
1
|
layer_name
|
str
|
The layer name to use. Defaults to None. |
None
|
api_key
|
str
|
The Planet API key. Defaults to None. |
None
|
token_name
|
str
|
The environment variable name of the API key. Defaults to "PLANET_API_KEY". |
'PLANET_API_KEY'
|
add_pmtiles(url, style=None, name=None, tooltip=True, overlay=True, control=True, show=True, zoom_to_layer=True, **kwargs)
¶
Adds a PMTiles layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the PMTiles file. |
required |
style
|
str
|
The CSS style to apply to the layer. Defaults to None. See https://docs.mapbox.com/style-spec/reference/layers/ for more info. |
None
|
name
|
str
|
The name of the layer. Defaults to None. |
None
|
tooltip
|
bool
|
Whether to show a tooltip when hovering over the layer. Defaults to True. |
True
|
overlay
|
bool
|
Whether the layer should be added as an overlay. Defaults to True. |
True
|
control
|
bool
|
Whether to include the layer in the layer control. Defaults to True. |
True
|
show
|
bool
|
Whether the layer should be shown initially. Defaults to True. |
True
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer extent. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments to pass to the PMTilesLayer constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
add_point_layer(filename, popup=None, layer_name='Marker Cluster', **kwargs)
¶
Adds a point layer to the map with a popup attribute.
add_points_from_xy(data, x='longitude', y='latitude', popup=None, min_width=100, max_width=200, layer_name='Marker Cluster', color_column=None, marker_colors=None, icon_colors=['white'], icon_names=['info'], angle=0, prefix='fa', add_legend=True, max_cluster_radius=80, **kwargs)
¶
Adds a marker cluster to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | DataFrame
|
A csv or Pandas DataFrame containing x, y, z values. |
required |
x
|
str
|
The column name for the x values. Defaults to "longitude". |
'longitude'
|
y
|
str
|
The column name for the y values. Defaults to "latitude". |
'latitude'
|
popup
|
list
|
A list of column names to be used as the popup. Defaults to None. |
None
|
min_width
|
int
|
The minimum width of the popup. Defaults to 100. |
100
|
max_width
|
int
|
The maximum width of the popup. Defaults to 200. |
200
|
layer_name
|
str
|
The name of the layer. Defaults to "Marker Cluster". |
'Marker Cluster'
|
color_column
|
str
|
The column name for the color values. Defaults to None. |
None
|
marker_colors
|
list
|
A list of colors to be used for the markers. Defaults to None. |
None
|
icon_colors
|
list
|
A list of colors to be used for the icons. Defaults to ['white']. |
['white']
|
icon_names
|
list
|
A list of names to be used for the icons. More icons can be found at https://fontawesome.com/v4/icons or https://getbootstrap.com/docs/3.3/components/?utm_source=pocket_mylist. Defaults to ['info']. |
['info']
|
angle
|
int
|
The angle of the icon. Defaults to 0. |
0
|
prefix
|
str
|
The prefix states the source of the icon. 'fa' for font-awesome or 'glyphicon' for bootstrap 3. Defaults to 'fa'. |
'fa'
|
add_legend
|
bool
|
If True, a legend will be added to the map. Defaults to True. |
True
|
max_cluster_radius
|
int
|
The maximum radius that a cluster will cover from the central marker (in pixels). |
80
|
**kwargs
|
Other keyword arguments to pass to folium.MarkerCluster(). For a list of available options, see https://github.com/Leaflet/Leaflet.markercluster. For example, to change the cluster radius, use options={"maxClusterRadius": 50}. |
{}
|
add_polars(df, geometry='geometry', crs=None, layer_name='Untitled', zoom_to_layer=True, info_mode='on_hover', opacity=1.0, **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_name
|
str
|
The layer name to be used. Defaults to "Untitled". |
'Untitled'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer. Defaults to True. |
True
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
**kwargs
|
Additional keyword arguments to pass to add_gdf. |
{}
|
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 | |
add_raster(source, indexes=None, colormap=None, vmin=None, vmax=None, nodata=None, attribution=None, layer_name='Raster', array_args={}, **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 | |
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 |
None
|
vmin
|
float
|
The minimum value to use when colormapping the colormap when plotting a single band. Defaults to None. |
None
|
vmax
|
float
|
The maximum value to use when colormapping the colormap 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
|
attribution
|
str
|
Attribution for the source raster. This defaults to a message about it being a local file.. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to use. Defaults to 'Raster'. |
'Raster'
|
array_args
|
dict
|
Additional arguments to pass to |
{}
|
add_raster_legacy(image, bands=None, layer_name=None, colormap=None, x_dim='x', y_dim='y')
¶
Adds a local raster dataset to the map.
add_remote_tile(source, indexes=None, colormap=None, vmin=None, vmax=None, nodata=None, attribution=None, layer_name=None, **kwargs)
¶
Add a remote Cloud Optimized GeoTIFF (COG) to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The path to the remote 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 |
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
|
attribution
|
str
|
Attribution for the source raster. This defaults to a message about it being a local file.. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to use. Defaults to None. |
None
|
add_search_control(url, marker=None, zoom=None, position='topleft', **kwargs)
¶
Adds a search control to the map.
add_shp(in_shp, layer_name='Untitled', info_mode='on_hover', zoom_to_layer=True, **kwargs)
¶
Adds a shapefile to the map. See https://python-visualization.github.io/folium/modules.html#folium.features.GeoJson for more info about setting style.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_shp
|
str
|
The input file path or HTTP URL (*.zip) to the shapefile. |
required |
layer_name
|
str
|
The layer name to be used. Defaults to "Untitled". |
'Untitled'
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The provided shapefile could not be found. |
add_stac_layer(url=None, collection=None, item=None, assets=None, bands=None, titiler_endpoint=None, name='STAC Layer', attribution='.', opacity=1.0, shown=True, fit_bounds=True, **kwargs)
¶
Adds a STAC TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a STAC item, e.g., https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json |
None
|
collection
|
str
|
The Microsoft Planetary Computer STAC collection ID, e.g., landsat-8-c2-l2. |
None
|
item
|
str
|
The Microsoft Planetary Computer STAC item ID, e.g., LC08_L2SP_047027_20201204_02_T1. |
None
|
assets
|
str | list
|
The Microsoft Planetary Computer STAC asset ID, e.g., ["SR_B7", "SR_B5", "SR_B4"]. |
None
|
bands
|
list
|
A list of band names, e.g., ["SR_B7", "SR_B5", "SR_B4"] |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint, e.g., "https://titiler.opengeos.org", "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
|
shown
|
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
|
add_text(text, fontsize=20, fontcolor='black', bold=False, padding='5px', background=True, bg_color='white', border_radius='5px', position='bottomright', **kwargs)
¶
Add text to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to add. |
required |
fontsize
|
int
|
The font size. Defaults to 20. |
20
|
fontcolor
|
str
|
The font color. Defaults to "black". |
'black'
|
bold
|
bool
|
Whether to use bold font. Defaults to False. |
False
|
padding
|
str
|
The padding. Defaults to "5px". |
'5px'
|
background
|
bool
|
Whether to use background. Defaults to True. |
True
|
bg_color
|
str
|
The background color. Defaults to "white". |
'white'
|
border_radius
|
str
|
The border radius. Defaults to "5px". |
'5px'
|
position
|
str
|
The position of the widget. Defaults to "bottomright". |
'bottomright'
|
add_tile_layer(url, name, attribution, overlay=True, control=True, shown=True, opacity=1.0, API_key=None, **kwargs)
¶
Add a XYZ tile layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the XYZ tile service. |
required |
name
|
str
|
The layer name to use on the layer control. |
required |
attribution
|
str
|
The attribution of the data layer. |
required |
overlay
|
bool
|
Allows overlay. Defaults to True. |
True
|
control
|
bool
|
Adds the layer to the layer control. Defaults to True. |
True
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
opacity
|
float
|
Sets the opacity for the layer. |
1.0
|
API_key
|
str
|
– API key for Cloudmade or Mapbox tiles. Defaults to True. |
None
|
add_time_slider(layers_dict={}, labels=None, time_interval=1, position='bottomright', slider_length='150px', **kwargs)
¶
Adds a time slider to the map.
add_title(title, align='center', font_size='16px', style=None)
¶
Adds a title to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
The title to use. |
required |
align
|
str
|
The alignment of the title, can be ["center", "left", "right"]. Defaults to "center". |
'center'
|
font_size
|
str
|
The font size in the unit of px. Defaults to "16px". |
'16px'
|
style
|
[type]
|
The style to use. Defaults to None. |
None
|
add_vector(filename, layer_name='Untitled', bbox=None, mask=None, rows=None, info_mode='on_hover', zoom_to_layer=True, opacity=1.0, **kwargs)
¶
Adds any geopandas-supported vector dataset to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Either the absolute or relative path to the file or URL to be opened, or any object with a read() method (such as an open file or StringIO). |
required |
layer_name
|
str
|
The layer name to use. Defaults to "Untitled". |
'Untitled'
|
bbox
|
tuple | GeoDataFrame or GeoSeries | shapely Geometry
|
Filter features by given bounding box, GeoSeries, GeoDataFrame or a shapely geometry. CRS mis-matches are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with mask. Defaults to None. |
None
|
mask
|
dict | GeoDataFrame or GeoSeries | shapely Geometry
|
Filter for features that intersect with the given dict-like geojson geometry, GeoSeries, GeoDataFrame or shapely geometry. CRS mis-matches are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with bbox. Defaults to None. |
None
|
rows
|
int or slice
|
Load in specific rows by passing an integer (first n rows) or a slice() object.. Defaults to None. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer. Defaults to True. |
True
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
add_vector_tile(url, styles={}, layer_name='Vector Tile', **kwargs)
¶
Adds a VectorTileLayer to the map. It wraps the folium.plugins.VectorGridProtobuf class. See https://github.com/python-visualization/folium/blob/main/folium/plugins/vectorgrid_protobuf.py#L7
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the tile layer |
required |
styles
|
dict | str
|
Style dict, specific to the vector tile source. If styles is given as a string, it will be passed directly to folium.plugins.VectorGrid directly, ignoring additional kwargs. See the "conditional styling" example in https://github.com/iwpnd/folium-vectorgrid |
{}
|
layer_name
|
str
|
The layer name to use for the layer. Defaults to 'Vector Tile'. |
'Vector Tile'
|
kwargs
|
Additional keyword arguments to pass to the folium.plugins.VectorGridProtobuf class. |
{}
|
add_widget(content, position='bottomright', **kwargs)
¶
Add a widget (e.g., text, HTML, figure) to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The widget to add. |
required |
position
|
str
|
The position of the widget. Defaults to "bottomright". |
'bottomright'
|
add_wms_layer(url, layers, name=None, attribution='', overlay=True, control=True, shown=True, format='image/png', transparent=True, version='1.1.1', styles='', **kwargs)
¶
Add a WMS layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the WMS web service. |
required |
layers
|
str
|
Comma-separated list of WMS layers to show. |
required |
name
|
str
|
The layer name to use on the layer control. Defaults to None. |
None
|
attribution
|
str
|
The attribution of the data layer. Defaults to ''. |
''
|
overlay
|
bool
|
Allows overlay. Defaults to True. |
True
|
control
|
bool
|
Adds the layer to the layer control. Defaults to True. |
True
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
format
|
str
|
WMS image format (use ‘image/png’ for layers with transparency). Defaults to 'image/png'. |
'image/png'
|
transparent
|
bool
|
Whether the layer shall allow transparency. Defaults to True. |
True
|
version
|
str
|
Version of the WMS service to use. Defaults to "1.1.1". |
'1.1.1'
|
styles
|
str
|
Comma-separated list of WMS styles. Defaults to "". |
''
|
add_wms_legend(url)
¶
Add a WMS legend based on an image URL
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL of the WMS legend image. Should have this format if using wms legend: {geoserver}/wms?REQUEST=GetLegendGraphic&FORMAT=image/png&LAYER={layer} |
required |
add_xy_data(in_csv, x='longitude', y='latitude', label=None, layer_name='Marker cluster')
¶
Adds points from a CSV file containing lat/lon information and display data on the map.
add_xyz_service(provider, **kwargs)
¶
Add a XYZ tile layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
A tile layer name starts with xyz or qms. For example, xyz.OpenTopoMap, |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
The provider is not valid. It must start with xyz or qms. |
basemap_demo()
¶
A demo for using leafmap basemaps.
clear_controls()
¶
Clears all controls on the map.
edit_vector(data, **kwargs)
¶
Edit a vector layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict | str
|
The data to edit. It can be a GeoJSON dictionary or a file path. |
required |
find_layer(name)
¶
Finds layer by name.
find_layer_index(name)
¶
Finds layer index by name.
get_layer_names()
¶
Gets layer names as a list.
get_scale()
¶
Returns the approximate pixel scale of the current map view, in meters.
image_overlay(url, bounds, name)
¶
Overlays an image from the Internet or locally on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
http URL or local file path to the image. |
required |
bounds
|
tuple
|
bounding box of the image in the format of (lower_left(lat, lon), upper_right(lat, lon)), such as ((13, -130), (32, -100)). |
required |
name
|
str
|
name of the layer to show on the layer control. |
required |
layer_opacity(name, value=1.0)
¶
Changes layer opacity.
oam_search(bbox=None, start_date=None, end_date=None, limit=100, info_mode='on_click', layer_args={}, add_image=True, **kwargs)
¶
Search OpenAerialMap for images within a bounding box and time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
list | str
|
The bounding box [xmin, ymin, xmax, ymax] to search within. Defaults to None. |
None
|
start_date
|
str
|
The start date to search within, such as "2015-04-20T00:00:00.000Z". Defaults to None. |
None
|
end_date
|
str
|
The end date to search within, such as "2015-04-21T00:00:00.000Z". Defaults to None. |
None
|
limit
|
int
|
The maximum number of results to return. Defaults to 100. |
100
|
info_mode
|
str
|
The mode to use for the info popup. Can be 'on_hover' or 'on_click'. Defaults to 'on_click'. |
'on_click'
|
layer_args
|
dict
|
The layer arguments for add_gdf() function. Defaults to {}. |
{}
|
add_image
|
bool
|
Whether to add the first 10 images to the map. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments to pass to the API. See https://hotosm.github.io/oam-api/ |
{}
|
remove_labels(**kwargs)
¶
Removes a layer from the map.
save_draw_features(out_file, indent=4, **kwargs)
¶
Save the draw features to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_file
|
str
|
The output file path. |
required |
indent
|
int
|
The indentation level when saving data as a GeoJSON. Defaults to 4. |
4
|
set_center(lon, lat, zoom=10)
¶
Centers the map view at a given coordinates with the given zoom level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
float
|
The longitude of the center, in degrees. |
required |
lat
|
float
|
The latitude of the center, in degrees. |
required |
zoom
|
int
|
The zoom level, from 1 to 24. Defaults to 10. |
10
|
split_map(left_layer='TERRAIN', right_layer='OpenTopoMap', left_args={}, right_args={}, left_array_args={}, right_array_args={}, left_label=None, right_label=None, left_position='bottomleft', right_position='bottomright', **kwargs)
¶
Adds a split-panel map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left_layer
|
str
|
The left tile layer. Can be a local file path, HTTP URL, or a basemap name. Defaults to 'TERRAIN'. |
'TERRAIN'
|
right_layer
|
str
|
The right tile layer. Can be a local file path, HTTP URL, or a basemap name. Defaults to 'OpenTopoMap'. |
'OpenTopoMap'
|
left_args
|
dict
|
The arguments for the left tile layer. Defaults to {}. |
{}
|
right_args
|
dict
|
The arguments for the right tile layer. Defaults to {}. |
{}
|
left_array_args
|
dict
|
The arguments for array_to_image for the left layer. Defaults to {}. |
{}
|
right_array_args
|
dict
|
The arguments for array_to_image for the right layer. Defaults to {}. |
{}
|
st_draw_features(st_component)
¶
Get the draw features of the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
st_component
|
st_folium
|
The streamlit component. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
The draw features of the map. |
st_fit_bounds()
¶
Fit the map to the bounds of the map.
Returns:
| Type | Description |
|---|---|
|
folium.Map: The map. |
st_last_click(st_component)
¶
Get the last click feature of the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
st_component
|
st_folium
|
The streamlit component. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The last click of the map. |
st_last_draw(st_component)
¶
Get the last draw feature of the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
st_component
|
st_folium
|
The streamlit component. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The last draw of the map. |
st_map_bounds(st_component)
¶
Get the bounds of the map in the format of (miny, minx, maxy, maxx).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
st_component
|
st_folium
|
The streamlit component. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple
|
The bounds of the map. |
st_map_center(st_component)
¶
Get the center of the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
st_component
|
st_folium
|
The streamlit component. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple
|
The center of the map. |
static_map(width=950, height=600, read_only=False, out_file=None, **kwargs)
¶
Display a folium static map in a Jupyter Notebook.
Args m (folium.Map): A folium map. width (int, optional): Width of the map. Defaults to 950. height (int, optional): Height of the map. Defaults to 600. read_only (bool, optional): Whether to hide the side panel to disable map customization. Defaults to False. out_file (str, optional): Output html file path. Defaults to None.
to_gradio(width='100%', height='500px', **kwargs)
¶
Converts the map to an HTML string that can be used in Gradio. Removes unsupported elements, such as attribution and any code blocks containing functions. See https://github.com/gradio-app/gradio/issues/3190
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
str
|
The width of the map. Defaults to '100%'. |
'100%'
|
height
|
str
|
The height of the map. Defaults to '500px'. |
'500px'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The HTML string to use in Gradio. |
to_html(outfile=None, **kwargs)
¶
Exports a map as an HTML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outfile
|
str
|
File path to the output HTML. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If it is an invalid HTML file. |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string containing the HTML code. |
to_image(outfile=None, monitor=1)
¶
Saves the map as a PNG or JPG image.
to_streamlit(width=None, height=600, scrolling=False, add_layer_control=True, bidirectional=False, **kwargs)
¶
Renders folium.Figure or folium.Map in a Streamlit app. This method is a static Streamlit Component, meaning, no information is passed back from Leaflet on browser interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the map. Defaults to None. |
None
|
height
|
int
|
Height of the map. Defaults to 600. |
600
|
scrolling
|
bool
|
Whether to allow the map to scroll. Defaults to False. |
False
|
add_layer_control
|
bool
|
Whether to add the layer control. Defaults to True. |
True
|
bidirectional
|
bool
|
Whether to add bidirectional functionality to the map. The streamlit-folium package is required to use the bidirectional functionality. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If streamlit is not installed. |
Returns:
| Type | Description |
|---|---|
|
streamlit.components: components.html object. |
toolbar_reset()
¶
Reset the toolbar so that no tool is selected.
user_roi_bounds(decimals=4)
¶
Get 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:
| Name | Type | Description |
|---|---|---|
list |
List
|
The bounds of the user drawn ROI as a tuple of (minx, miny, maxx, maxy). |
video_overlay(url, bounds, name)
¶
Overlays a video from the Internet on the map.
zoom_to_bounds(bounds)
¶
Zooms to a bounding box in the form of [minx, miny, maxx, maxy].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
list | tuple
|
A list/tuple containing minx, miny, maxx, maxy values for the bounds. |
required |
zoom_to_gdf(gdf)
¶
Zooms to the bounding box of a GeoPandas GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoPandas GeoDataFrame. |
required |
PMTilesLayer
¶
Bases: JSCSSMixin, Layer
Creates a PMTilesLayer object for displaying PMTiles. Adapted from https://github.com/jtmiclat/folium-pmtiles. Credits to @jtmiclat.
__init__(url, style=None, name=None, tooltip=True, overlay=True, show=True, control=True, **kwargs)
¶
Initializes a PMTilesLayer object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the PMTiles file. |
required |
style
|
dict
|
The style to apply to the layer. Defaults to None. |
None
|
name
|
str
|
The name of the layer. Defaults to None. |
None
|
tooltip
|
bool
|
Whether to show a tooltip. Defaults to True. |
True
|
overlay
|
bool
|
Whether the layer should be added as an overlay. Defaults to True. |
True
|
show
|
bool
|
Whether the layer should be shown initially. Defaults to True. |
True
|
control
|
bool
|
Whether to include the layer in the layer control. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments to pass to the Layer constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
PMTilesMapLibreTooltip
¶
Bases: JSCSSMixin, MacroElement
Creates a PMTilesMapLibreTooltip object for displaying tooltips. Adapted from https://github.com/jtmiclat/folium-pmtiles. Credits to @jtmiclat.
SideBySideLayers
¶
Bases: JSCSSMixin, Layer
Creates a SideBySideLayers that takes two Layers and adds a sliding control with the leaflet-side-by-side plugin. Uses the Leaflet leaflet-side-by-side plugin https://github.com/digidem/leaflet-side-by-side. Adopted from https://github.com/python-visualization/folium/pull/1292/files. Parameters
layer_left: Layer. The left Layer within the side by side control. Must be created and added to the map before being passed to this class. layer_right: Layer. The right Layer within the side by side control. Must be created and added to the map before being passed to this class. Examples
sidebyside = SideBySideLayers(layer_left, layer_right) sidebyside.add_to(m)
SplitControl
¶
Bases: Layer
Creates a SplitControl that takes two Layers and adds a sliding control with the leaflet-side-by-side plugin. Uses the Leaflet leaflet-side-by-side plugin https://github.com/digidem/leaflet-side-by-side Parameters. The source code is adapted from https://github.com/python-visualization/folium/pull/1292
layer_left: Layer. The left Layer within the side by side control. Must be created and added to the map before being passed to this class. layer_right: Layer. The left Layer within the side by side control. Must be created and added to the map before being passed to this class. name : string, default None The name of the Layer, as it will appear in LayerControls. overlay : bool, default True Adds the layer as an optional overlay (True) or the base layer (False). control : bool, default True Whether the Layer will be included in LayerControls. show: bool, default True Whether the layer will be shown on opening (only for overlays). Examples
sidebyside = SideBySideLayers(layer_left, layer_right) sidebyside.add_to(m)
geojson_layer(in_geojson, layer_name='Untitled', encoding='utf-8', info_mode='on_hover', **kwargs)
¶
Adds a GeoJSON file to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str
|
The input file path to the GeoJSON. |
required |
layer_name
|
str
|
The layer name to be used. Defaults to "Untitled". |
'Untitled'
|
encoding
|
str
|
The encoding of the GeoJSON file. Defaults to "utf-8". |
'utf-8'
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The provided GeoJSON file could not be found. |
linked_maps(rows=2, cols=2, height='400px', layers=[], labels=[], label_position='topright', **kwargs)
¶
Create linked maps of XYZ tile layers.
split_map(left_layer='ROADMAP', right_layer='HYBRID', left_label=None, right_label=None, label_position='bottom', **kwargs)
¶
Creates a split-panel map.
st_map_center(lat, lon)
¶
Returns the map center coordinates for a given latitude and longitude. If the system variable 'map_center' exists, it is used. Otherwise, the default is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude. |
required |
lon
|
float
|
Longitude. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If streamlit is not installed. |
Returns:
| Name | Type | Description |
|---|---|---|
list |
The map center coordinates. |
st_save_bounds(st_component)
¶
Saves the map bounds to the session state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map
|
Map
|
The map to save the bounds from. |
required |