Add a published vector tile layer to an existing map.
A
In this tutorial, you display a parcels layer from a public
Prerequisites
Steps
Create a new pen
- To get started, either complete the Display a map tutorial or
.
Get an access token
You need an
- Go to the Create an API key tutorial and create an
API key with the followingprivilege(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.
- Note: If you are using your own custom data layer for this tutorial, you need to grant the
- Privileges
- In CodePen, set the
apiKeyproperty on the globalesriConfigvariable 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.
Update the map
- Update the
basemapattribute to display a gray basemap and change the zoom level.26 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: Add a vector tile layer</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/light-gray" center="-118.805, 34.020" zoom="12"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map>4 collapsed lines</body></html>
Add modules
- In a new
<script>at the bottom of the<body>, use$arcgis.importto add theVectorTileLayermodule.The
ArcGIS Maps SDK for JavaScript is available via CDN and npm, but this tutorial is based on CDN. The$arcgis.importglobal function accepts a module path or array of module paths, and returns a promise that resolves with the requested modules. This function can only be used when working with the CDN; otherwise, use the standard import syntax. To learn more about the SDK’s different modules, visit the References page.31 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: Add a vector tile layer</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/light-gray" center="-118.805, 34.020" zoom="12"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const VectorTileLayer = await $arcgis.import("@arcgis/core/layers/VectorTileLayer.js");</script>4 collapsed lines</body></html>
Add the vector tile layer
-
Use the
viewOnReadymethod to wait until the Map component is ready before adding the layer.31 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: Add a vector tile layer</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/light-gray" center="-118.805, 34.020" zoom="12"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const VectorTileLayer = await $arcgis.import("@arcgis/core/layers/VectorTileLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();</script>4 collapsed lines</body></html> -
Create a
VectorTileLayerand set theurlproperty to reference thevector tile layer .31 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: Add a vector tile layer</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/light-gray" center="-118.805, 34.020" zoom="12"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const VectorTileLayer = await $arcgis.import("@arcgis/core/layers/VectorTileLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();const vtlLayer = new VectorTileLayer({url: "https://vectortileservices3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_Mountains_Parcels_VTL/VectorTileServer/",});</script>4 collapsed lines</body></html> -
Add the
VectorTileLayerto the map.31 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: Add a vector tile layer</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/light-gray" center="-118.805, 34.020" zoom="12"><arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map><script type="module">const VectorTileLayer = await $arcgis.import("@arcgis/core/layers/VectorTileLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();const vtlLayer = new VectorTileLayer({url: "https://vectortileservices3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_Mountains_Parcels_VTL/VectorTileServer/",});viewElement.map.add(vtlLayer);</script>4 collapsed lines</body></html>
Run the App
In CodePen, run your code to display the map.
You should see the vector tile layer with parcels displayed on the basemap layer.
What’s next?
Learn how to use additional SDK features and ArcGIS services in these tutorials: