Skip to content

Learn how to use the ArcGIS Static Basemap Tiles service to display a raster tile basemap.

Display a map using API key authentication

The ArcGIS Static Basemap Tiles service provides basemap data as pre-rendered and pre-styled map tiles for the world. The service rovides styles from the ArcGIS Basemap style family that are grouped into categories such as streets, topography, reference, and creative.

In this tutorial, you display the ArcGIS Navigation basemap style provided by the service.

Prerequisites

You need an ArcGIS Location Platform account.

ArcGIS Online and ArcGIS Enterprise accounts are not supported.

Steps

Create a new app

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

  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
    73
    74
    75
    76
    77
    78
    79
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
        <title>OpenLayers 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 API key or OAuth developer credentials in your portal for the type of authentication you selected.

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 access token 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
    73
    74
    75
    76
    77
    78
    79
        <script>
    
          /* Use for API key authentication */
          const accessToken = "YOUR_ACCESS_TOKEN";
    
          const map = new ol.Map({
            target: "map",
    
            layers: [tileLayer],
    
            view: new ol.View({
              center: ol.proj.fromLonLat([-20, 30]),
              zoom: 3
            })
          });
    
        </script>
    
    Expand

Add script references

You will need add <script> and <link> tags to load the JavaScript and CSS files for OpenLayers and ol-mapbox-style.

  1. In the index.html file, add the following <link> and <script> references if they are missing.

    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
    77
    78
    79
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v10.7.0/ol.css">
        <script src="https://cdn.jsdelivr.net/npm/ol@v10.7.0/dist/ol.js"></script>
    

Create a map

Use the Map and View classes to create an OpenLayers map.

  1. Use the Map class to create a map. Set the target property to "map", which is the id of the div element. To center the map view, set the center property to -20, 30 and the zoom property to 3.

    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
    77
    78
    79
          const map = new ol.Map({
            target: "map",
    
            view: new ol.View({
              center: ol.proj.fromLonLat([-20, 30]),
              zoom: 3
            })
          });
    
    Expand

Add a basemap layer

  1. Create a basemapId variable and set it to arcgis/navigation. To find a list of basemap styles, go to Introduction to the Static Basemap Tiles service .

    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
    77
    78
    79
          const basemapId = "arcgis/navigation";
    
    
    Expand
  2. Construct the basemap URL based on basemapId and 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
    73
    74
    75
    76
    77
    78
    79
          const basemapId = "arcgis/navigation";
    
          const basemapURL = "https://static-map-tiles-api.arcgis.com/arcgis/rest/services/static-basemap-tiles-service/v1";
    
    
    Expand
  3. Create a Tile object that will provide basemap tiles to the map. Pass basemapId into the tile source's URL.

    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
    77
    78
    79
        <script>
    
          /* 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_URI", // The redirect URL registered in your OAuth credentials
          //   portal: "https://www.arcgis.com/sharing/rest" // Your portal URL
          // })
    
          // const accessToken = session.token;
    
          const basemapId = "arcgis/navigation";
    
          const basemapURL = "https://static-map-tiles-api.arcgis.com/arcgis/rest/services/static-basemap-tiles-service/v1";
    
          const tileLayer = new ol.layer.Tile({
            source: new ol.source.XYZ({
              url: `${basemapURL}/${basemapId}/static/tile/{z}/{y}/{x}?token=${accessToken}`, // Default basemap
              tileSize: 512
            })
          });
    
          const map = new ol.Map({
            target: "map",
    
            view: new ol.View({
              center: ol.proj.fromLonLat([-20, 30]),
              zoom: 3
            })
          });
    
        </script>
    
  4. Pass the tileLayer into the map's layers attribute.

    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
    77
    78
    79
          const map = new ol.Map({
            target: "map",
    
            layers: [tileLayer],
    
            view: new ol.View({
              center: ol.proj.fromLonLat([-20, 30]),
              zoom: 3
            })
          });
    
    Expand

Add attribution

You need to display Esri and data attribution in all applications that use Esri technology.

  1. Fetch the copyrightText from the service URL. Then, display it and prepend Powered by Esri string in the map's attribution control.

    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
    77
    78
    79
          fetch(`${basemapURL}/${basemapId}/static?token=${accessToken}`)
            .then((response) => response.json())
            .then((data) => {
              tileLayer
                .getSource()
                .setAttributions("Powered by <a href='https://www.esri.com/en-us/home' target='_blank'>Esri</a> | " + [data.copyrightText]);
            });
    
    Expand

Run the app

Run the app.

The map should display the ArcGIS Navigation basemap layer centered on the world.

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.