Skip to content

Display multiple basemap layers

Learn how to add multiple basemap layers from different services to your map.

Display multiple basemap layers with API key authentication

This tutorial shows how to display two basemap layers from different services in your application. You will use the World Imagery map tile service satellite imagery basemap to provide the underlying visual and geographic context for the map. To provide additional context, you will use the arcgis/imagery/labels style from the ArcGIS Static Basemap Tiles service to display place labels for the world. The combination of the two layers will result in a basemap that provides additional context for the mapping application.

Prerequisites

You need an ArcGIS Location Platform account.

ArcGIS Online and ArcGIS Enterprise accounts are not supported.

Steps

Get the starter app

Select a type of authentication and follow the steps to create a new app.

You can choose one of the following to create a new CodePen:

  • Option 1: Complete the Display a map tutorial; or,
  • Option 2: Start from the Display a map tutorial .

Set up authentication

Create a new API key credential with the correct privileges to get an access token.

  1. Go to the Create an API key tutorial and create an API key with the following privilege(s):
    • Privileges
      • Location services > Basemaps > Static basemap tiles

Set developer credentials

Use the API key or OAuth developer credentials so your application can access ArcGIS services.

  1. Update the accessToken variable to use your API key.

    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
        <script>
    
          /* Use for API key authentication */
          const accessToken = "YOUR_ACCESS_TOKEN";
    
          const map = L.map("map", {
            minZoom: 2
          });
    
        </script>
    

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

Add a second basemap layer

Use the TiledMapLayer class to access and display basemap layer from the World Imagery map tile service alongside existing static basemap tile layer.

  1. Modify the basemap style to arcgis/imagery/labels.

    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
          const basemapEnum = "arcgis/imagery/labels";
    
          L.esri.Static.staticBasemapTileLayer(basemapEnum, {
            token: accessToken
          }).addTo(map);
    
    Expand
  2. Add another basemap layer from the World Imagery map tile service with tiledMapLayer to the 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
          const tileLayer = L.esri.tiledMapLayer({
            url: "https://ibasemaps-api.arcgis.com/arcgis/rest/services/World_Imagery/MapServer",
            token: accessToken
          });
    
          tileLayer.addTo(map);
    
    Expand

Run the app

Run the app.

The map should display basemap layers from the World Imagery map tile service and the Static Basemap Tiles service.

What's next?

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