Skip to content

Basemaps

image image image

Customize basemaps

Uncomment the following line to install leafmap if needed.

1
# %pip install "leafmap[maplibre]"
1
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 set it as an environment variable in your notebook or script as follows:

1
2
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"

By default, if the style parameter is not provided, the default dark-matter style from CartoDB will be used. Other styles can be found here, including positron, voyager, dark-matter-nolabels, positron-nolabels, and voyager-nolabels.

1
2
m = leafmap.Map(style="dark-matter")
m

If you have a MapTiler API key, you can use any basemap available in the MapTiler Basemap style gallery by specifying the style parameter. For example, style='satellite' will use the satellite basemap from MapTiler.

1
2
m = leafmap.Map(center=[-100, 40], zoom=3, style="streets")
m

You can also use any raster basemaps from xyzservices. For example, style='OpenTopoMap' will use the OpenTopoMap basemap.

1
2
3
m = leafmap.Map(center=[-100, 40], zoom=3)
m.add_basemap("OpenTopoMap")
m

If you don't know the name of the basemap, you can use the add_basemap() function to get a list of basemaps and select the one you like.

1
m.add_basemap()