Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / Pipeline Aging Inspection
deck.gl · Business scenario

Pipeline Aging Inspection

80 pipelines coloured end to end from green to red by age, 260 inspection points on the lines, and a checkbox that shows only the segments older than 20 years.

Open standalone → Chinese notes All business examples
/demos/deckgl-biz-grid-inspection.htmlLIVE
single HTML file · CDN dependencies onlyinterface labels are in Chinese

Business context

Maintenance crews for gas, heating and municipal pipeline networks use age-coloured maps to sequence replacements, identify segments entering a high-risk period, and justify refurbishment budgets to management. Data comes from the pipeline GIS — material, installation year, diameter — plus inspection check-in records. A mid-sized city has tens of thousands of kilometres of trunk mains and up to 100,000 features once split into segments; this example uses 80 pipelines and 260 inspection points.

Age is computed from material and installation year, and segments with missing years are flagged rather than defaulted to zero. PathLayer getColor returns one value per path, so each pipeline is a single colour and cannot change shade at a threshold within one pipe. Where segmentation is genuinely required, the polyline must be split into sub-paths at the threshold; inspection points take the colour of their segment, and width uses pixels to stay visible at any zoom.

Age and remaining life are easily conflated: a 35-year cast iron main and a 35-year ductile iron main carry different risk, so year alone misleads. Colouring inspection points by pipeline age rather than defect grade implies that having been inspected means safe. After filtering to over-age segments the toolbar still reports the full count, which reads as a broken filter when only the statistic is unsynchronised.

How it works

Each of the 80 pipelines takes 6–14 vertices from a seeded random generator, with age sampled uniformly between 0 and 35 years. PathLayer getColor interpolates by age through green [56,168,122], yellow [232,196,78] and red [234,82,62], while getWidth is fixed at 3 with widthUnits set to pixels, so width does not follow map scale. Each of the 260 inspection points picks a random pipeline and then a random segment for linear interpolation; its colour splits by whether the age exceeds 20 years into yellow [255,214,102] and blue [118,202,255], with a radius of 3.4 px.

The whole pipeline carries one colour because PathLayer data is per path and getColor and getWidth each return a single value; breaking colour at a 20-year threshold within one pipeline requires splitting the polyline into sub-paths at the break point, which duplicates vertices and degrades picking and tooltips from one pipeline into multiple fragments. When the over-age checkbox is on, pipelines and inspection points are filtered by the same condition, while the toolbar keeps the full count of over-age segments so it is clear how many were filtered out.

ConfigurationWhat it does
widthUnits: 'pixels'Fixed 3 px width, unaffected by metre scale when zooming
getColor / getWidthPathLayer takes one value per path and cannot shade along a path
ageColor0–35 years mapped across green, yellow and red, with yellow at 0.57
getRadius: 3.4 + radiusUnits: 'pixels'Fixed screen size for inspection points so they do not vanish when zoomed out

Note. To shade by threshold, split the polyline at the threshold and colour the parts separately; a single PathLayer getColor does not interpolate along one path.

Source

