Add colorbar

Add a colorbar to the map
This source code of this example is adapted from the MapLibre GL JS example - maplibre_xxx.
Uncomment the following line to install leafmap if needed.
| # %pip install "leafmap[maplibre]"
|
| import leafmap.maplibregl as leafmap
|
To run this notebook, you will need an API key from MapTiler. Once you have the API key, you can uncomment the following code block and replace YOUR_API_KEY with your actual API key. Then, run the code block code to set the API key as an environment variable.
| # import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
|
| dem = "https://github.com/opengeos/datasets/releases/download/raster/srtm90.tif"
|
| m = leafmap.Map(style="streets")
m.add_cog_layer(
dem, name="DEM", colormap_name="terrain", rescale="0, 4000", fit_bounds=True
)
m.add_colorbar(
cmap="terrain", vmin=0, vmax=4000, label="Elevation (m)", position="bottom-right"
)
m
|

1
2
3
4
5
6
7
8
9
10
11
12
13 | m = leafmap.Map(style="streets")
m.add_cog_layer(
dem, name="DEM", colormap_name="terrain", rescale="0, 4000", fit_bounds=True
)
m.add_colorbar(
cmap="terrain",
vmin=0,
vmax=4000,
label="Elevation (m)",
position="bottom-right",
transparent=True,
)
m
|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | m = leafmap.Map(style="streets")
m.add_cog_layer(
dem, name="DEM", colormap_name="terrain", rescale="0, 4000", fit_bounds=True
)
m.add_colorbar(
cmap="terrain",
vmin=0,
vmax=4000,
label="Elevation (m)",
position="bottom-right",
width=0.2,
height=3,
orientation="vertical",
)
m
|
