Transmission Lines Coloured by Voltage
70 transmission lines use 12, 7 and 4 metre widths for 500, 220 and 110 kV, and buttons switch between voltage colouring and load-rate colouring.
Business context
Grid dispatch, maintenance and planning departments use it to read the voltage hierarchy of transmission corridors, line loading and geographic routing, supporting outage plans and new route siting. Data comes from the line ledger in PMS and dispatch systems — terminal substations, voltage class, conductor type, load-rate curves — plus GIS polylines. A provincial grid has thousands of lines; this example uses 70, each with 20 to 60 vertices.
Polylines are reprojected and topologically cleaned before rendering, removing dangles and duplicate vertices. Voltage class maps to metre-based width so the stroke matches the real corridor, and widthMinPixels keeps lines from disappearing at regional scale. Load-rate colouring reads daily average or real-time values from the ledger; both colour modes share the same geometry, so switching only swaps getColor and never re-uploads vertices.
Misreading comes from treating stroke width at small scale as capacity: at zoom 8 both 500 kV and 110 kV are compressed near widthMinPixels, colour becomes the only differentiator, and viewers assume equal class. Load rate also needs a stated basis, instantaneous versus daily peak; daily averages flatten peak-hour risk. Double-circuit lines on one tower appear as a single line, so circuit counts cannot be read from visible line count.
How it works
The 70 lines start from 8 substations: the first 14 are 500 kV, the next 24 are 220 kV and the remaining 32 are 110 kV, each with 20–60 random vertices, a heading jitter of ±0.09 radians per step, and lengths falling in 0.55–0.95, 0.35–0.60 and 0.18–0.35 degrees respectively. PathLayer getWidth returns 12/7/4 by voltage and widthUnits is meters, so width is the physical corridor rather than screen pixels; at zoom 8, 12 metres is about 0.05 pixels, which only widthMinPixels 1.5 makes visible, and at that scale the three classes are distinguished by colour. Above zoom 15, 500 kV reaches 6.5 pixels, 220 kV 3.8 and 110 kV 2.2, and the width difference finally opens up.
Switching to load rate makes getColor read a precomputed load value, with 0.30–0.50 green, 0.50–0.70 yellow, 0.70–0.85 orange and above 0.85 red; the toolbar legend switches to the same four thresholds while width stays keyed to voltage. Writing width as widthUnits pixels makes 500 kV and 110 kV look identical at every zoom and loses the voltage information, while writing metres without widthMinPixels breaks the lines apart at regional scale. The tooltip reports both kV and load percentage so the two colour modes can be checked against the same set of lines.
| Configuration | What it does |
|---|---|
| widthUnits meters | Width matches the real corridor and changes naturally with zoom |
| getWidth 12/7/4 | Physical width for 500, 220 and 110 kV |
| widthMinPixels 1.5 | Minimum visibility at regional zoom so lines never vanish |
| getColor dual mode | Three colours by voltage, or four threshold bands by load rate |
Note. Capture line widths at zoom 8, then compare at zoom 15: the 500 kV line grows from the 1.5 px floor to about 6.5 px, which shows what metre-based width means.
Source
<!--
示例:电网管线按电压着色
要点:PathLayer 用米制线宽表达电压等级,widthMinPixels 兜住区域级缩放,配色可切到负载率
依赖: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}
.lg{display:flex;align-items:center;gap:8px;white-space:nowrap}
.lg .sw{width:12px;height:3px;border-radius:2px;display:inline-block;margin-right:2px}
#cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
<span>线路 <b>70</b> 条</span>
<span class="sep"></span>
<button data-mode="voltage" class="on">按电压</button>
<button data-mode="load">按负载率</button>
<span class="sep"></span>
<span class="lg" id="lgv">
<span><span class="sw" style="background:#f06848"></span>500 kV · 12 m</span>
<span><span class="sw" style="background:#f6ba4e"></span>220 kV · 7 m</span>
<span><span class="sw" style="background:#40cee2"></span>110 kV · 4 m</span>
</span>
<span class="lg" id="lgl" style="display:none">
<span><span class="sw" style="background:#56d6a8"></span><50%</span>
<span><span class="sw" style="background:#f6dc60"></span>50–70%</span>
<span><span class="sw" style="background:#f69e46"></span>70–85%</span>
<span><span class="sw" style="background:#f06048"></span>>85%</span>
</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(881122);
var subs = [
[114.75, 39.00], [116.10, 38.75], [117.60, 39.20], [118.05, 40.20],
[116.40, 39.90], [115.05, 40.60], [117.20, 40.95], [115.60, 39.65]
];
var lines = [];
for (var i = 0; i < 70; i++) {
var v = i < 14 ? 500 : (i < 38 ? 220 : 110);
var n = 20 + Math.floor(rand() * 41);
var sub = subs[i % subs.length];
var ang = rand() * Math.PI * 2;
var len = v === 500 ? 0.55 + rand() * 0.40
: v === 220 ? 0.35 + rand() * 0.25
: 0.18 + rand() * 0.17;
var path = [];
var lng = sub[0];
var lat = sub[1];
for (var s = 0; s < n; s++) {
path.push([lng, lat]);
ang += (rand() - 0.5) * 0.18;
lng += Math.cos(ang) * len / n;
lat += Math.sin(ang) * len / n * 0.85;
}
lines.push({ path: path, v: v, load: 0.30 + rand() * 0.72 });
}
function voltWidth(v) {
if (v === 500) return 12;
if (v === 220) return 7;
return 4;
}
function voltColor(v) {
if (v === 500) return [240, 104, 72, 235];
if (v === 220) return [246, 186, 78, 235];
return [64, 206, 226, 235];
}
function loadColor(x) {
if (x < 0.50) return [86, 214, 168, 235];
if (x < 0.70) return [246, 220, 96, 235];
if (x < 0.85) return [246, 158, 70, 235];
return [240, 96, 72, 240];
}
var mode = 'voltage';
function buildLines() {
return new deck.PathLayer({
id: 'grid-lines',
data: lines,
getPath: function (d) { return d.path; },
getColor: function (d) {
return mode === 'voltage' ? voltColor(d.v) : loadColor(d.load);
},
getWidth: function (d) { return voltWidth(d.v); },
widthUnits: 'meters',
widthMinPixels: 1.5,
jointRounded: true,
capRounded: true,
pickable: true
});
}
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: {
longitude: 116.40,
latitude: 39.90,
zoom: 8,
pitch: 0,
bearing: 0
},
controller: true,
layers: [buildLines()],
getTooltip: function (info) {
if (!info.object) return null;
return info.object.v + ' kV · 负载 ' +
Math.round(info.object.load * 100) + '%';
}
});
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);
}
document.getElementById('lgv').style.display = mode === 'voltage' ? 'flex' : 'none';
document.getElementById('lgl').style.display = mode === 'load' ? 'flex' : 'none';
deckgl.setProps({ layers: [buildLines()] });
});
}
window.__deck = deckgl;
})();
</script>
</body>
</html>