demos/deckgl-biz-grid-inspection.html
<!--
  示例:管线老化巡检
  要点:PathLayer 按管龄给整条管线着色,勾选框同时筛掉未超龄管线与巡检点
  依赖: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 input[type=range]{width:140px;accent-color:#4f9ef8}
  .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="n">—</b> 条 · 超龄 <b id="over">—</b> 段</span>
  <span class="sep"></span>
  <label><input type="checkbox" id="only"> 仅显示超龄(&gt;20 年)</label>
  <span>0 年绿 → 35 年红</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;
    };
  }

  // 0 年绿 → 20 年黄 → 35 年红
  function ageColor(age) {
    var t = age / 35;
    var c0, c1, f;
    if (t < 0.57) {
      c0 = [56, 168, 122]; c1 = [232, 196, 78]; f = t / 0.57;
    } else {
      c0 = [232, 196, 78]; c1 = [234, 82, 62]; f = (t - 0.57) / 0.43;
    }
    return [
      Math.round(c0[0] + (c1[0] - c0[0]) * f),
      Math.round(c0[1] + (c1[1] - c0[1]) * f),
      Math.round(c0[2] + (c1[2] - c0[2]) * f),
      232
    ];
  }

  var rand = rng(20261124);
  var pipes = [];
  var i, j;
  for (i = 0; i < 80; i++) {
    var cx = 116.40 + (rand() - 0.5) * 0.94;
    var cy = 39.92 + (rand() - 0.5) * 0.56;
    var head = rand() * Math.PI * 2;
    var nodes = 6 + Math.floor(rand() * 9);
    var step = 0.008 + rand() * 0.012;
    var path = [];
    for (j = 0; j < nodes; j++) {
      path.push([cx, cy]);
      head += (rand() - 0.5) * 0.8;
      cx += Math.cos(head) * step;
      cy += Math.sin(head) * step * 0.78;
    }
    var age = rand() * 35;
    pipes.push({ path: path, age: age, color: ageColor(age) });
  }

  var overCount = 0;
  for (i = 0; i < pipes.length; i++) {
    if (pipes[i].age > 20) overCount++;
  }

  var marks = [];
  for (i = 0; i < 260; i++) {
    var p = pipes[Math.floor(rand() * pipes.length)];
    var s = Math.floor(rand() * (p.path.length - 1));
    var f = rand();
    var a = p.path[s];
    var b = p.path[s + 1];
    marks.push({
      pos: [a[0] + (b[0] - a[0]) * f, a[1] + (b[1] - a[1]) * f],
      age: p.age,
      color: p.age > 20 ? [255, 214, 102, 235] : [118, 202, 255, 220]
    });
  }

  document.getElementById('n').textContent = pipes.length;
  document.getElementById('over').textContent = overCount;

  var onlyOver = false;
  var shownPipes = pipes;
  var shownMarks = marks;

  function filterData() {
    if (!onlyOver) {
      shownPipes = pipes;
      shownMarks = marks;
      return;
    }
    shownPipes = [];
    shownMarks = [];
    var k;
    for (k = 0; k < pipes.length; k++) {
      if (pipes[k].age > 20) shownPipes.push(pipes[k]);
    }
    for (k = 0; k < marks.length; k++) {
      if (marks[k].age > 20) shownMarks.push(marks[k]);
    }
  }

  function buildLayers() {
    return [
      new deck.PathLayer({
        id: 'grid-pipe',
        data: shownPipes,
        getPath: function (d) { return d.path; },
        getColor: function (d) { return d.color; },
        getWidth: 3,
        widthUnits: 'pixels',
        widthMinPixels: 1.4,
        capRounded: true,
        jointRounded: true,
        pickable: true
      }),
      new deck.ScatterplotLayer({
        id: 'grid-inspect',
        data: shownMarks,
        getPosition: function (d) { return d.pos; },
        getRadius: 3.4,
        radiusUnits: 'pixels',
        radiusMinPixels: 2,
        getFillColor: function (d) { return d.color; },
        stroked: true,
        getLineColor: [13, 17, 23, 210],
        lineWidthUnits: 'pixels',
        getLineWidth: 1.2,
        pickable: true
      })
    ];
  }

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    initialViewState: { longitude: 116.40, latitude: 39.92, zoom: 10.4, pitch: 0, bearing: 0 },
    controller: true,
    layers: buildLayers(),
    getTooltip: function (info) {
      if (!info.object || !info.layer) return null;
      return info.layer.id === 'grid-pipe'
        ? '管龄 ' + info.object.age.toFixed(1) + ' 年'
        : '巡检点 · 所在管线 ' + info.object.age.toFixed(1) + ' 年';
    }
  });

  document.getElementById('only').addEventListener('change', function (e) {
    onlyOver = e.target.checked;
    filterData();
    deckgl.setProps({ layers: buildLayers() });
  });

  window.__deck = deckgl;
})();
</script>
</body>
</html>
Language: this page is in English; the demo keeps Chinese interface labels and code comments. The Chinese page carries the full notes and the same runnable file.

More business examples

deck.gl · APIPathLayer deck.gl · APIScatterplotLayer