Geojson layer in stack

Add a new layer below labels
This source code of this example is adapted from the MapLibre GL JS example - Add a new layer below labels.
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"
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | m = leafmap.Map(center=[-88.137343, 35.137451], zoom=4, style="streets")
source = {
"type": "geojson",
"data": "https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_urban_areas.geojson",
}
m.add_source("urban-areas", source)
first_symbol_layer = m.find_first_symbol_layer()
layer = {
"id": "urban-areas-fill",
"type": "fill",
"source": "urban-areas",
"layout": {},
"paint": {"fill-color": "#f08", "fill-opacity": 0.4},
}
m.add_layer(layer, before_id=first_symbol_layer["id"])
m
|
