Style vector tiles
Learn how to perform data-driven styling to customize the appearance of vector tiles based on their underlying feature data.
You can use Esri Leaflet to display vector tile data using custom styles. Esri Leaflet Vector supports the MapLibre style specification, which allows you to customize the fill, outline, opacity, and other properties of vector tiles to display data effectively. If your vector tiles are published from a feature service, you can also perform data-driven visualizations based on attributes of the original feature service.
In this tutorial, you style land parcels from a public vector tile service according to their use type.
Prerequisites
You need an ArcGIS Developer or ArcGIS Online account to access the developer dashboard and create an API key.
Steps
Review the source data
This tutorial uses the Santa Monica Mountains Parcels vector tile service. This vector tile service was created by publishing a feature service as vector tiles using ArcGIS.com. It contains the attributes of the original feature service, which can be accessed to style layers in your application. Find the original feature service in ArcGIS.com to view the names and values of different attributes.
Go to the item page for the Santa Monica Mountains Parcels vector tile layer.
Under Details, find the Created from property. Follow the link to view the item page for the original feature layer, Santa_Monica_Mountains_Parcels.
Click the Data tab to view the layer's features and attributes. 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
Use
field. You will use this field to style vector tiles in your application.Type
Create a new pen
- To get started, either complete the Display a map tutorial or .
Set the API key
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
api
to use your key.Key Use dark colors for code blocks Change line
Add a vector tile layer
Use the Vector
class from Esri Leaflet Vector to add data from the Santa Monica Mountains Parcels vector tile service to your application.
Create a
Vector
and set theTile Layer url
to the URL of the Santa Monica Mountains Parcels vector tile service. Add it to the map.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line.
Style parcels by use type
Use the MapLibre style specification to style land parcels according to their Use
category.
Since Leaflet does not support WebGL, Esri Leaflet Vector uses MapLibre GL JS internally to render vector tiles.
Add a
style
function to theVector
. This function allows you to modify the layer's MapLibre style object.Tile Layer Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add a custom
fill-color
to the layer. Useget
to retrieveUse
attribute values, viewed in the previous step. UseType case
to create a conditional expression that assigns a unique color to each use type.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Run the app. The vector tiles should appear with custom colors for residential, commercial, government, industrial, and institutional land parcels. All remaining parcels should be displayed in gray.
Add an outline layer
Add another style layer to the MapLibre style object to display parcel outlines.
Add a
line
layer to the list oflayers
in the style object. Set the source toesri
and thesource-layer
toSanta_
to reference the vector tile service.Monica_ Mountains_ Parcels Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Style the color, width, and opacity of the parcel outlines.
Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line.
Run the app
In CodePen, run your code to display the map.
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 ArcGIS location services in these tutorials: