Add a vector tile source
This source code of this example is adapted from the MapLibre GL JS example - Add a vector tile source.
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!
MAPTILER_KEY = leafmap.get_api_key("MAPTILER_KEY")
MAPTILER_KEY = leafmap.get_api_key("MAPTILER_KEY")
In [5]:
Copied!
m = leafmap.Map(center=[-122.447303, 37.753574], zoom=13, style="streets")
source = {
"type": "vector",
"url": f"https://api.maptiler.com/tiles/contours/tiles.json?key={MAPTILER_KEY}",
}
layer = {
"id": "terrain-data",
"type": "line",
"source": "contours",
"source-layer": "contour",
"layout": {"line-join": "round", "line-cap": "round"},
"paint": {"line-color": "#ff69b4", "line-width": 1},
}
m.add_source("contours", source)
m.add_layer(layer)
m
m = leafmap.Map(center=[-122.447303, 37.753574], zoom=13, style="streets")
source = {
"type": "vector",
"url": f"https://api.maptiler.com/tiles/contours/tiles.json?key={MAPTILER_KEY}",
}
layer = {
"id": "terrain-data",
"type": "line",
"source": "contours",
"source-layer": "contour",
"layout": {"line-join": "round", "line-cap": "round"},
"paint": {"line-color": "#ff69b4", "line-width": 1},
}
m.add_source("contours", source)
m.add_layer(layer)
m
Failed to retrieve the MapTiler style. Defaulting to 'dark-matter' style.