Nationwide Station Status
3,000 stations around 30 cities recalculate 0–18% timeout rates every 1.5 seconds, with ScatterplotLayer transitions of 900 ms easing color and radius to the new values; a checkbox isolates abnormal stations.
Business context
Operations monitoring teams for a logistics network use a nationwide real-time board to watch timeout rates, parcel volume and abnormal stations, and the on-duty staff dispatch inspections, reroute parcels or notify customers from it. Data comes from each station's WMS fulfillment event stream and parcel status callbacks, refreshed at minute-level granularity; a national network usually has thousands of stations, and each refresh changes only a subset of their metrics.
Before deck.gl the station metrics are aligned by station ID, missing values filled, and ratio fields such as timeout rate clipped to a sane range so a single outlier does not skew the color scale; positions come from fixed coordinates in the station master data and need no recalculation. ScatterplotLayer is chosen because stations are discrete objects that must be picked individually for detail, and transition animation expresses continuous metric change more readably than full redraws.
The easiest thing to misread is a jump in color: if objects are recreated every round, transitions have no previous frame to interpolate from and the metric appears to leap. Timeout windows and refresh frequency also usually differ; a 1.5-second refresh does not mean a 1.5-second measurement window, and treating it as an instantaneous value overstates volatility.
How it works
3,000 stations are dealt round-robin across 30 cities, their coordinates built from three random offsets around each city center to approximate a normal spread, with volumes between 1 and 40 and timeout rates initialized randomly within 0–18%. ScatterplotLayer uses radiusUnits pixels with getRadius returning 2.5+sqrt(vol)*0.9 for roughly 3.4–8.2 pixels; getFillColor interpolates from teal through yellow to red by timeout/18, and transitions give both attributes 900 ms.
Every 1.5 seconds the timer changes only each station's timeout field and packs the same objects into a new array for the layer still under id warehouse-status; because the objects are not recreated, transitions can look up the previous frame's attributes by id and interpolate. Creating 3,000 fresh objects each round makes colors jump instead. The abnormal-only checkbox filters on timeout>10, which changes array length, so transitions apply only to stations that still exist.
| Configuration | What it does |
|---|---|
| transitions.getFillColor | 900 ms color transition, requires a layer with the same id |
| transitions.getRadius | 900 ms radius transition, smooth when volume changes |
| getRadius | 2.5+sqrt(vol)*0.9 maps volume to pixel radius |
| Abnormality threshold | timeout>10; the checkbox filters stations on this |
Note. For transitions to take effect, keep the layer id and station object references unchanged and pass a new array of the same objects; recreating objects wholesale loses the interpolation.
Source
<!--
示例:全国站点实时状态
要点:3000 个站点对象复用,每 1.5 秒改超时率,ScatterplotLayer 用 transitions 平滑变色变径
依赖: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:12px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
.bar b{color:#58a6ff;font-weight:600}
.bar label{display:flex;align-items:center;gap:5px;cursor:pointer}
.bar input[type=checkbox]{accent-color:#4f9ef8}
.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="bad">—</b></span>
<span>总站点 <b>3000</b></span>
<span class="sep"></span>
<label><input id="only" type="checkbox"> 只看异常(>10%)</label>
<span class="sep"></span>
<span>每 1.5 s 刷新超时率 · transitions 900 ms</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 cities = [
[116.41, 39.90, '北京'], [121.47, 31.23, '上海'], [113.26, 23.13, '广州'],
[114.06, 22.54, '深圳'], [120.15, 30.27, '杭州'], [118.80, 32.06, '南京'],
[114.31, 30.59, '武汉'], [104.07, 30.67, '成都'], [106.55, 29.56, '重庆'],
[108.94, 34.34, '西安'], [117.20, 39.13, '天津'], [123.43, 41.80, '沈阳'],
[126.64, 45.76, '哈尔滨'], [125.32, 43.90, '长春'], [117.12, 36.65, '济南'],
[113.62, 34.75, '郑州'], [112.94, 28.23, '长沙'], [117.23, 31.82, '合肥'],
[119.30, 26.08, '福州'], [115.89, 28.68, '南昌'], [102.83, 24.88, '昆明'],
[106.63, 26.65, '贵阳'], [103.83, 36.06, '兰州'], [112.55, 37.87, '太原'],
[114.51, 38.04, '石家庄'], [111.75, 40.84, '呼和浩特'], [87.62, 43.82, '乌鲁木齐'],
[101.78, 36.62, '西宁'], [106.23, 38.49, '银川'], [108.37, 22.82, '南宁']
];
function jitter() {
return (Math.random() + Math.random() + Math.random() - 1.5) * 0.16;
}
var stations = [];
for (var i = 0; i < 3000; i++) {
var c = cities[i % cities.length];
stations.push({
id: i,
lng: c[0] + jitter(),
lat: c[1] + jitter(),
city: c[2],
vol: 1 + Math.floor(Math.random() * 40),
timeout: Math.random() * 18
});
}
var onlyBad = false;
function fillColor(d) {
var t = d.timeout / 18;
if (t < 0.55) {
var k = t / 0.55;
return [
Math.round(50 + 170 * k),
Math.round(185 - 60 * k),
Math.round(150 - 60 * k),
210
];
}
var k2 = (t - 0.55) / 0.45;
return [
Math.round(220 + 30 * k2),
Math.round(125 - 90 * k2),
Math.round(90 - 50 * k2),
230
];
}
function visible() {
if (!onlyBad) return stations.slice();
var out = [];
for (var k = 0; k < stations.length; k++) {
if (stations[k].timeout > 10) out.push(stations[k]);
}
return out;
}
function buildLayer() {
return new deck.ScatterplotLayer({
id: 'warehouse-status',
data: visible(),
getPosition: function (d) { return [d.lng, d.lat]; },
getRadius: function (d) { return 2.5 + Math.sqrt(d.vol) * 0.9; },
radiusUnits: 'pixels',
radiusMinPixels: 2,
getFillColor: fillColor,
transitions: {
getFillColor: 900,
getRadius: 900
},
pickable: true
});
}
function updateBadge() {
var bad = 0;
for (var k = 0; k < stations.length; k++) {
if (stations[k].timeout > 10) bad++;
}
document.getElementById('bad').textContent = bad;
}
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: {
longitude: 104,
latitude: 35,
zoom: 4,
pitch: 0,
bearing: 0
},
controller: true,
layers: [buildLayer()],
getTooltip: function (info) {
if (!info.object) return null;
return info.object.city + ' · 件量 ' + info.object.vol +
' · 超时率 ' + info.object.timeout.toFixed(1) + '%';
}
});
document.getElementById('only').addEventListener('change', function (e) {
onlyBad = e.currentTarget.checked;
deckgl.setProps({ layers: [buildLayer()] });
});
updateBadge();
setInterval(function () {
for (var k = 0; k < stations.length; k++) {
stations[k].timeout = Math.random() * 18;
}
updateBadge();
deckgl.setProps({ layers: [buildLayer()] });
}, 1500);
window.__deck = deckgl;
})();
</script>
</body>
</html>