Tiles#

Built-in tilesets#

[1]:
import folium


lon, lat = -38.625, -12.875

zoom_start = 8
[2]:
folium.Map(location=[lat, lon], tiles="OpenStreetMap", zoom_start=zoom_start)
[2]:
Make this Notebook Trusted to load map: File -> Trust Notebook
[3]:
folium.Map(location=[lat, lon], tiles="Cartodb Positron", zoom_start=zoom_start)
[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
[4]:
folium.Map(location=[lat, lon], tiles="Cartodb dark_matter", zoom_start=zoom_start)
[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Custom tiles#

You can also provide a url template to load tiles from, for example if you use a paid API. You also have to provide an attribution in that case. For information how that url template should look like see the Leaflet documentation: https://leafletjs.com/reference.html#tilelayer.

Below is an example, note the literal {z}, {x} and {y} in the url template.

[5]:
attr = (
    '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> '
    'contributors, &copy; <a href="https://cartodb.com/attributions">CartoDB</a>'
)
tiles = "https://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png"

folium.Map(location=[lat, lon], tiles=tiles, attr=attr, zoom_start=zoom_start)
[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Other tilesets#

For a list of many more tile providers go to https://leaflet-extras.github.io/leaflet-providers/preview/.

You can also use the xyzservices package: geopandas/xyzservices.