Add image

Add an icon to the map
This source code of this example is adapted from the MapLibre GL JS example - Add an icon to the map.
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
24
25
26
27
28
29 | m = leafmap.Map(center=[0.349419, -1.80921], zoom=3, style="streets")
image = "https://upload.wikimedia.org/wikipedia/commons/7/7c/201408_cat.png"
source = {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{"type": "Feature", "geometry": {"type": "Point", "coordinates": [0, 0]}}
],
},
}
layer = {
"id": "points",
"type": "symbol",
"source": "point",
"layout": {
"icon-image": "cat",
"icon-size": 0.25,
"text-field": "I love kitty!",
"text-font": ["Open Sans Regular"],
"text-offset": [0, 3],
"text-anchor": "top",
},
}
m.add_image("cat", image)
m.add_source("point", source)
m.add_layer(layer)
m
|
