Book Image

Leaflet.js Essentials

Book Image

Leaflet.js Essentials

Overview of this book

Table of Contents (13 chapters)
Leaflet.js Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a choropleth map with Leaflet


In the previous examples, you used heatmaps to color code a map based on the density or intensity of points. A choropleth map also measures the intensity or density of a statistical variable but within polygons. A popular choropleth map is the population density by county. Choropleth maps do not require any plugins, as was the case with the heatmap examples. A choropleth map is usually created by styling GeoJSON based on a property.

The GeoJSON data

When adding a large amount of GeoJSON data to a map, it is easier to place the code in a separate JavaScript file. This clears your HTML file of hundreds of lines of code, which makes it hard to focus on building the map. When you place the GeoJSON code in a JavaScript file, you will declare it as a variable, as shown in the following code:

var ct = {"type": "FeatureCollection", "features": [{"geometry": {"type": "Polygon", "coordinates": [[[-106.501132, 35.093911], [-106.501231, 35.09385], [-106.501481, 35...