Change the basemap language

Learn how to localize basemap place labels using the basemap styles service.

The basemap styles service provides a number of basemap layer styles such as topography, streets, and imagery that you can use in maps. Each style accepts a language parameter, which allows you to localize place labels. There are currently over 30 different languages available.

In this tutorial, you will create a Calcite combobox to switch between different languages to update the Basemap style and app language.

Prerequisites

Steps

Create a new pen

  1. To get started, either complete the Display a map tutorial or .

Get an access token

You need an access token with the correct privileges to access the location services used in this tutorial.

  1. Go to the Create an API key tutorial and create an API key with the following privilege(s):
    • Privileges
      • Location services > Basemaps
  2. In CodePen, set esriConfig.apiKey to your access token.
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
      var esriConfig = {
        apiKey: "YOUR_ACCESS_TOKEN"
      };
    

To learn about other ways to get an access token, go to Types of authentication.

Update the map

  1. Update the center and zoom attributes to focus the display on Europe.
    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
        <arcgis-map basemap="arcgis/topographic" center="13, 46" zoom="4">
    
            <arcgis-zoom position="top-left"></arcgis-zoom>
    
        </arcgis-map>
    
    Expand

Add modules

The request module can be used to request data from a remote server or file. We'll use this module to fetch the available languages from the basemap style API endpoint.

  1. In a new <script> at the bottom of the <body>, use a require statement to add the request module.
    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
        <script>
            require([
                "esri/request",
            ], (esriRequest) => {
    
            });
        </script>
    
    Expand

Set the current language

Set the current language of the basemap and the lang attribute on the body to Spanish (es). Setting the lang of the application will update the components to use the given language and formatting. For instance, when the locale is set to Spanish, the zoom component tooltip will say Acercar instead of Zoom in.

  1. Set the app's locale to Spanish (es) by setting the lang attribute on the document body.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    
    <body lang="es">
    
        <arcgis-map basemap="arcgis/topographic" center="13, 46" zoom="4">
    
            <arcgis-zoom position="top-left"></arcgis-zoom>
    
        </arcgis-map>
    
    </body>
    
    Expand
  2. Set the basemap from a style to the arcgis/outdoor basemap style with the language property set to "es". This will display the basemap's place labels in Spanish.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
        <script>
            require([
                "esri/request",
            ], (esriRequest) => {
    
                const map = document.querySelector("arcgis-map");
                map.basemap = {
                    style: {
                        id: "arcgis/outdoor",
                        language: "es" // Spanish language basemap
                    }
                };
    
            });
        </script>
    
    Expand

Create a language dropdown

Get the list of languages available from the basemap styles service and add them to a calcite-combobox component to allow users to select the language of their basemap.

  1. Add an arcgis-placement component to the map to place the content in the top-right of the map component.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
        <arcgis-map basemap="arcgis/topographic" center="13, 46" zoom="4">
    
            <arcgis-zoom position="top-left"></arcgis-zoom>
    
            <arcgis-placement position="top-right">
    
            </arcgis-placement>
    
        </arcgis-map>
    
    Expand
  2. Inside the arcgis-placement component, create a div called basemapLanguage with a calcite-combobox component. Set selection-mode to single, so only one language can be selected at a time. Add the clear-disabled attribute so that a language is always selected.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
        <arcgis-map basemap="arcgis/topographic" center="13, 46" zoom="4">
    
            <arcgis-zoom position="top-left"></arcgis-zoom>
    
            <arcgis-placement position="top-right">
    
                <div id="basemapLanguage">
                    <calcite-label>Basemap language</calcite-label>
                    <calcite-combobox id="languageCombobox" selection-mode="single"
                        clear-disabled></calcite-combobox>
                </div>
    
            </arcgis-placement>
    
        </arcgis-map>
    
    Expand
  3. Within the <style> tags, apply some CSS properties to the basemapLanguage div.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
            #basemapLanguage {
                width: 200px;
                padding: 10px;
                background-color: white;
            }
    
    Expand
  4. Fetch the list of languages available from the /self endpoint for the basemap styles service using the esriRequest method. Specify json as the response type. This will return a json response with a languages property.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
                // update combobox values with languages from rest endpoint
                const basemapStylesEndpoint = "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self";
                esriRequest(basemapStylesEndpoint, {
                    responseType: "json"
                }).then((response) => {
    
                });
    
    Expand
  5. From the response data, use the JavaScript forEach method to iterate through each of the languages and add it as a calcite-combobox-item. Set the value to the language code, and the label to the language name. If the language code matches the language of the current basemap, set the item as selected.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
                // update combobox values with languages from rest endpoint
                const basemapStylesEndpoint = "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self";
                esriRequest(basemapStylesEndpoint, {
                    responseType: "json"
                }).then((response) => {
    
                    const json = response.data;
                    // add each language as a combobox item
                    json.languages.forEach((language, index) => {
                        const comboboxItem = document.createElement("calcite-combobox-item");
                        comboboxItem.value = language.code;
                        comboboxItem.textLabel = language.name;
                        // if the current basemap language is the same as the combobox item, select it
                        comboboxItem.selected = map.basemap.style.language === language.code;
                        languageCombobox.appendChild(comboboxItem);
                    });
    
                });
    
    Expand

Create a basemap language function

Create a function that accepts a language code and updates the basemap style formatted with that language.

  1. Define a new function updateBasemapLanguage that accepts a language code.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
                const updateLanguage = (languageCode) => {
    
                };
    
    
    Expand
  2. Use the languageCode variable to update the application's language and the language of the basemap style.

    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
                const updateLanguage = (languageCode) => {
    
                    // update language in html body
                    document.body.setAttribute('lang', languageCode);
                    // update the basemap language
                    map.basemap = {
                        style: {
                            id: "arcgis/outdoor",
                            language: languageCode
                        }
                    }
    
                };
    
    
    Expand

Update the language on user input

Use the calciteComboboxChange event to recognize when the user has selected a new language.

  1. Add an event listener to watch for changes on the combobox. When the combobox value has changed, call the updateBasemapLanguage function to update the basemap language and app locale.
    Expand
    Use dark colors for code blocks
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
                const updateLanguage = (languageCode) => {
    
                    // update language in html body
                    document.body.setAttribute('lang', languageCode);
                    // update the basemap language
                    map.basemap = {
                        style: {
                            id: "arcgis/outdoor",
                            language: languageCode
                        }
                    }
    
                };
    
                const languageCombobox = document.getElementById("languageCombobox");
                // when the combobox value changes, update the language
                languageCombobox.addEventListener("calciteComboboxChange", () => {
                    updateLanguage(languageCombobox.value);
                });
    
    Expand

Run the App

In CodePen, run your code to display the map.

You should be able to use the calcite combobox to update the basemap language and app language.

What's Next?

Learn how to use additional API features and ArcGIS services in these tutorials:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.