Work Order Spatiotemporal Density
140,000 work orders with hourly timestamps rendered as a kernel density surface; dragging the start and end sliders cuts a time window, and voids and hotspots redistribute immediately.
Business context
City management command centres and 12345 hotline teams are the primary users. They need to see how complaints and cases migrate within a day in order to schedule patrol shifts and district staffing. The source is the work order event table: acceptance time, closure time, request category and reported coordinates, at 100,000 to 300,000 records per month for a mid-sized city. Coordinates come from phone positioning or manual grid-worker entry, accurate to tens or hundreds of metres, so on the map they are stacked points rather than exact addresses.
Orders are bucketed by hour, coordinates normalised to WGS84 and points outside the jurisdiction dropped. At the 140,000-point scale the question is a continuous distribution rather than discrete positions; per-point scatter collapses into a single smear, so HeatmapLayer computes screen-space kernel density instead of a pre-aggregated grid. A slider change rebuilds the array on the CPU and passes only in-window points to the layer, so out-of-window points do not enter the kernel normalisation and dilute the colours; incremental updates swap the data reference while the layer id stays stable.
The most common misreading is treating kernel density as an absolute count. Hotspot brightness depends on radiusPixels and intensity, and the kernel radius is fixed in pixels, so the visual hotspot size does not change with zoom and is easily mistaken for a fixed incident footprint. The second is the time window definition: filtering by acceptance time rather than closure time shifts hotspots by several districts. threshold also clips low-density pixels, so an apparently empty area may simply be a thin sample rather than a governance improvement.
How it works
Orders are generated around six districts with radii of 0.022–0.032 degrees, and hours are sampled at 6% in the early morning, 22% in the morning, 30% in the afternoon, 32% in the evening and 10% at night, so 06:00–11:00 and 18:00–21:00 both rise. HeatmapLayer is configured only with getPosition and getWeight 1, and radiusPixels is fixed at 26, so the kernel radius does not change with zoom and a hotspot is about 52 pixels across. threshold 0.06 makes pixels below that density transparent, intensity 1.4 pushes mid values toward the top colour, and colorRange runs through six bands from deep blue to orange-red.
Filtering runs on the CPU: every slider change walks the 140,000 records and rebuilds the array, passing only in-window points to the layer. Setting the weight of out-of-window points to 0 instead leaves the kernel normalised against the full count, dilutes hotspot colour and leaves a translucent halo at the boundary. Narrowing the window to two hours shows the kernel breaking into isolated patches, which is what threshold cuts out of a thin sample; widening it to 18:00–21:00 lets intensity 1.4 merge several districts into one saturated mass, at which point intensity has to come down before internal structure is readable.
| Configuration | What it does |
|---|---|
| radiusPixels 26 | Kernel radius fixed in screen pixels; hotspot size stays constant when zooming |
| intensity 1.4 | Density multiplier; higher values reach the saturated end of colorRange sooner |
| threshold 0.06 | Pixels below this density are transparent and set where voids begin |
| Dual-slider filter | Trim data before upload so weights are not normalised against the full set |
Note. Raise threshold from 0.06 to 0.12, then narrow to a three-hour window, to see how hotspots break into isolated kernels when the sample is thin.
Source
<!--
示例:工单时空密度
要点:HeatmapLayer 按小时筛选后重算核密度,threshold 抬高露出低密度空洞,intensity 放大高密度饱和
依赖: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 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}
.bar input[type=range]{width:140px;accent-color:#4f9ef8}
#cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
<span>筛选 <b id="n">—</b> 条</span>
<span class="sep"></span>
<span>起始 <b id="h0v">0</b> 时</span>
<input id="h0" type="range" min="0" max="23" step="1" value="0">
<span>结束 <b id="h1v">23</b> 时</span>
<input id="h1" type="range" min="0" max="23" step="1" value="23">
<span class="sep"></span>
<span>radius 26 px · intensity 1.4 · threshold 0.06</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;
}
function rng(seed) {
var a = seed >>> 0;
return function () {
a = (a + 0x6D2B79F5) >>> 0;
var t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
var rand = rng(20261124);
// 六个投诉高发片区:中心、半径(度)
var hubs = [
[116.336, 39.908, 0.032],
[116.452, 39.952, 0.026],
[116.300, 39.958, 0.022],
[116.508, 39.898, 0.030],
[116.392, 40.012, 0.024],
[116.466, 39.840, 0.028]
];
// 工单时刻分布:凌晨少、上午与傍晚双峰
function pickHour() {
var x = rand() * 100;
if (x < 6) return Math.floor(rand() * 6);
if (x < 28) return 6 + Math.floor(rand() * 6);
if (x < 58) return 12 + Math.floor(rand() * 6);
if (x < 90) return 18 + Math.floor(rand() * 4);
return 22 + Math.floor(rand() * 2);
}
var points = [];
for (var i = 0; i < 140000; i++) {
var h = hubs[i % hubs.length];
var rad = Math.sqrt(rand()) * h[2];
var ang = rand() * Math.PI * 2;
points.push({
lng: h[0] + Math.cos(ang) * rad,
lat: h[1] + Math.sin(ang) * rad * 0.8,
hour: pickHour()
});
}
var colorRange = [
[18, 32, 66, 170],
[36, 88, 148, 195],
[52, 152, 176, 210],
[150, 205, 130, 220],
[244, 200, 84, 235],
[235, 104, 52, 250]
];
var nLabel = document.getElementById('n');
var h0 = document.getElementById('h0');
var h1 = document.getElementById('h1');
var h0v = document.getElementById('h0v');
var h1v = document.getElementById('h1v');
function buildHeat(data) {
return new deck.HeatmapLayer({
id: 'workorder-heat',
data: data,
getPosition: function (d) { return [d.lng, d.lat]; },
getWeight: function () { return 1; },
radiusPixels: 26,
intensity: 1.4,
threshold: 0.06,
colorRange: colorRange
});
}
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: {
longitude: 116.40,
latitude: 39.93,
zoom: 10.4,
pitch: 0,
bearing: 0
},
controller: true,
layers: [buildHeat(points)]
});
nLabel.textContent = points.length.toLocaleString();
// 按小时区间过滤:先把数据裁到区间内再交给 GPU,而不是给每个点算权重
function applyRange(changed) {
var a = Number(h0.value);
var b = Number(h1.value);
if (a > b) {
if (changed === 'start') {
b = a;
h1.value = String(a);
} else {
a = b;
h0.value = String(b);
}
}
h0v.textContent = a;
h1v.textContent = b;
var out = [];
for (var i = 0; i < points.length; i++) {
if (points[i].hour >= a && points[i].hour <= b) out.push(points[i]);
}
nLabel.textContent = out.length.toLocaleString();
deckgl.setProps({ layers: [buildHeat(out)] });
}
h0.addEventListener('input', function () { applyRange('start'); });
h1.addEventListener('input', function () { applyRange('end'); });
window.__deck = deckgl;
})();
</script>
</body>
</html>