Skip to content

Add a vector tile layer

Learn how to add a vector tile layer to a map.

Add a vector tile layer using API key authentication

A vector tile layer is a hosted data layer in ArcGIS. The data is vector tile data. You can publish a vector tile layer by from an existing hosted feature layer. To display ArcGIS vector tiles in a MapLibre GL JS app, use the MapLibre ArcGIS plugin.

In this tutorial, display a parcels layer from a vector tile service using the default styling.

Prerequisites

You need an ArcGIS Location Platform or ArcGIS Online account.

Steps

Review the source data

This tutorial uses the Santa Monica Mountains Parcels vector tile service.

  1. Go to the item page for the Santa Monica Mountains Parcels vector tile service.

  2. Get the item ID of the vector tile layer from the URL, for example:

    • URL: https://www.arcgis.com/home/item.html?id=f0298e881b5b4743bbdf2c7d378acc84
    • Item ID: f0298e881b5b4743bbdf2c7d378acc84
  3. Copy the item ID and store it somewhere safe. You will need this in a later step.

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 the correct privileges to access the resources used in this tutorial.

  1. Go to the Create an API key tutorial to follow the steps to get an access token with these 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.

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.

    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
        /* Use for API key authentication */
        const accessToken = "YOUR_ACCESS_TOKEN";
    
    Expand

Add a vector tile layer

To add the vector tile layer to your map, use the MapLibre ArcGIS plugin.

  1. Use map.on('load', ...) to register an event handler that runs only once when the map has finished loading.

    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
      map.on("load", async () => {
    
      });
    
    Expand
  2. Inside the load event, use the plugin to create a new VectorTileLayer object that references the item ID of the vector tile layer you copied earlier and add it 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
      map.on("load", async () => {
    
        const vectorLayer = await maplibreArcGIS.VectorTileLayer.fromPortalItem('f0298e881b5b4743bbdf2c7d378acc84', {
          token: accessToken,
        });
        vectorLayer.addSourcesAndLayersTo(map);
    
      });
    
    Expand

Run the app

Run the app.

You should see the vector tile layer with light blue parcels displayed on the basemap.

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.