Skip to content

Display a map

Learn how to use the ArcGIS Basemap Styles service to display a vector tile basemap.

Display a map using API key authentication

The ArcGIS Basemap Styles service provides a number of basemap styles such as topography, streets, outdoor, navigation, and imagery that you can use in maps. To display a basemap style from the service in a MapLibre GL JS app, use the MapLibre ArcGIS plugin.

In this tutorial, display a map of the world with the arcgis/outdoor basemap style.

This application will use the basemap tiles usage model .

Prerequisites

You need an ArcGIS Location Platform or ArcGIS Online account.

Steps

Create a new app

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

Create a new CodePen app with a map div that is the full width and height of the browser window.

  1. Go to CodePen and create a new pen for your application.

  2. In CodePen > HTML, add HTML and CSS to create a page with a div element called map.

    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
    <!DOCTYPE html>
    <html>
    
    <head>
    
      <meta charset="utf-8" />
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
      <title>MapLibre GL JS Tutorials: Display a map</title>
      <style>
        html,
        body,
        #map {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
          font-family: Arial, Helvetica, sans-serif;
          font-size: 14px;
          color: #323232;
        }
    
      </style>
    
    </head>
    
    
    <body>
      <div id="map"></div>
    
    </body>
    
    
    </html>

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

Set developer credentials

Use the API key or OAuth developer credentials created in the previous step in your application.

  1. Add a <script> element in the HTML <body> and create an accessToken variable to store your access token. Set YOUR_ACCESS_TOKEN with the access token you previously copied from your API key credentials.

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

Add script references

Reference the MapLibre GL JS library and the MapLibre ArcGIS plugin.

  1. In the index.html file, add the following <link> and <script> 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
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
      <meta charset="utf-8" />
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
      <title>MapLibre GL JS Tutorials: Display a map</title>
      <style>
        html,
        body,
        #map {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
          font-family: Arial, Helvetica, sans-serif;
          font-size: 14px;
          color: #323232;
        }
    
      </style>
    
      <!-- Load MapLibre GL JS from CDN -->
      <script src=https://unpkg.com/maplibre-gl@5.9.0/dist/maplibre-gl.js></script>
      <link href=https://unpkg.com/maplibre-gl@5.9.0/dist/maplibre-gl.css rel="stylesheet" />
      <!-- Load MapLibre ArcGIS from CDN -->
      <script src="https://unpkg.com/@esri/maplibre-arcgis@1.0.0/dist/umd/maplibre-arcgis.min.js"></script>
    

Create a map

Create a map to display an ArcGIS basemap style centered on the world. Use the MapLibre ArcGIS plugin to access the basemap style.

  1. Create a Map that is centered on the world.

    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
        const map = new maplibregl.Map({
          container: "map", // the id of the div element
          zoom: 2, // starting zoom
          center: [-20, 30] // starting location [longitude, latitude]
        });
    
    Expand
  2. Use the plugin to apply a BasemapStyle to the map. The plugin will automatically apply Esri and data attribution.

    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
        const basemapStyle = maplibreArcGIS.BasemapStyle.applyStyle(map, {
          style: 'arcgis/outdoor',
          token: accessToken
        });
    
    Expand

Run the app

Run the app.

The map should display the arcgis/outdoor style from the Basemap Styles 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.