Fill pattern

Add a pattern to a polygon
This source code of this example is adapted from the MapLibre GL JS example - Add a pattern to a polygon.
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
17
18
19
20
21
22
23 | m = leafmap.Map(zoom=1, style="streets")
source = {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-30, -25], [-30, 35], [30, 35], [30, -25], [-30, -25]]],
},
},
}
m.add_source("source", source)
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Cat_silhouette.svg/64px-Cat_silhouette.svg.png"
m.add_image("pattern", url)
layer = {
"id": "pattern-layer",
"type": "fill",
"source": "source",
"paint": {"fill-pattern": "pattern"},
}
m.add_layer(layer)
m
|
