Add a published vector tile layer to an existing map.
A vector tile layer is a hosted data layer. The data is vector tile data. You can create a vector tile layer by publishing your data with data management tools.
In this tutorial, you display a parcels layer from a public vector tile service, using the default styling.
Prerequisites
Steps
Create a new pen
- To get started, either complete the Display a map tutorial or .
Get an access token
You need an access token with the correct privileges to access the location services used in this tutorial.
- Go to the Create an API key tutorial and create an API key with the following privilege(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.
- Privileges
- In CodePen, set
esri
to your access token.Config.api Key Use dark colors for code blocks 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
basemap
attribute to display a gray basemap.Use dark colors for code blocks <arcgis-map basemap="arcgis/light-gray" center="-118.805, 34.027" zoom="13"> <arcgis-zoom position="top-left"></arcgis-zoom> </arcgis-map>
Add modules
- In a new
<script
at the bottom of the> <body
, use> $arcgis.import
to add theVector
module.Tile Layer The ArcGIS Maps SDK for JavaScript is available via CDN and npm, but this tutorial is based on CDN. The
$arcgis.import
global 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.Use dark colors for code blocks <script type="module"> const VectorTileLayer = await $arcgis.import("@arcgis/core/layers/VectorTileLayer.js"); </script>
Add the vector tile layer
-
Use the
view
method to wait until the Map component is ready before adding the layer.On Ready Use dark colors for code blocks <script type="module"> const VectorTileLayer = await $arcgis.import("@arcgis/core/layers/VectorTileLayer.js"); const viewElement = document.querySelector("arcgis-map"); await viewElement.viewOnReady(); </script>
-
Create a
Vector
and set theTile Layer url
property to reference the vector tile layer.Use dark colors for code blocks <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>
-
Add the
Vector
to the map.Tile Layer Use dark colors for code blocks <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>
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 API features and ArcGIS services in these tutorials: