A vector tile layer is a hosted data layer in ArcGIS. The data is vector tile data. You can create a vector tile layer by publishing your data with data management tools. To display vector tiles in MapLibre GL JS, you create a source to retrieve the tiles, and a layer to display them.
In this tutorial, you display a parcels layer from a public vector tile service, using the default styling.
To access location services, you need an API key or OAuth 2.0 access token. To learn how to create and scope your key, visit the Create an API key tutorial.
Go to your dashboard to get an API key. The API key must be scoped to access the services used in this tutorial.
In CodePen, update apiKey to use your key.
Use dark colors for code blocks
Change line
1
2
3
4
5
6
7
8
9
10
const apiKey = "YOUR_API_KEY";
const basemapEnum = "ArcGIS:Streets";
const map = new maplibregl.Map({
container: "map", // the id of the div elementstyle: `https://basemaps-api.arcgis.com/arcgis/rest/services/styles/${basemapEnum}?type=style&token=${apiKey}`,
zoom: 12, // starting zoomcenter: [-118.805, 34.027] // starting location [longitude, latitude]});
Add a load event handler
You need to wait for the map to be completely loaded before adding any layers
You use a source of type vector to add the vector tiles. The source tells MapLibre GL JS how to access the data for the layer, but does not visually add it to the map.
Inside the load event handler, add a vector tile source with id parcels.
While there are several types of source, the two most common are vector (for vector tiles) and geojson (for a set of features represented as GeoJSON).
A layer in MapLibre GL JS is a visual representation of the data within one source. Use a layer of type fill to display the parcels.
Use addLayer to add a fill layer with id parcels-fill. Set source to parcels to reference the source you just created, and source-layer as Parcels to reference the specific layer within the vector tile set. Add paint properties to color the parcels light blue.
The type property defines how it will be displayed. Commonly used layer types include circle, line, fill and symbol (used for text and icons).
The id property is an identifier you choose. You will need it if you want to manipulate the layer, such as hiding it or changing its properties dynamically.
The source property references the id property of the source you just created.
The source-layer property tells MapLibre GL JS which layer within the vector tiles to display. If you enter the source-layer property incorrectly, nothing will display.
The paint properties control the visual attributes of the layer and are specific to the type of layer.