Fatal car crashes in 2017 represented as a continuous heatmap. Areas with higher concentrations of crashes are yellow.
What is a heatmap?
A Heatmap renders point features as a raster surface, emphasizing areas with a higher density of points along a continuous color ramp.
Why are heatmaps useful?
Heatmaps can be used as an alternative to clustering, opacity, and bloom to visualize overlapping point features. Unlike these alternative techniques for visualizing density, you can use a heatmap to weight the density of points based on a data value. This may reveal a different pattern than density calculated using location alone.
Location-only heatmap
Data-weighted heatmap
Density of car crashes that resulted in a fatality (2017). Yellow areas indicate the highest density of crash incidents.
Density of fatal car crashes involving drunk drivers (2017). Yellow areas indicate the highest density of crash incidents that involved drunk drivers.
How a heatmap works
Heatmaps are created by setting a HeatmapRenderer instance to the renderer property of the layer. The HeatmapRenderer has several key properties. The blurRadius determines the area of influence surrounding a point. For example, if you set a blur radius of 10 pixels, each pixel within 10 pixels of a single point will be assigned an intensity value of 1. Pixels on the screen that fall outside that 10-pixel blur radius will have an intensity value of 0.
The intensity value of each pixel accumulates based on its proximity to multiple points. For example, a pixel within 10px of only a single point, will have a pixel intensity value of 1. A pixel within 10px of 10 points, will have a pixel intensity value of 10.
The colorStops in the renderer determine how to colorize pixels based on their pixel ratio (i.e. pixelIntensity / maxPixelIntensity). Pixels with an intensity value at or above the maxPixelIntensity have a pixel ratio of 1 and should be assigned the brightest color since these represent the hottest areas. The larger the maxPixelIntensity, the fewer hot spots will exist in the map.
Examples
Location heatmap
To create a heatmap, you must apply a HeatmapRenderer to a point layer. Set the renderer properties using the guidelines outlined above. Open this example in CodePen and adjust the blurRadius and maxPixelIntensity to see how these properties impact the heatmap.
Density of car crashes that resulted in a fatality (2017). Yellow areas indicate the highest density of crash incidents.
This example modifies the previous heatmap to weight the surface by a data variable. The crashes layer used in this example has an attribute that tallies the number of drunk drivers involved in the incident. We can visualize where more drunk drivers are involved in fatal accidents by weighting by that field.
When a field is specified, each pixel's pixelIntensity is multiplied by the data value, so you need to adjust the maxPixelIntensity accordingly.
Density of car crashes involving drunk drivers that resulted in a fatality (2017). Yellow areas indicate the highest density of crash incidents.
Heatmaps are only visually appropriate at a few scale levels. As the user zooms out, the heatmap will always appear hotter. As the user zooms in, the heatmap will appear colder. To prevent the user from viewing a heatmap that is too hot, you should set a minScale on the layer or as a view constraint.
As the user zooms in, the heatmap becomes irrelevant. Therefore, you should set a watch on the view to toggle the layer's heatmap to a simple renderer representing individual point locations.
Density of crimes classified as "fraud" in San Diego California. Zoom in and out on the map to view how the developer can restrict the user from seeing a heatmap that is too hot or too cold. As the user zooms in, the heatmap toggles off and displays the point locations as a simple renderer.
Set a constraint on map view scale to avoid hot heatmaps