In this recipe, we will create a choropleth map. In this type of map, the shaded areas represent the measurement of a variable—for example, population density, total population, or temperature. Higher values in the variable are represented by a denser color.
We will now create a choropleth map that shows the education level in the United States.
The condensed steps are as follows:
Generate a map with a base layer.
Generate a GeoJSON that contains the data we want to display, as well as a polygon of the area that the data represents.
Create a GeoJSON layer using
L.geoJson. Enumerate through the data, and for each feature, use
style(<GeoJSON> featureData)to style the polygon.
Let's perform these steps now:
Start by opening the
chapter-4-example11-choropleth-starterproject in your favorite text editor. There is already a configured base map, as in the previous recipes. Open the
We will import a
states.jsfile using the following line: