Display a custom basemap style

Learn how to access and display a styled vector basemap layer in a map.

A styled basemap layer is a set of styles that you define to override one of the default Basemap layer service vector tile layer styles. These are used to create and display a map or scene with your own custom styles, labels, and colors. To create a styled basemap layer, you use the ArcGIS Vector Tile Style Editor. The editor stores your styles in ArcGIS as a layer item with an item ID.

In this tutorial, you use an item ID to access and display a styled vector tile layer (Forest and Parks Canvas) in a map. You also add an image tile layer (World Hillshade) to enhance the visualization. Both layers are hosted in ArcGIS Online.

Prerequisites

You need a free ArcGIS developer account to access your dashboard and API keys. The API key must be scoped to access the services used in this tutorial.

Steps

Create a new pen

  1. To get started, either complete the Display a map tutorial or .

Set the API key

To access ArcGIS services, you need an API key.

  1. Go to your dashboard to get an API key.

  2. In CodePen, set the apiKey to your key, so it can be used to access basemap layer and location services.

    Change line
        
    esriConfig.apiKey = "YOUR-API-KEY";
    const map = new Map({
      basemap: "arcgis-topographic" //Basemap layer service
    });
    

Add modules

  1. In the require statement, add the Basemap, VectorTileLayer, and TileLayer modules.

    The ArcGIS API for JavaScript uses AMD modules. The require function is used to load modules so they can be used in the main function. It's important to keep the module references and function parameters in the same order.

    Add line.Add line.Add line.Change lineChange lineChange line
                                                                            
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Add a styled basemap layer</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>  <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.19/"></script>
      <script>
    
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
    
        "esri/Basemap",
        "esri/layers/VectorTileLayer",
        "esri/layers/TileLayer",
    
      ], function(esriConfig,Map, MapView, Basemap, VectorTileLayer, TileLayer) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
      const vectorTileLayer = new VectorTileLayer({
        portalItem: {
          id: "6976148c11bd497d8624206f9ee03e30" // Forest and Parks Canvas
        },
        opacity: .75
      });
    
      const imageTileLayer = new TileLayer({
        portalItem: {
          id: "1b243539f4514b6ba35e7d995890db1d" // World Hillshade
        }
      });
    
      const basemap = new Basemap({
        baseLayers: [
    
          imageTileLayer,
          vectorTileLayer
    
        ]
      });
    
    // const apikey = YOUR-API-KEY ;
      const map = new Map({
        basemap: basemap,
      });
    
      const view = new MapView({
        container: "viewDiv",
        map: map,
    
        center: [-100,40],
        zoom: 3
    
      });
    
      });
      </script>
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Create a vector tile layer

You can access a basemap layer by referencing its item ID. You can find a layer's item ID by accessing it with ArcGIS Online or the ArcGIS Vector Tile Style Editor.

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

  2. In CodePen, create a new VectorTileLayer object and set its portalItem id property to d2ff12395aeb45998c1b154e25d680e5 and the opacity property to 0.75.

    Learn more about loading a layer by its item ID in the API reference.

    Add line.Add line.Add line.Add line.Add line.Add line.
                                                                            
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Add a styled basemap layer</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>  <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.19/"></script>
      <script>
    
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
    
        "esri/Basemap",
        "esri/layers/VectorTileLayer",
        "esri/layers/TileLayer",
    
      ], function(esriConfig,Map, MapView, Basemap, VectorTileLayer, TileLayer) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
      const vectorTileLayer = new VectorTileLayer({
        portalItem: {
          id: "6976148c11bd497d8624206f9ee03e30" // Forest and Parks Canvas
        },
        opacity: .75
      });
    
      const imageTileLayer = new TileLayer({
        portalItem: {
          id: "1b243539f4514b6ba35e7d995890db1d" // World Hillshade
        }
      });
    
      const basemap = new Basemap({
        baseLayers: [
    
          imageTileLayer,
          vectorTileLayer
    
        ]
      });
    
    // const apikey = YOUR-API-KEY ;
      const map = new Map({
        basemap: basemap,
      });
    
      const view = new MapView({
        container: "viewDiv",
        map: map,
    
        center: [-100,40],
        zoom: 3
    
      });
    
      });
      </script>
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Create an image tile layer

