Learn how to style vector tiles.
You can use OpenLayers to display vector tile
In this tutorial, you style land parcels from a public vector tile service
Prerequisites
You need an ArcGIS Location Platform or ArcGIS Online account.
Steps
Review the source data
This tutorial uses the Santa Monica Mountains Parcels vector tile service
-
Go to the item page
An item page is a web page in ArcGIS Online or the developer dashboard used to access and manage the properties for an item and the content it references such as a web map, hosted layer, or file. for the Santa Monica Mountains Parcels vector tile layerA vector tile layer is a data layer used to access and display tiled data and its corresponding styles. . -
Under Details, find the Created from property. Follow the link to view the item page for the original feature layer
A hosted feature layer is a hosted layer (item) in a portal that is used to manage the properties and settings of a spatially-enabled feature layer in a feature service. , Santa_Monica_Mountains_Parcels. -
Click the Data tab to view the layer's features
A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. and attributesAttributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. . Each feature represents a land parcel and has attributes such as an address, use code, and number of square feet. -
Review the values of the
Usefield. You will use this field to style vector tiles in your application.Type
Get the starter app
Select a type of authentication and follow the steps to create a new app.
Choose API key authentication if you:
- Want the easiest way to get started.
- Want to build public applications
A public application is an application that allows anonymous access without requiring users to sign in with an ArcGIS account. It supports API key or app authentication. that access ArcGIS Location ServicesArcGIS 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. and secure itemsAn 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. . - Have an ArcGIS Location Platform or ArcGIS Online account.
Choose user authentication if you:
- Want to build private applications.
- Require application users to sign in with their own ArcGIS account
An ArcGIS account is an identity with a user type and set of privileges that can access specific ArcGIS products, tools, APIs, services, and resources. The main account types that can be used for development are an ArcGIS Location Platform account, ArcGIS Online account, and ArcGIS Enterprise account. ArcGIS Location Platform and ArcGIS Online accounts are also associated with a subscription. and access resources their behalf. - Have an ArcGIS Online account.
To learn more about both types of authentication, go to Authentication.
Set up authentication
Set developer credentials
Use the API key or OAuth developer credentials
Add the vector tile layer
Add a vector tile Source and a vector tile Layer to your application to display data from the Santa Monica Mountains Parcels vector tile service
-
Create a
Vectorsource using anTile MVTfeature format. Save it to aparcelsvariable.Source Use dark colors for code blocks olms.apply(map, basemapURL).then((map) => { const parcelsSource = new ol.source.VectorTile({ format: new ol.format.MVT(), url: "https://vectortileservices3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_Mountains_Parcels_VTL/VectorTileServer/tile/{z}/{y}/{x}.pbf", }); -
Add the data attribution
Data attribution is the requirement to display the names of data source providers in all applications when accessing ArcGIS content, layers, or services. for the vector tile layer source.- Go to the Santa Monica Mountains Parcels 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. . - Scroll down to the Acknowledgments section and copy its value.
- Paste the copied value to the
attributionsproperty.Use dark colors for code blocks olms.apply(map, basemapURL).then((map) => { const parcelsSource = new ol.source.VectorTile({ format: new ol.format.MVT(), url: "https://vectortileservices3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_Mountains_Parcels_VTL/VectorTileServer/tile/{z}/{y}/{x}.pbf", // Attribution text retrieved from https://arcgis.com/home/item.html?id=f0298e881b5b4743bbdf2c7d378acc84 attributions: ["| County of Los Angeles Office of the Assessor"] });
- Go to the Santa Monica Mountains Parcels item
-
Create a
Vectorlayer, referencing theTile parcelssource.Source Use dark colors for code blocks const parcelsSource = new ol.source.VectorTile({ format: new ol.format.MVT(), url: "https://vectortileservices3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_Mountains_Parcels_VTL/VectorTileServer/tile/{z}/{y}/{x}.pbf", // Attribution text retrieved from https://arcgis.com/home/item.html?id=f0298e881b5b4743bbdf2c7d378acc84 attributions: ["| County of Los Angeles Office of the Assessor"] }); const parcelsLayer = new ol.layer.VectorTile({ source: parcelsSource }); -
Add the layer to the map with
map.add.Layer Use dark colors for code blocks const parcelsLayer = new ol.layer.VectorTile({ source: parcelsSource }); map.addLayer(parcelsLayer);
Create a MapLibre style object
The ol-mapbox-style library will allow you to style data and reference the attributesUse attribute.
-
Create a MapLibre style object and set the root properties. Set
versionto 8 and include a source of typevector. Do not include other source parameters, as you have already created a source using OpenLayers.Use dark colors for code blocks map.addLayer(parcelsLayer); const parcelsStyle = { version: 8, sources: { parcels: { type: "vector" } }, layers: [ ] }; -
Add a
filllayer that references theparcelssource. Setsource-layertoSantato reference the original feature service._Monica _Mountains _Parcels Use dark colors for code blocks const parcelsStyle = { version: 8, sources: { parcels: { type: "vector" } }, layers: [ { "id": "parcels-fill", "source": "parcels", "source-layer": "Santa_Monica_Mountains_Parcels", "type": "fill", }, ] }; -
Add a custom
fill-colorto the layer. Usegetto retrieveUseattribute values, viewed in the previous step. UseType caseto create a conditional expression that assigns a unique color to each use type.Use dark colors for code blocks const parcelsStyle = { version: 8, sources: { parcels: { type: "vector" } }, layers: [ { "id": "parcels-fill", "source": "parcels", "source-layer": "Santa_Monica_Mountains_Parcels", "type": "fill", "paint": { "fill-color": ["case", ["==", ["get", "UseType"], "Residential"], "#E8E191", // Yellow ["==", ["get", "UseType"], "Commercial"], "#E580A2", // Red ["==", ["get", "UseType"], "Government"], "#79E284", // Green ["==", ["get", "UseType"], "Industrial"], "#C080E5", // Purple ["==", ["get", "UseType"], "Institutional"], "#80BBE5", // Blue "#bfbfbf" ] } }, ] };
Add an outline layer
Add a second vector tile layer to the style object to customize the parcel outlines.
-
Add a
linelayer to thelayerslist in the style object. Set the layer ID toparcels-outline, the source toparcels, and thesource-layertoSantato reference the original feature service._Monica _Mountains _Parcels Use dark colors for code blocks const parcelsStyle = { version: 8, sources: { parcels: { type: "vector" } }, layers: [ { "id": "parcels-fill", "source": "parcels", "source-layer": "Santa_Monica_Mountains_Parcels", "type": "fill", "paint": { "fill-color": ["case", ["==", ["get", "UseType"], "Residential"], "#E8E191", // Yellow ["==", ["get", "UseType"], "Commercial"], "#E580A2", // Red ["==", ["get", "UseType"], "Government"], "#79E284", // Green ["==", ["get", "UseType"], "Industrial"], "#C080E5", // Purple ["==", ["get", "UseType"], "Institutional"], "#80BBE5", // Blue "#bfbfbf" ] } }, { "id": "parcels-outline", "source": "parcels", "source-layer": "Santa_Monica_Mountains_Parcels", "type": "line", } ] }; -
Style the color, width, and opacity of the parcel outlines.
Use dark colors for code blocks { "id": "parcels-outline", "source": "parcels", "source-layer": "Santa_Monica_Mountains_Parcels", "type": "line", "paint": { "line-color": "#000000", "line-width": 0.25, "line-opacity": 0.25 } }
Apply the layer style
Use ol-mapbox-style to apply the MapLibre style object to the vector tile layer.
-
Call
olms.applywith the parcels layer and parcels style to customize the vector tiles. SetStyle() updatetoSource falseto preserve the OpenLayers source you provided.Use dark colors for code blocks "paint": { "line-color": "#000000", "line-width": 0.25, "line-opacity": 0.25 } } ] }; olms.applyStyle(parcelsLayer, parcelsStyle, { updateSource: false });
Run the app
Run the app.
You should see the styled vector tile layer with parcels displayed on the basemap layer. Parcels shouold be styled in different colors based on their use type, and thin outlines should be present around each parcel.What's next?
Learn how to use additional location services in these tutorials:


