Tutorial: Change the static basemap tiles style

Learn how to change the basemap style in a map using the static basemap tiles service (beta).

The static basemap tiles service (beta) provides access to raster basemap tiles for the world. The service supports a number of ArcGIS styles such as navigation, streets, outdoor, and light-gray. The tiles are returned as PNG files.

In this tutorial, you use the L.esri.Static.staticBasemapTileLayer class to change the static basemap tiles style.

Prerequisites

This tutorial requires an ArcGIS Location Platform account.

Steps

Create a new pen

  1. To get started, you can complete the Display a map tutorial or use the .

Get an access token

You need an access token with the correct privileges to access the resources 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. Copy the API key access token to your clipboard when prompted.

  3. In CodePen, update the accessToken variable to use your access token.

    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
          const map = L.map("map", {
            minZoom: 2
          })
    
          map.setView([34.02, -118.805], 13);
    
          const accessToken = "YOUR_ACCESS_TOKEN";
    
          const basemapEnum = "arcgis/streets";
    
          L.esri.Vector.vectorBasemapLayer(basemapEnum, {
            token: accessToken
          }).addTo(map);
    
  4. Run the code to ensure the basemap is displayed in the map.

To learn about the other types of authentication available, go to Types of authentication.

Update script references

The map will use static basemap tiles as its basemap layer. Therefore, you remove references to the esri-leaflet-vector plugin and the vector basemap layer. Then, you reference the staticBasemapTileLayer plugin.

  1. Remove the script references to esri-leaflet-vector plugin.

    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
      <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
        <title>Esri Leaflet Tutorials: Display a map</title>
    
        <!-- Load Leaflet from CDN -->
        <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" crossorigin="" />
        <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" crossorigin=""></script>
    
        <!-- Load Esri Leaflet from CDN -->
        <script src="https://unpkg.com/esri-leaflet@3.0.10/dist/esri-leaflet.js"></script>
    
        <script src="https://unpkg.com/esri-leaflet-vector@4.2.5/dist/esri-leaflet-vector.js"></script>
    
  2. Remove the basemapEnum and vectorBasemapLayer references.

    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
          const map = L.map("map", {
            minZoom: 2
          })
    
          map.setView([34.02, -118.805], 13);
    
          const accessToken = "YOUR_ACCESS_TOKEN";
    
          const basemapEnum = "arcgis/streets";
    
          L.esri.Vector.vectorBasemapLayer(basemapEnum, {
            token: accessToken
          }).addTo(map);
    
  3. Add <script> tag to reference the staticBasemapTileLayer plugin.

    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
      <!-- Load Esri Leaflet from CDN -->
      <script src="https://unpkg.com/esri-leaflet@3.0.10/dist/esri-leaflet.js"></script>
    
      <script src="https://unpkg.com/esri-leaflet-static-basemap-tile@1.0.0-beta.1/dist/esri-leaflet-static-basemap-tile.js"></script>
    
    Expand

Update the map's viewpoint

  1. Change the map's center to [37.1174, -91.2996] and zoom level to 5. This will focus the map on the United States of America.

    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
      <script>
        const accessToken = "YOUR_ACCESS_TOKEN";
    
        const map = L.map("map", {
          minZoom: 2
        })
    
        map.setView([37.1174, -91.2996], 5);
    
      </script>
    
    Expand

Add the basemap styles

You will get all the available basemap styles from the static basemap tiles service and create a menu that allows users to change the basemap style of your map.

  1. Use the getSelf method from L.esri.Static.Util to make a request to the static basemap tiles service that returns all available basemap styles and their metadata.

    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
      <script>
        const accessToken = "YOUR_ACCESS_TOKEN";
    
        const map = L.map("map", {
          minZoom: 2
        })
    
        map.setView([37.1174, -91.2996], 5);
    
        L.esri.Static.Util.getSelf(accessToken).then((data) => {
    
        })
    
      </script>
    
    Expand
  2. Create a basemapLayers object to store all the returned basemap styles.

    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
        L.esri.Static.Util.getSelf(accessToken).then((data) => {
    
          const basemapLayers = {};
    
        })
    
    Expand
  3. Iterate through each basemap style and create an L.esri.Static.staticBasemapTileLayer from the style. Store it inside the basemapLayers object.

    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
        L.esri.Static.Util.getSelf(accessToken).then((data) => {
    
          const basemapLayers = {};
    
          data.styles.forEach(style => {
            basemapLayers[style.name] = L.esri.Static.staticBasemapTileLayer('beta' + style.path, {
              token: accessToken
            })
          })
    
        })
    
    Expand
  4. Create a Layers control that references basemapLayers and add it to your map.

    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
        L.esri.Static.Util.getSelf(accessToken).then((data) => {
    
          const basemapLayers = {};
    
          data.styles.forEach(style => {
            basemapLayers[style.name] = L.esri.Static.staticBasemapTileLayer('beta' + style.path, {
              token: accessToken
            })
          })
    
          L.control.layers(basemapLayers, null, { collapsed: false }).addTo(map);
    
        })
    
    Expand
  5. Append addTo to the ArcGIS Navigation entry so that it is the default style when the application loads.

    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
        L.esri.Static.Util.getSelf(accessToken).then((data) => {
    
          const basemapLayers = {};
    
          data.styles.forEach(style => {
            basemapLayers[style.name] = L.esri.Static.staticBasemapTileLayer('beta' + style.path, {
              token: accessToken
            })
          })
    
          L.control.layers(basemapLayers, null, { collapsed: false }).addTo(map);
    
          basemapLayers['ArcGIS Navigation'].addTo(map);
    
        })
    
    Expand

Run the app

In CodePen, run your code to display the map.

Use the layers control in the top right to select and explore different basemap layer styles from the static basemap tiles service.

What's next?

Learn how to use additional ArcGIS location 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.