Language switch

Change a map's language
This source code of this example is adapted from the MapLibre GL JS example - Change a map's language.
Uncomment the following line to install leafmap if needed.
| # %pip install "leafmap[maplibre]"
|
| import leafmap.maplibregl as leafmap
import ipywidgets as widgets
|
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(center=[16.05, 48], zoom=3, style="basic")
languages = {
"English": "en",
"French": "fr",
"German": "de",
"Italian": "it",
"Spanish": "es",
"Russian": "ru",
"Chinese": "zh",
"Japanese": "ja",
"Korean": "ko",
}
dropdown = widgets.Dropdown(options=languages, description="Language:")
def change_language(change):
m.set_layout_property(
"label_country", "text-field", ["get", f"name:{dropdown.value}"]
)
dropdown.observe(change_language, names="value")
m
|
