Learn how to change language labels on a basemap.
The ArcGIS Basemap Styles servicelanguage parameter, which allows you to localize place labels into more than 30 different languages.
In this tutorial, set the basemap style preferences to change between different place label languages using the MapLibre ArcGIS plugin.
Prerequisites
You need an ArcGIS Location Platform or ArcGIS Online account.
Steps
Get the starter app
Select a type of authentication and follow the steps to create a new app.
Choose API key authentication if you:
- Want the easiest way to get started.
- Want to build public applications
A public application is an application that allows anonymous access without requiring users to sign in with an ArcGIS account. It supports API key or app authentication. that access ArcGIS Location ServicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. and secure itemsAn item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. . - Have an ArcGIS Location Platform or ArcGIS Online account.
Choose user authentication if you:
- Want to build private applications.
- Require application users to sign in with their own ArcGIS account
An ArcGIS account is an identity with a user type and set of privileges that can access specific ArcGIS products, tools, APIs, services, and resources. The main account types that can be used for development are an ArcGIS Location Platform account, ArcGIS Online account, and ArcGIS Enterprise account. ArcGIS Location Platform and ArcGIS Online accounts are also associated with a subscription. and access resources their behalf. - Have an ArcGIS Online account.
To learn more about both types of authentication, go to Authentication.
Set up authentication
Set developer credentials
Use the API key or OAuth developer credentials
Add a language selector
Add a menu that allows users to change display language of your map. To accomplish this, use a standard html <select element.
-
Create a
<divtag to contain the> <selectdropdown menu, which you will populate in a later step.> Use dark colors for code blocks </style> <!-- Load MapLibre GL JS from CDN --> <script src="https://unpkg.com/maplibre-gl@5.23.0/dist/maplibre-gl.js"></script> <link href="https://unpkg.com/maplibre-gl@5.23.0/dist/maplibre-gl.css" rel="stylesheet"> <!-- Load MapLibre ArcGIS from CDN --> <script src="https://unpkg.com/@esri/maplibre-arcgis@1.1.0/dist/umd/maplibre-arcgis.min.js"></script> </head> <body> <div id="map"></div> <div id="languages-wrapper"> <select id="languages"></select> </div> -
In the
<styleelement, add CSS styling to the> languages-wrapperandlanguages.Use dark colors for code blocks <style> html, body, #map { padding: 0; margin: 0; height: 100%; width: 100%; font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #323232; } #languages-wrapper { position: absolute; top: 20px; right: 20px; background: rgba(255, 255, 255, 0); } #languages { font-size: 16px; padding: 4px 8px; } </style> <!-- Load MapLibre GL JS from CDN --> <script src="https://unpkg.com/maplibre-gl@5.23.0/dist/maplibre-gl.js"></script> <link href="https://unpkg.com/maplibre-gl@5.23.0/dist/maplibre-gl.css" rel="stylesheet"> <!-- Load MapLibre ArcGIS from CDN --> <script src="https://unpkg.com/@esri/maplibre-arcgis@1.1.0/dist/umd/maplibre-arcgis.min.js"></script>
Set the basemap
Using the MapLibre ArcGIS plugin, reference the Basemap Styles service
-
Define a function to update the
stylelanguage to the selected language.Use dark colors for code blocks const setLanguage = (selection) => { // Instantiate the given basemap layer. basemapStyle.updateStyle({ preferences: { language: selection } }); }; -
Select the DOM element used for the language selector.
Use dark colors for code blocks const languageSelectElement = document.querySelector("#languages"); -
Use the MapLibre ArcGIS plugin to make a request to the Basemap Styles service. This dynamically fetches the available languages and populates the
selectelement.Use dark colors for code blocks const languageSelectElement = document.querySelector("#languages"); maplibreArcGIS.BasemapStyle.getSelf().then((response) => { response.languages.forEach((language) => { const option = document.createElement("option"); option.value = language.code; option.textContent = language.name; languageSelectElement.appendChild(option); }); }); -
Call
setto initialize the language labels to the first language in theLanguage selectelement.Use dark colors for code blocks maplibreArcGIS.BasemapStyle.getSelf().then((response) => { response.languages.forEach((language) => { const option = document.createElement("option"); option.value = language.code; option.textContent = language.name; languageSelectElement.appendChild(option); }); setLanguage(response.languages[0].code); });
Add an event listener
Use an event listener to register a basemap change in the <select element and to update the map.
-
Add an event listener to update the map when a new language is selected.
Use dark colors for code blocks const languageSelectElement = document.querySelector("#languages"); maplibreArcGIS.BasemapStyle.getSelf().then((response) => { response.languages.forEach((language) => { const option = document.createElement("option"); option.value = language.code; option.textContent = language.name; languageSelectElement.appendChild(option); }); setLanguage(response.languages[0].code); }); languageSelectElement.addEventListener("change", (e) => { setLanguage(e.target.value); });
Add RTL language support
MapLibre GL JS does not automatically display right-to-left languages such as Arabic and Hebrew correctly. Use the Mapbox GL RTL Text plugin to configure settings for RTL languages.
-
Call the
maplibregl.setwith the URL of the Mapbox GL RTL Text plugin to configure support for RTL languages.RTL Text Plugin Use dark colors for code blocks languageSelectElement.addEventListener("change", (e) => { setLanguage(e.target.value); }); maplibregl.setRTLTextPlugin("https://unpkg.com/@mapbox/mapbox-gl-rtl-text@0.2.3/mapbox-gl-rtl-text.js");
Run the app
Run the app.
You should be able to use the<select > element to switch between language labels on your basemap.
What's next?
Learn how to use additional location services in these tutorials:



