Add interactivity to your map by showing a state's population count in a popup.
Prerequisites
- You need an ArcGIS Location Platform or ArcGIS Online account.
- You need to complete Step 6. Add vector tiles.
Steps
Add a click handler
-
Add a
click
event handler to the layerUSA
. This layer contains polygon features for U.S. states, each with_States _Population _polygons/39,538,223/1 STATE
and_NAME POPULATION
attributes.Use dark colors for code blocks map.on('click', 'USA_States_Population_polygons/39,538,223/1', (e) => { });
-
Inside the
click
event, create variables to store the state’s name and population. Format the population for readability.Use dark colors for code blocks map.on('click', 'USA_States_Population_polygons/39,538,223/1', (e) => { const name = e.features[0].properties.STATE_NAME; const population = new Intl.NumberFormat().format(e.features[0].properties.POPULATION); });
Add a popup
-
Inside the
click
event, create aPopup()
object. Set its position usingset
, define the content to show the state's name and population count, and add it to the map.Lng Lat Use dark colors for code blocks map.on('click', 'USA_States_Population_polygons/39,538,223/1', (e) => { const name = e.features[0].properties.STATE_NAME; const population = new Intl.NumberFormat().format(e.features[0].properties.POPULATION); new maplibregl.Popup() .setLngLat(e.lngLat) .setHTML(`<b>Name</b>: ${name} <br/><b>Population</b>: ${population}`) .addTo(map); });
Run the app
Run the app.
When you click on a state, a popup should appear with the state’s name and population.Congratulations!
You have completed the Create and style vector tiles how-to. The application displays styled vector tiles of U.S. states on a map. It allows you to click on a state and view a popup that shows the state's population.
What's next?

Style vector tiles
Change the fill and outline color of vector tiles based on their attributes on the client side.

Add a map tile layer
Add a map tile layer (raster) to a map.

Get global data
Query demographic information for locations around the world.
To explore additional ArcGIS capabilities, go to Tutorials.