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

Pan and zoom the map to explore the custom vector tile styles.

A styled basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more is a set of styles A style is the visual definition of how geographic data is displayed in a map including colors, backgrounds, outlines, labels, and other visual elements. Each style emphasizes a specific type of cartographic theme and data. Learn more that you define to override one of the default basemap styles service The ArcGIS Basemap Styles service, also referred to as the Basemap Styles service, is a location service that provides basemap styles and data for the world. It returns styles as Mapbox styles and web maps, and data as vector tiles and/or map tiles. It supports all of the styles in the ArcGIS Basemap style and Open Basemap style family. An ArcGIS Location Platform or ArcGIS Online account is required to use the service. Learn more vector tile layer styles. These are used to create and display a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more or scene A scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more with your own custom styles, labels, and colors. To create a styled basemap layer, you can use the ArcGIS Vector Tile Style Editor The ArcGIS Vector Tile Style Editor is a web-based application used to create, edit, and save a custom style for vector tile basemap layer. Learn more . The editor stores your styles in ArcGIS ArcGIS is the brand name for all of the desktop, server, and developer products and technologies offered by Esri. Learn more as a layer item An item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. Learn more with an item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more .

In this tutorial, you will use an item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more to access and display a styled vector tile layer (Forest and Parks Canvas) in a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more . You also add an image tile layer (World Hillshade) to enhance the visualization. Both layers are hosted in ArcGIS Online ArcGIS Online is a GIS mapping, analytics, data hosting, and content management software as a service (SaaS) product. It includes applications, tools, APIs, and location services for users and developers. It is subscription-based and requires an ArcGIS Online account. Learn more .

Prerequisites

Steps

Create a new pen

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

Get an access token

You need an access token An access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more with the correct privileges to access the location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more used in this tutorial.

  1. Go to the Create an API key tutorial and create an API key An API key is a long-lived access token created using API key credentials. They are valid for up to one year and are typically embedded directly into client applications. Learn more with the following privilege(s) Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more :
    • Privileges
      • Location services > Basemaps
  2. In CodePen, set the apiKey property on the global esriConfig variable to your access token.
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };

To learn about other ways to get an access token, go to Types of authentication.

Add modules

  1. In a new <script> at the bottom of the <body>, add the Basemap, VectorTileLayer, and TileLayer modules.

    33 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Display a custom basemap style</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [Basemap, TileLayer, VectorTileLayer] = await $arcgis.import([
    "@arcgis/core/Basemap.js",
    "@arcgis/core/layers/TileLayer.js",
    "@arcgis/core/layers/VectorTileLayer.js",
    ]);
    </script>
    5 collapsed lines
    </body>
    </html>

Create a vector tile layer

You can access a basemap layer by referencing its item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more . You can find a layer’s item ID by accessing it with ArcGIS Online ArcGIS Online is a GIS mapping, analytics, data hosting, and content management software as a service (SaaS) product. It includes applications, tools, APIs, and location services for users and developers. It is subscription-based and requires an ArcGIS Online account. Learn more or the ArcGIS Vector Tile Style Editor The ArcGIS Vector Tile Style Editor is a web-based application used to create, edit, and save a custom style for vector tile basemap layer. Learn more .

  1. Go to the Forest and Parks Canvas vector tile layer in ArcGIS Online and find its item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more . 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.

    41 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Display a custom basemap style</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [Basemap, TileLayer, VectorTileLayer] = await $arcgis.import([
    "@arcgis/core/Basemap.js",
    "@arcgis/core/layers/TileLayer.js",
    "@arcgis/core/layers/VectorTileLayer.js",
    ]);
    const vectorTileLayer = new VectorTileLayer({
    portalItem: {
    id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
    },
    opacity: 0.75,
    });
    6 collapsed lines
    </script>
    </body>
    </html>

Create an image tile layer

Use ArcGIS Online ArcGIS Online is a GIS mapping, analytics, data hosting, and content management software as a service (SaaS) product. It includes applications, tools, APIs, and location services for users and developers. It is subscription-based and requires an ArcGIS Online account. Learn more to find the item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more for the World Hillshade image tile layer and then use it to access the layer A layer is a reference to a collection of geographic data that is used to access and display data. The data for layers are typically provided by the basemap layer service and data services. Learn more . 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.

41 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>ArcGIS Maps SDK for JavaScript Tutorials: Display a custom basemap style</title>
<style>
html,
body {
height: 100%;
margin: 0;
}
</style>
<script>
var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };
</script>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
</head>
<body>
<arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13">
<arcgis-zoom slot="top-left"></arcgis-zoom>
</arcgis-map>
<script type="module">
const [Basemap, TileLayer, VectorTileLayer] = await $arcgis.import([
"@arcgis/core/Basemap.js",
"@arcgis/core/layers/TileLayer.js",
"@arcgis/core/layers/VectorTileLayer.js",
]);
const vectorTileLayer = new VectorTileLayer({
portalItem: {
id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
},
opacity: 0.75,
});
const hillshadeTileLayer = new TileLayer({
portalItem: {
id: "1b243539f4514b6ba35e7d995890db1d", // World Hillshade
},
});
6 collapsed lines
</script>
</body>
</html>

Add the basemap layers

Basemaps can contain multiple baseLayers. Use the Basemap class to add the vectorTileLayerand hillshadeTileLayer created above. These layers will create the underlying style for the map. The vector tile layer provides the base colors and the image tile layer provides the hillshade A hillshade is a layer data source with raster images that portrays hypothetical illumination of a surface by determining illumination values for each cell in a raster. Learn more or topographic effect.

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

    41 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Display a custom basemap style</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [Basemap, TileLayer, VectorTileLayer] = await $arcgis.import([
    "@arcgis/core/Basemap.js",
    "@arcgis/core/layers/TileLayer.js",
    "@arcgis/core/layers/VectorTileLayer.js",
    ]);
    const vectorTileLayer = new VectorTileLayer({
    portalItem: {
    id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
    },
    opacity: 0.75,
    });
    const hillshadeTileLayer = new TileLayer({
    portalItem: {
    id: "1b243539f4514b6ba35e7d995890db1d", // World Hillshade
    },
    });
    const basemap = new Basemap({ baseLayers: [hillshadeTileLayer, vectorTileLayer] });
    6 collapsed lines
    </script>
    </body>
    </html>
  2. Update the map’s basemap property to use the basemap object created earlier.

    41 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Display a custom basemap style</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [Basemap, TileLayer, VectorTileLayer] = await $arcgis.import([
    "@arcgis/core/Basemap.js",
    "@arcgis/core/layers/TileLayer.js",
    "@arcgis/core/layers/VectorTileLayer.js",
    ]);
    const vectorTileLayer = new VectorTileLayer({
    portalItem: {
    id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
    },
    opacity: 0.75,
    });
    const hillshadeTileLayer = new TileLayer({
    portalItem: {
    id: "1b243539f4514b6ba35e7d995890db1d", // World Hillshade
    },
    });
    const basemap = new Basemap({ baseLayers: [hillshadeTileLayer, vectorTileLayer] });
    const viewElement = document.querySelector("arcgis-map");
    viewElement.basemap = basemap;
    6 collapsed lines
    </script>
    </body>
    </html>

Update the map position

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

    56 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Display a custom basemap style</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [Basemap, TileLayer, VectorTileLayer] = await $arcgis.import([
    "@arcgis/core/Basemap.js",
    "@arcgis/core/layers/TileLayer.js",
    "@arcgis/core/layers/VectorTileLayer.js",
    ]);
    const vectorTileLayer = new VectorTileLayer({
    portalItem: {
    id: "6976148c11bd497d8624206f9ee03e30", // Forest and Parks Canvas
    },
    opacity: 0.75,
    });
    const hillshadeTileLayer = new TileLayer({
    portalItem: {
    id: "1b243539f4514b6ba35e7d995890db1d", // World Hillshade
    },
    });
    const basemap = new Basemap({ baseLayers: [hillshadeTileLayer, vectorTileLayer] });
    const viewElement = document.querySelector("arcgis-map");
    viewElement.basemap = basemap;
    viewElement.center = [-100, 40];
    viewElement.zoom = 3;
    7 collapsed lines
    </script>
    </body>
    </html>

Run the app

In CodePen, run your code to display the map.

The map 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 SDK features and ArcGIS services in these tutorials: