Learn how to localize place labels in the basemap.
The ArcGIS Basemap Styles servicelanguage parameter, which allows you to localize place labels. There are currently over 30 different languages available.
In this tutorial, you use Esri Leaflet Vector to create a language selector and switch between different languages.
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
Create a basemap language function
Create a function that accepts a language code and returns a basemap style formatted with that language.
-
Define a new
getfunction that accepts a language code and returns aLanguage Vector.Basemap Layer Use dark colors for code blocks function getLanguage(languageCode) { return L.esri.Vector.vectorBasemapLayer(basemapStyle, ); } -
In the basemap layer properties, set the
languageoption to yourlanguage. SetCode versionto access the styles service, and pass your access token.:2 Use dark colors for code blocks function getLanguage(languageCode) { return L.esri.Vector.vectorBasemapLayer(basemapStyle, { language: languageCode, token: accessToken } ); }
Add a language selector
Add a menu that allows users to change the display language of your map.
-
Use
L.esri.getto make a request to the Basemap Styles service. This dynamically fetches the available basemap languages. For each enumerated language, call thegetfunction to populate theLanguage languageslist.Use dark colors for code blocks function getLanguage(languageCode) { return L.esri.Vector.vectorBasemapLayer(basemapStyle, { language: languageCode, token: accessToken } ); } L.esri.get( "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self", { token: accessToken }, (error, response) => { if (error) { console.error("Error fetching languages:", error); return; } const languages = {}; let firstLanguage; response.languages.forEach((language, index) => { const layer = getLanguage(language.code); languages[language.name] = layer; if (index === 0) { firstLanguage = layer; firstLanguage.addTo(map); } }); -
Create a Leaflet
Controland add it to your map. Pass thelanguagesobject to display all of the supported languages.Use dark colors for code blocks L.esri.get( "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self", { token: accessToken }, (error, response) => { if (error) { console.error("Error fetching languages:", error); return; } const languages = {}; let firstLanguage; response.languages.forEach((language, index) => { const layer = getLanguage(language.code); languages[language.name] = layer; if (index === 0) { firstLanguage = layer; firstLanguage.addTo(map); } }); L.control.layers(languages, null, { collapsed: false }).addTo(map);
Add RTL language support
Esri Leaflet Vector 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 L.Esri.Vector.setRTLTextPlugin with the URL of the Mapbox GL RTL Text plugin to configure support for RTL languages.
Use dark colors for code blocks L.control.layers(languages, null, { collapsed: false }).addTo(map); } ); L.esri.Vector.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 Leaflet control to switch between basemap languages.What's next?
Learn how to use additional location services in these tutorials:



