3D Terrain
This source code of this example is adapted from the MapLibre GL JS example - 3D Terrain.
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!
style = {
"version": 8,
"sources": {
"osm": {
"type": "raster",
"tiles": ["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"],
"tileSize": 256,
"attribution": "© OpenStreetMap Contributors",
"maxzoom": 19,
},
"terrainSource": {
"type": "raster-dem",
"url": "https://demotiles.maplibre.org/terrain-tiles/tiles.json",
"tileSize": 256,
},
"hillshadeSource": {
"type": "raster-dem",
"url": "https://demotiles.maplibre.org/terrain-tiles/tiles.json",
"tileSize": 256,
},
},
"layers": [
{"id": "osm", "type": "raster", "source": "osm"},
{
"id": "hills",
"type": "hillshade",
"source": "hillshadeSource",
"layout": {"visibility": "visible"},
"paint": {"hillshade-shadow-color": "#473B24"},
},
],
"terrain": {"source": "terrainSource", "exaggeration": 1},
}
style = {
"version": 8,
"sources": {
"osm": {
"type": "raster",
"tiles": ["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"],
"tileSize": 256,
"attribution": "© OpenStreetMap Contributors",
"maxzoom": 19,
},
"terrainSource": {
"type": "raster-dem",
"url": "https://demotiles.maplibre.org/terrain-tiles/tiles.json",
"tileSize": 256,
},
"hillshadeSource": {
"type": "raster-dem",
"url": "https://demotiles.maplibre.org/terrain-tiles/tiles.json",
"tileSize": 256,
},
},
"layers": [
{"id": "osm", "type": "raster", "source": "osm"},
{
"id": "hills",
"type": "hillshade",
"source": "hillshadeSource",
"layout": {"visibility": "visible"},
"paint": {"hillshade-shadow-color": "#473B24"},
},
],
"terrain": {"source": "terrainSource", "exaggeration": 1},
}
In [5]:
Copied!
m = leafmap.Map(center=[11.39085, 47.27574], zoom=12, pitch=52, style=style)
m.add_layer_control(bg_layers=True)
m
m = leafmap.Map(center=[11.39085, 47.27574], zoom=12, pitch=52, style=style)
m.add_layer_control(bg_layers=True)
m
In [6]:
Copied!
m = leafmap.Map(
center=[-122.19861, 46.21168], zoom=13, pitch=60, bearing=150, style="3d-terrain"
)
m.add_layer_control(bg_layers=True)
m
m = leafmap.Map(
center=[-122.19861, 46.21168], zoom=13, pitch=60, bearing=150, style="3d-terrain"
)
m.add_layer_control(bg_layers=True)
m
An API key is required to use the 3D terrain feature.