Learn how to customize 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 Location Platform or ArcGIS Online account.
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 the portal. 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 your portal 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
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 that access ArcGIS Location Services and secure items.
- 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 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 so your application can access ArcGIS services.
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
Vectorand set theTile Layer urlto the URL of the Santa Monica Mountains Parcels vector tile service. Add it to the map.Use dark colors for code blocks L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken, pane: "tilePane" }).addTo(map); const parcelsUrl = "https://vectortileservices3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_Mountains_Parcels_VTL/VectorTileServer"; L.esri.Vector.vectorTileLayer( parcelsUrl, ).addTo(map); </script>
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
stylefunction to theVector.Tile Layer Use dark colors for code blocks L.esri.Vector.vectorTileLayer( parcelsUrl, { style: function (style) { return style; } } ).addTo(map); -
Add a custom
fill-colorto the new style 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 L.esri.Vector.vectorTileLayer( parcelsUrl, { style: function (style) { style.layers[0].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" ] }; return style; } } ).addTo(map); -
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
linelayer to the list oflayersin the style object. Set the source toesriand thesource-layertoSantato reference the vector tile service._Monica _Mountains _Parcels Use dark colors for code blocks { style: function (style) { style.layers[0].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" ] }; style.layers.push({ "id": "parcels-outline", "source": "Santa_Monica_Mountains_Parcels_VTL", "source-layer": "Santa_Monica_Mountains_Parcels", "type": "line", }); return style; } } -
Style the color, width, and opacity of the parcel outlines.
Use dark colors for code blocks style.layers.push({ "id": "parcels-outline", "source": "Santa_Monica_Mountains_Parcels_VTL", "source-layer": "Santa_Monica_Mountains_Parcels", "type": "line", "paint": { "line-color": "#000000", "line-width": 0.25, "line-opacity": 0.25 } });
Run the app
Run the app.
You should see the styled vector tile layer with parcels displayed on the basemap layer. Parcels should 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:


