How to use and filter data for MapTiler Countries
This tutorial shows how to use and filter data for MapTiler Countries dataset and make a choropleth map of the US states. MapTiler Countries is a dataset that primarily contains data about administrative divisions of a world based on countries and their territories.
Copy the following code, paste it into your favorite text editor, and save it as a
YOUR_MAPTILER_API_KEY_HEREwith your actual MapTiler API key.
The next it’s up to you. You can start the map in a different place by modifying the
starting zoom, and you can change the look of the map to any of our styles, or yours, by updating the
style URL. See what’s available here.
Add event handler for map
loadevent. You will add code to create a vector source and a vector layer in this handler.
Create vector source. The following snippet creates vector source for the MapTiler Countries dataset.
Get the id of the first symbol layer. We want to include the vector layer below the map labels. That means we need to know the id of the first symbol layer so we can include the vector layer before this layer.
Add the vector layer. We need to include
map.addLayerfunction to display the vector under the maps labels
Filter the data to only show the states of USA. Add a filter to the layer to only display level 1 items. The dataset now contains divisions and sub-subdivisions only for the US, if you need other country`s divisions, please contact us.
Create a choropleth map based on the name attribute. Change the
fill-colorproperty of the layer.
Check out the How to create a countries map with your own data tutorial.
Visit the MapTiler Countries schema to know how it is organized into different thematic layers and which attribute and values each layer contains.
Read the following How-tos related to choropleth maps:
- Get Started
- Learn the basics
- Display Marker
- GeoJSON Polygon Layer
- GeoJSON Line Layer
- GeoJSON Point Layer
- Raster Layer
- Custom Map
- 3D Map
- Choropleth GeoJSON
- Reverse Geocoding
- Geocoder component
- Countries filter
- Countries with data
- Elevation profile
- Center map by IP
- Disputed borders by IP
- Map language by IP
- Cookie consent by IP
- Scale control
- Style switcher
- Minimap control
- Legend control
- Choropleth Legend