Vector tile

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.
| # %pip install "leafmap[maplibre]"
|
| 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 uncomment the following code block and replace YOUR_API_KEY with your actual API key. Then, run the code block code to set the API key as an environment variable.
| # import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
|
| MAPTILER_KEY = leafmap.get_api_key("MAPTILER_KEY")
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | 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
|
