Asset Status Panel
Across a 600×400 m plant, 120 assets are colored by running, alarm and offline states; the view can be filtered to alarms or offline assets, with IDs pinned to the right of each point.
Business context
Asset status panels are a common form for operations duty screens and command displays. The users are on-call engineers, EHS staff and park managers who need to locate alarming and offline assets within tens of seconds. Data is merged from SCADA, MQTT gateways and the asset register; a single plant has hundreds to thousands of assets, and the 120 colored by three states here emphasize the status definition rather than scale.
The register provides metric local coordinates or positions relative to buildings, so alignment to the same origin as the building basemap, normalization of status codes into a finite enumeration and a stable ID per asset all happen before deck.gl; keeping coordinates within a few hundred meters avoids float jitter. Cesium needs a full geographic and temporal entity model and three.js needs custom text rendering, while TextLayer labels with pixel offsets involve far less work.
The classic misreading is to treat color as continuous: the three states are a discrete enumeration with no intermediate level. Status colors smear together on projectors or for color-vision-deficient viewers, so IDs and textual counts must carry the information. Point radius is also in meters, so points cover neighboring assets when zoomed in, and apparent coverage differs a lot between zoom levels without reflecting real footprint.
How it works
Assets sit on a 12-column by 10-row grid with 50 m column spacing and 40 m row spacing, each point jittered by ±6 m, which lands them within x ∈ [-281,281] and y ∈ [-186,186] for a 600×400 m site; state is cut from a single random number into 0–0.66 running, 0.66–0.87 alarm and 0.87–1 offline, and the script counts the three states once at startup and writes them into the bar. ScatterplotLayer uses getRadius of 7 m with radiusUnits: 'meters', so points grow with the site, and radiusMinPixels: 3 keeps them from disappearing; TextLayer fixes getSize at 11 with sizeUnits: 'pixels' so IDs keep the same size at any zoom, and getPixelOffset: [9,-9] is an offset in pixels from the anchor, combined with getTextAnchor: 'start' and getAlignmentBaseline: 'bottom' to place text at the upper right of each point.
Switching to 'alarm' or 'offline' filters once at the moment of the click; the resulting array is shared by both layers, layer ids stay stable and deck.gl reuses the existing GPU resources. Distinguishing three states by color alone fails on projectors and for color-vision-deficient users, so IDs are emitted together with status colors and the bar also shows counts for the three states. The getPixelOffset unit is screen pixels rather than meters: label spacing must not scale with the site, or text will overlap neighboring points when zoomed in.
| Setting | Effect |
|---|---|
| coordinateOrigin: [116.40, 39.92] | Geographic origin for metric offsets; determines which basemap area the assets land on |
| radiusUnits: 'meters' | Asset radius of 7 m, scaling with zoom |
| getPixelOffset: [9, -9] | Label displacement in screen pixels, unaffected by zoom |
| sizeUnits: 'pixels' | Font size fixed at 11 px so labels stay legible at any zoom |
Note. Status colors blur together on projectors; showing IDs alongside status colors lets color-vision-deficient users locate assets by label.
Source
<!--
示例:设备状态面板
要点:METER_OFFSETS 挂到 [116.40,39.92],120 台设备三态着色,TextLayer 用 getPixelOffset 把编号压到点的右上方
依赖: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:14px;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 input[type=range]{width:150px;accent-color:#4f9ef8}
.bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:4px;cursor:pointer;
border:1px solid #2f3947;background:#1d242e;color:#c9d3e0}
.bar button:hover{background:#26303d}
.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>设备 120</span>
<span style="color:#56d6a8">运行 <b id="n-run" style="color:inherit">0</b></span>
<span style="color:#f6ba4e">告警 <b id="n-warn" style="color:inherit">0</b></span>
<span style="color:#7e8898">离线 <b id="n-off" style="color:inherit">0</b></span>
<span class="sep"></span>
<button data-f="all" class="on">全部</button>
<button data-f="warn">告警</button>
<button data-f="off">离线</button>
<span class="sep"></span>
<span>600 × 400 m · 拖拽缩放</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 ORIGIN = [116.40, 39.92];
var rand = rng(8848);
var ST = [
{ color: [86, 214, 168] },
{ color: [246, 186, 78] },
{ color: [126, 136, 152] }
];
var devices = [];
var i, j;
for (i = 0; i < 120; i++) {
var col = i % 12;
var row = (i / 12) | 0;
var x = (col - 5.5) * 50 + (rand() - 0.5) * 12;
var y = (row - 4.5) * 40 + (rand() - 0.5) * 12;
var r = rand();
var s = r < 0.66 ? 0 : (r < 0.87 ? 1 : 2);
devices.push({
pos: [x, y, 0],
code: 'E-' + (i < 9 ? '0' : '') + (i + 1),
s: s
});
}
var counts = [0, 0, 0];
for (i = 0; i < devices.length; i++) counts[devices[i].s]++;
document.getElementById('n-run').textContent = counts[0];
document.getElementById('n-warn').textContent = counts[1];
document.getElementById('n-off').textContent = counts[2];
var filter = 'all';
var shown = devices;
function pick() {
if (filter === 'all') return devices;
var want = filter === 'warn' ? 1 : 2;
var out = [];
for (var k = 0; k < devices.length; k++) {
if (devices[k].s === want) out.push(devices[k]);
}
return out;
}
function buildLayers() {
return [
new deck.ScatterplotLayer({
id: 'asset-dots',
data: shown,
coordinateSystem: deck.COORDINATE_SYSTEM.METER_OFFSETS,
coordinateOrigin: ORIGIN,
getPosition: function (d) { return d.pos; },
getFillColor: function (d) { return ST[d.s].color; },
getRadius: 7,
radiusUnits: 'meters',
radiusMinPixels: 3,
radiusMaxPixels: 30,
stroked: true,
getLineColor: [13, 17, 23, 210],
getLineWidth: 1.5,
lineWidthUnits: 'pixels',
pickable: false,
transitions: { getRadius: 220 }
}),
new deck.TextLayer({
id: 'asset-labels',
data: shown,
coordinateSystem: deck.COORDINATE_SYSTEM.METER_OFFSETS,
coordinateOrigin: ORIGIN,
getPosition: function (d) { return d.pos; },
getText: function (d) { return d.code; },
getSize: 11,
sizeUnits: 'pixels',
getPixelOffset: [9, -9],
getTextAnchor: 'start',
getAlignmentBaseline: 'bottom',
getColor: function (d) {
var c = ST[d.s].color;
return [c[0], c[1], c[2], 235];
},
outlineWidth: 2,
outlineColor: [13, 17, 23, 230],
fontSettings: { sdf: true },
fontFamily: 'monospace',
pickable: false
})
];
}
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: {
longitude: ORIGIN[0],
latitude: ORIGIN[1],
zoom: 16.9,
pitch: 32,
bearing: -20
},
controller: true,
layers: buildLayers()
});
var btns = document.querySelectorAll('.bar button[data-f]');
for (i = 0; i < btns.length; i++) {
btns[i].addEventListener('click', function () {
filter = this.getAttribute('data-f');
for (j = 0; j < btns.length; j++) {
btns[j].className = btns[j] === this ? 'on' : '';
}
shown = pick();
deckgl.setProps({ layers: buildLayers() });
});
}
window.__deck = deckgl;
})();
</script>
</body>
</html>