Display a custom basemap style

Learn how to add a custom vector basemap layer to a map.

Display a custom basemap style using API key authentication

A basemap layer provides the visual context for a map. You can use the default basemap layer styles provided by the basemap styles service or you can create your own custom styles with the ArcGIS Vector Tile Style Editor for specific mapping applications.

In this tutorial you display a styled vector basemap layer in a map. You can view the basemap layer style in the vector tile style editor here.

Prerequisites

Steps

Get the starter app

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

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 developer credentials in your portal for the type of authentication you selected.

Create a new API key credential with 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
    • Item access
      • Note: If you are using your own custom data layer for this tutorial, you need to grant the API key credentials access to the layer item. Learn more in Item access privileges.
  2. When prompted, copy and paste the API key to a safe location. It will be used in the next step.

Set developer credentials

Use the API key or OAuth developer credentials so your application can access location 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
    75
    76
      <script>
    
        /* Use for API key authentication */
        const accessToken = "YOUR_ACCESS_TOKEN";
    
        const map = L.map("map", {
          minZoom: 2
        })
    
        map.setView([34.02, -118.805], 13);
    
        const basemapEnum = "arcgis/streets";
    
        L.esri.Vector.vectorBasemapLayer(basemapEnum, {
          token: accessToken
        }).addTo(map);
    
      </script>
    

Add the vector tile layer

You can display a vector tile layer by either using its service URL or item ID. You can find a layer's item ID by accessing it in your portal or the ArcGIS Vector Tile Style Editor.

  1. Go to the Forest and Parks Canvas vector tile layer in your portal and find its item ID. The ID is at the end of the URL.

  2. Change the basemapEnum from arcgis/streets to the custom item ID.

    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
        /* Use for API key authentication */
        const accessToken = "YOUR_ACCESS_TOKEN";
    
        // or
    
        /* Use for user authentication */
        // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({
        //   clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials
        //   redirectUri: "YOUR_REDIRECT_URL", // The redirect URL registered in your OAuth credentials
        //   portal: "https://www.arcgis.com/sharing/rest" // Your portal URL
        // })
    
        // const accessToken = session.token;
        const map = L.map("map", {
          minZoom: 2
        })
    
        map.setView([34.02, -118.805], 13);
    
        const basemapEnum = "6976148c11bd497d8624206f9ee03e30";
    
        L.esri.Vector.vectorBasemapLayer(basemapEnum, {
          token: accessToken
        }).addTo(map);
    
    Expand

Run the app

Run the app.

It should display the Forest and Parks Canvas vector basemap layer.

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.