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.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import leafmap.maplibregl as leafmap
import ipywidgets as widgets
import leafmap.maplibregl as leafmap
import ipywidgets as widgets
In [3]:
Copied!
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
In [4]:
Copied!
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
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
Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style.
In [5]:
Copied!
dropdown
dropdown