Taxi Supply-Demand Heatmap
90,000 order points and 24,000 idle-vehicle points are scattered across six Beijing hubs, and two hexagonal layers at identical radius overlay supply against demand; a button switches between the single-layer and overlay views.
Business context
Dispatch and regional operations teams at ride-hailing platforms use this view to judge whether hubs such as airports and rail stations have too few cars for the orders arriving, then decide whether to push incentive campaigns, open temporary staging areas or reposition stationed vehicles. The data comes from order transaction logs and idle-position reports from driver apps, deduplicated on hourly windows; a single city handles several hundred thousand orders per day, and one hub can accumulate tens of thousands of points at peak.
The raw points are WGS84 latitude and longitude. Before entering deck.gl they are reprojected to the plane coordinates of the basemap and aggregated onto a 1 km grid, so the browser receives only per-cell weight sums rather than hundreds of thousands of original points. HexagonLayer is chosen because orders and idle vehicles have to be compared as totals on the same bin grid; hexagons tile uniformly with no directional bias as on a square grid, and overlaid column heights can be read against each other directly.
The most common misreading is treating column height as a live supply-demand ratio. Both layers aggregate by SUM, so height only expresses an area total: many orders do not imply a large gap, and the reading is meaningless without the idle-vehicle layer at the same position. If bin radius, coverage or elevationRange differ between the layers, the hexagon edges misalign, the apparently overlapping area is really two separate grids, and the supply-demand conclusion shifts wholesale.
How it works
Each of the six hubs scatters points with a sqrt-random radius: 90,000 orders weighted 0.5–2 and 24,000 idle vehicles weighted a constant 1. The two HexagonLayers share radius 1000, coverage 0.9, elevationRange [0, 3200] and elevationScale 1.2; both aggregate color by SUM and differ only in colorRange, warm versus cool, so column heights and color steps at the same location are directly comparable.
The top-bar button swaps only the layers array; layer ids stay hex-orders and hex-vehicles and data references are not rebuilt. Color and height both use SUM rather than MEAN: MEAN averages per point first, so with different point counts the two layers' heights stop being comparable and the area total becomes unreadable. A common pitfall is giving the two layers different radius or elevationRange: the hexagon edges then misalign, visually overlapping supply-demand areas are misjudged, and heights no longer share a scale. The vehicle layer uses opacity 0.55 so the warm layer beneath shows through in overlay mode.
| Configuration | What it does |
|---|---|
| radius | 1000 m on both layers, keeping the hexagon grids aligned |
| colorAggregation | SUM accumulates weights to express area totals |
| elevationRange | Identical range on both layers so heights compare across layers |
| opacity | 0.55 on the vehicle layer so it does not hide orders when overlaid |
Note. When overlaying two layers, align radius, coverage and elevationRange first, then tune color and opacity; changing only the color band keeps both layers on one grid and makes supply and demand readable.
Source
<!--
示例:打车供需热力
要点:订单与空驶车两份点云用同半径 HexagonLayer 分箱,暖冷两条色带叠加比较
依赖:deck.gl 9.0 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>打车供需热力</title>
<style>
html,body{height:100%;margin:0;background:#0d1117}
body{display:flex;flex-direction:column;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#e6e8ec}
.bar{position:relative;z-index:5;flex:0 0 auto;padding:8px 12px;background:#161b22;border-bottom:1px solid #252c36;
display:flex;gap:10px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
.bar b{color:#58a6ff;font-weight:600}
.bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:5px;cursor:pointer;
border:1px solid #303845;background:#1d2531;color:#c8d2e0}
.bar button:hover{background:#253040}
.bar button.on{background:#2c4a7a;border-color:#4f8ad6;color:#dfe9ff}
.bar .sep{width:1px;height:18px;background:#2a313c;margin:0 4px}
#cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
<span>订单 <b id="no">—</b></span>
<span>空驶车 <b id="nv">—</b></span>
<span class="sep"></span>
<button data-mode="order">订单</button>
<button data-mode="vehicle">车辆</button>
<button data-mode="both" class="on">叠加</button>
<span class="sep"></span>
<span>半径 1 km · coverage 0.9 · elevationScale 1.2</span>
</div>
<canvas id="cv"></canvas>
<script src="https://cdn.jsdelivr.net/npm/deck.gl@9.0.35/dist.min.js"></script>
<script>
(function () {
'use strict';
if (typeof deck === 'undefined') {
document.body.innerHTML =
'<div style="padding:24px;color:#ff8c74">deck.gl 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
return;
}
var hubs = [
[116.390, 39.900, 0.20],
[116.470, 39.980, 0.16],
[116.300, 39.860, 0.14],
[116.520, 39.840, 0.12],
[116.350, 40.010, 0.11],
[116.440, 39.930, 0.18]
];
var orders = [];
var vehicles = [];
var i, h, r, a;
for (i = 0; i < 90000; i++) {
h = hubs[i % hubs.length];
r = Math.sqrt(Math.random()) * h[2];
a = Math.random() * Math.PI * 2;
orders.push({
lng: h[0] + Math.cos(a) * r,
lat: h[1] + Math.sin(a) * r * 0.85,
weight: 0.5 + Math.random() * 1.5
});
}
for (i = 0; i < 24000; i++) {
h = hubs[i % hubs.length];
r = Math.sqrt(Math.random()) * h[2] * 0.9;
a = Math.random() * Math.PI * 2;
vehicles.push({
lng: h[0] + Math.cos(a) * r,
lat: h[1] + Math.sin(a) * r * 0.85
});
}
document.getElementById('no').textContent = orders.length.toLocaleString();
document.getElementById('nv').textContent = vehicles.length.toLocaleString();
var warm = [
[60, 16, 10, 150],
[120, 36, 18, 175],
[178, 60, 26, 200],
[224, 96, 38, 220],
[248, 150, 66, 238],
[255, 206, 120, 250]
];
var cool = [
[10, 30, 70, 150],
[22, 62, 120, 175],
[36, 104, 172, 200],
[62, 152, 210, 220],
[110, 198, 232, 238],
[180, 236, 246, 250]
];
var mode = 'both';
function orderLayer() {
return new deck.HexagonLayer({
id: 'hex-orders',
data: orders,
getPosition: function (d) { return [d.lng, d.lat]; },
radius: 1000,
coverage: 0.9,
extruded: true,
elevationScale: 1.2,
elevationRange: [0, 3200],
getColorWeight: function (d) { return d.weight; },
colorAggregation: 'SUM',
getElevationWeight: function (d) { return d.weight; },
elevationAggregation: 'SUM',
colorRange: warm,
upperPercentile: 100,
material: { ambient: 0.5, diffuse: 0.7, shininess: 16 },
pickable: true
});
}
function vehicleLayer() {
return new deck.HexagonLayer({
id: 'hex-vehicles',
data: vehicles,
getPosition: function (d) { return [d.lng, d.lat]; },
radius: 1000,
coverage: 0.9,
extruded: true,
elevationScale: 1.2,
elevationRange: [0, 3200],
getColorWeight: function () { return 1; },
colorAggregation: 'SUM',
getElevationWeight: function () { return 1; },
elevationAggregation: 'SUM',
colorRange: cool,
upperPercentile: 100,
opacity: 0.55,
material: { ambient: 0.5, diffuse: 0.7, shininess: 16 },
pickable: true
});
}
function layers() {
if (mode === 'order') return [orderLayer()];
if (mode === 'vehicle') return [vehicleLayer()];
return [orderLayer(), vehicleLayer()];
}
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: {
longitude: 116.40,
latitude: 39.93,
zoom: 10.4,
pitch: 45,
bearing: -12,
maxPitch: 70
},
controller: true,
layers: layers(),
getTooltip: function (info) {
if (!info.object) return null;
var label = info.layer && info.layer.id === 'hex-orders' ? '订单权重和 ' : '空驶车数 ';
return info.object.count + ' 个点 · ' + label + Math.round(info.object.elevationValue);
}
});
var buttons = document.querySelectorAll('[data-mode]');
for (var b = 0; b < buttons.length; b++) {
buttons[b].addEventListener('click', function (e) {
mode = e.currentTarget.getAttribute('data-mode');
for (var k = 0; k < buttons.length; k++) {
buttons[k].classList.toggle('on', buttons[k] === e.currentTarget);
}
deckgl.setProps({ layers: layers() });
});
}
window.__deck = deckgl;
})();
</script>
</body>
</html>