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.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import leafmap.maplibregl as leafmap
import leafmap.maplibregl as leafmap
In [3]:
Copied!
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
In [4]:
Copied!
dem = "https://github.com/opengeos/datasets/releases/download/raster/srtm90.tif"
dem = "https://github.com/opengeos/datasets/releases/download/raster/srtm90.tif"
In [5]:
Copied!
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
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
Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style.
In [6]:
Copied!
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
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
Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style.
In [7]:
Copied!
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
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
Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style.