Use ArcGIS Online to find the item ID for the World Hillshade image tile layer and then use it to access the layer. The image tile layer will be used to visually enhance the styles with terrain.

  1. Go to the World Hillshade image tile layer in ArcGIS and find its item ID. The ID is at the end of the URL.

  2. In CodePen, create a new TileLayer and set its portalItem id property to 1b243539f4514b6ba35e7d995890db1d.

    Learn more about loading a layer by its item ID in the API reference.

    Add line.Add line.Add line.Add line.Add line.
                                                                            
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Add a styled basemap layer</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>  <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.19/"></script>
      <script>
    
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
    
        "esri/Basemap",
        "esri/layers/VectorTileLayer",
        "esri/layers/TileLayer",
    
      ], function(esriConfig,Map, MapView, Basemap, VectorTileLayer, TileLayer) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
      const vectorTileLayer = new VectorTileLayer({
        portalItem: {
          id: "6976148c11bd497d8624206f9ee03e30" // Forest and Parks Canvas
        },
        opacity: .75
      });
    
      const imageTileLayer = new TileLayer({
        portalItem: {
          id: "1b243539f4514b6ba35e7d995890db1d" // World Hillshade
        }
      });
    
      const basemap = new Basemap({
        baseLayers: [
    
          imageTileLayer,
          vectorTileLayer
    
        ]
      });
    
    // const apikey = YOUR-API-KEY ;
      const map = new Map({
        basemap: basemap,
      });
    
      const view = new MapView({
        container: "viewDiv",
        map: map,
    
        center: [-100,40],
        zoom: 3
    
      });
    
      });
      </script>
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Add the basemap layers

Basemaps can contain multiple baselayers. Use the Basemap class to add the vectorTileLayerand imageTileLayer created above. These layers will be blended together to create the underlying style for the map. The vector tile layer provides the base colors and the image tile layer provides the hillshade or topographic effect.

  1. In the main function, create a Basemap object and add vectorTileLayer and the imageTileLayer to the baselayers array.

    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
                                                                            
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Add a styled basemap layer</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>  <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.19/"></script>
      <script>
    
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
    
        "esri/Basemap",
        "esri/layers/VectorTileLayer",
        "esri/layers/TileLayer",
    
      ], function(esriConfig,Map, MapView, Basemap, VectorTileLayer, TileLayer) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
      const vectorTileLayer = new VectorTileLayer({
        portalItem: {
          id: "6976148c11bd497d8624206f9ee03e30" // Forest and Parks Canvas
        },
        opacity: .75
      });
    
      const imageTileLayer = new TileLayer({
        portalItem: {
          id: "1b243539f4514b6ba35e7d995890db1d" // World Hillshade
        }
      });
    
      const basemap = new Basemap({
        baseLayers: [
    
          imageTileLayer,
          vectorTileLayer
    
        ]
      });
    
    // const apikey = YOUR-API-KEY ;
      const map = new Map({
        basemap: basemap,
      });
    
      const view = new MapView({
        container: "viewDiv",
        map: map,
    
        center: [-100,40],
        zoom: 3
    
      });
    
      });
      </script>
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  2. Update the basemap property to use the basemap object created earlier.

    Change line
                                                                            
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Add a styled basemap layer</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>  <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.19/"></script>
      <script>
    
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
    
        "esri/Basemap",
        "esri/layers/VectorTileLayer",
        "esri/layers/TileLayer",
    
      ], function(esriConfig,Map, MapView, Basemap, VectorTileLayer, TileLayer) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
      const vectorTileLayer = new VectorTileLayer({
        portalItem: {
          id: "6976148c11bd497d8624206f9ee03e30" // Forest and Parks Canvas
        },
        opacity: .75
      });
    
      const imageTileLayer = new TileLayer({
        portalItem: {
          id: "1b243539f4514b6ba35e7d995890db1d" // World Hillshade
        }
      });
    
      const basemap = new Basemap({
        baseLayers: [
    
          imageTileLayer,
          vectorTileLayer
    
        ]
      });
    
    // const apikey = YOUR-API-KEY ;
      const map = new Map({
        basemap: basemap,
      });
    
      const view = new MapView({
        container: "viewDiv",
        map: map,
    
        center: [-100,40],
        zoom: 3
    
      });
    
      });
      </script>
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Update the map view

  1. Update the center and zoom properties to zoom the display to North America.

    Change lineChange line
                                                                            
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Add a styled basemap layer</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>  <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.19/"></script>
      <script>
    
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
    
        "esri/Basemap",
        "esri/layers/VectorTileLayer",
        "esri/layers/TileLayer",
    
      ], function(esriConfig,Map, MapView, Basemap, VectorTileLayer, TileLayer) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
      const vectorTileLayer = new VectorTileLayer({
        portalItem: {
          id: "6976148c11bd497d8624206f9ee03e30" // Forest and Parks Canvas
        },
        opacity: .75
      });
    
      const imageTileLayer = new TileLayer({
        portalItem: {
          id: "1b243539f4514b6ba35e7d995890db1d" // World Hillshade
        }
      });
    
      const basemap = new Basemap({
        baseLayers: [
    
          imageTileLayer,
          vectorTileLayer
    
        ]
      });
    
    // const apikey = YOUR-API-KEY ;
      const map = new Map({
        basemap: basemap,
      });
    
      const view = new MapView({
        container: "viewDiv",
        map: map,
    
        center: [-100,40],
        zoom: 3
    
      });
    
      });
      </script>
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Run the app

In CodePen, run your code to display the map.

The map view should display the Forest and Parks Canvas vector tile layer on top of the World Hillshade image tile layer. The styled vector tile layer is displayed on top of the hillshade terrain.

What's next?

Learn how to use additional API features and ArcGIS services in these tutorials: