Aggregation, Heatmaps, and Thematic Maps
🎯 Introduction
By the end of this article, you will be able to choose heatmaps, hexagonal bins, or grids based on data density and your visualization goals, and understand how a Mapbox basemap provides geographic context for thematic data.
🧱 Why aggregate?
Drawing many individual points causes overlap and makes spatial trends difficult to see. Aggregation combines points within a spatial area into statistics, then represents the results through color, elevation, or counts.
The Mapbox basemap supplies roads, administrative areas, and place names for orientation. deck.gl aggregation layers represent the density and intensity of application data.
🔥 HeatmapLayer
HeatmapLayer combines the influence of points into a continuous color surface, useful for population, traffic, temperature, or event density:
const layer = new HeatmapLayer({
id: 'traffic-heatmap',
data: points,
getPosition: (item) => item.position,
getWeight: (item) => item.count,
radiusPixels: 40,
weightsTextureSize: 512,
debounceTimeout: 250,
intensity: 1,
threshold: 0.05,
});
overlay.setProps({ layers: [layer] });
getWeight specifies each point's contribution to the aggregation, while radiusPixels controls its influence on screen. Larger radii produce smoother hotspots; smaller radii reveal more local variation.
weightsTextureSize limits the size of the heatmap's internal texture, while debounceTimeout batches recalculation after successive zoom changes. Larger textures provide more detail but require more GPU data processing during zooming.
The heatmap combines point weights into a continuous color surface over a Mapbox basemap:
⬡ HexagonLayer
HexagonLayer groups points into hexagonal bins. Color commonly represents counts, and elevation can represent a third dimension:
const layer = new HexagonLayer({
id: 'event-hexagons',
data: points,
getPosition: (item) => item.position,
getColorWeight: (item) => item.count,
getElevationWeight: (item) => item.count,
radius: 800,
elevationScale: 20,
extruded: true,
});
overlay.setProps({ layers: [layer] });
radius sets the spatial aggregation scale, typically in meters. The hexagon visualization aggregates points into hexagons and represents weights through color and elevation:
▦ GridLayer
GridLayer uses rectangular cells, making it useful alongside regular grids, raster statistics, or management units:
const layer = new GridLayer({
id: 'event-grid',
data: points,
getPosition: (item) => item.position,
getColorWeight: (item) => item.count,
cellSize: 800,
extruded: false,
});
overlay.setProps({ layers: [layer] });
cellSize is the side length of a grid cell and defines the spatial aggregation scale. getColorWeight specifies each point's weight in the color aggregation.
This grid visualization aggregates the same points into regular cells:
⚖️ Color, radius, and spatial scale
- Weight answers how much each point contributes, often based on a count, level, or event intensity.
- Color indicates the intensity range of an aggregated result and needs a consistent color scale.
- Radius determines the area within which points are grouped, controlling spatial detail.
- Elevation represents a third numeric dimension; check that perspective does not make it misleading.
Provide a legend for thematic maps and explain what color and elevation represent, so readers do not have to infer numeric meaning from color intensity alone.
🪤 Limits of aggregation
Aggregated results can change with the viewport and zoom level. An overly large radius can merge neighboring areas; an overly small one can remain hard to read. In production, adjust the aggregation scale for data density, map extent, and user tasks.
🧾 Summary
- Mapbox basemaps provide geographic context; deck.gl aggregation layers display thematic data.
- HeatmapLayer suits continuous hotspots, HexagonLayer suits hexagonal bins, and GridLayer suits rectangular cells.
- Weights determine contributions, radius determines spatial scale, and color and elevation represent results.
- Adjust aggregation scale for map extent and user tasks.
❓ Questions and answers
Q1: How do I choose between a heatmap and hexagonal bins?
Use a heatmap for continuous hotspot trends, and hexagonal bins to compare statistics across individual spatial units.
Q2: How do radiusPixels and radius differ?
A heatmap's radiusPixels uses screen pixels. A hexagon layer's radius uses geographic distance, commonly meters.
Q3: Can I still inspect the original points after aggregation?
Aggregation layers show statistics. For details, switch to a point layer when zoomed in, or load the area's original records when an aggregated object is clicked.
🧪 Exercises
- Change the hexagon radius from
800to400and observe the spatial detail and number of shapes. - Change
getColorWeightfromcountto another numeric field and observe how the thematic meaning changes.
🎉 You can now turn large point datasets into spatial thematic visualizations with geographic context.
