Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / Timeout Station Alerts
deck.gl · Business scenario

Timeout Station Alerts

5,000 stations are mapped as timeout rate on a screen grid; dragging a threshold slider leaves only alert points, whose rings pulse on a 1.6-second cycle.

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

Business context

Fulfillment quality and customer service teams use an alert view to lock onto areas where timeouts concentrate, prioritize which hubs or routes to investigate, and issue remediation requests to regional owners. Data comes from parcel fulfillment timestamps and station reports, aggregated into station-level timeout rates by hour or by batch; with thousands of stations nationwide, peak hours generate a large backlog of alerts that aggregation and thresholds must reduce.

Timeout rates are computed on one definition and banded first, and only stations valid in the current window are kept before entering deck.gl; positions come from station master data. ScreenGridLayer forms the density base because it aggregates in screen space, so cell edge length stays fixed and density perception is stable under zoom; alert points that need individual picking and pulse cues are layered on with ScatterplotLayer.

Screen grid density changes with zoom: the same stations spread over more cells when magnified and look sparser, which is a change in aggregation grain, not in the data. Another trap is that the threshold filters display only, not statistics; fewer alert points on screen does not mean fewer alerts in total, so reporting must separate the display definition from the statistical one.

How it works

5,000 stations jitter around six hubs in polar coordinates with radius Math.sqrt(rand)*0.062 and timeout rate Math.pow(rand,1.5)*25, dense at low values and sparse at high ones, close to a real fulfillment distribution. The base ScreenGridLayer fixes cellSizePixels at 24, getWeight returns the raw timeout rate, colorDomain is [0,120] and colorRange runs five steps from deep blue to orange-red; zooming changes cell count while cell edge length stays fixed.

Dragging the threshold rebuilds the alert array once; every other frame goes through requestAnimationFrame, calling setProps with a new layer instance while data keeps the same array reference and only updateTriggers.getRadius changes to a new phase, swinging radius between 5 and 13 px on a 1.6-second sine. Filtering into a new array each frame would retransmit the position and color attributes wholesale and rebuild the picking index, making hover flicker.

ConfigurationWhat it does
cellSizePixels: 24Screen cells fixed at 24 px; wheel zoom does not change aggregation
getWeight + colorDomain [0,120]Raw timeout rates summed per cell on a fixed domain so color does not drift with filtering
updateTriggers.getRadiusOnly radius recomputes per frame; position and color stay untouched
radiusUnits: 'pixels'Pulse rings stay 5–13 px at any zoom level

Note. When a per-frame animation changes only radius, put the phase in updateTriggers and keep data on the same reference; otherwise per-frame attribute uploads make picking flicker.

Source

demos/deckgl-biz-warehouse-alert.html
<!--
  示例:超时站点告警
  要点:ScatterplotLayer 按阈值过滤,脉冲逐帧只改 getRadius,底层 ScreenGridLayer 表达超时率
  依赖: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:150px;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></span>
  <span>告警 <b id="alert">—</b></span>
  <span class="sep"></span>
  <span>超时率阈值</span>
  <input id="th" type="range" min="0" max="25" step="1" value="12">
  <span><b id="thv">12%</b></span>
  <span class="sep"></span>
  <label><input id="pulse" type="checkbox" checked>显示告警脉冲</label>
</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 HUBS = [
    [116.30, 39.86], [116.44, 39.95], [116.52, 39.82],
    [116.36, 40.02], [116.48, 39.90], [116.24, 39.96]
  ];

  var rand = rng(20240611);
  var sites = [];
  for (var i = 0; i < 5000; i++) {
    var hub = HUBS[i % HUBS.length];
    var ring = Math.sqrt(rand()) * 0.062;
    var ang = rand() * Math.PI * 2;
    sites.push({
      lng: hub[0] + Math.cos(ang) * ring,
      lat: hub[1] + Math.sin(ang) * ring * 0.8,
      rate: Math.pow(rand(), 1.5) * 25,
      area: i % HUBS.length
    });
  }

  function pos(d) { return [d.lng, d.lat]; }

  var GRID_COLORS = [
    [26, 44, 86, 150],
    [36, 96, 150, 175],
    [72, 166, 170, 195],
    [246, 198, 90, 215],
    [236, 88, 58, 235]
  ];

  var threshold = 12;
  var alertData = [];
  var phase = 0.5;
  var pulseOn = true;

  function refilter() {
    alertData = [];
    for (var k = 0; k < sites.length; k++) {
      if (sites[k].rate >= threshold) alertData.push(sites[k]);
    }
    document.getElementById('alert').textContent = alertData.length.toLocaleString();
  }

  function pulseRadius() {
    return 5 + 8 * phase;
  }

  function makeGrid() {
    return new deck.ScreenGridLayer({
      id: 'alert-grid',
      data: sites,
      getPosition: pos,
      getWeight: function (d) { return d.rate; },
      cellSizePixels: 24,
      colorDomain: [0, 120],
      colorRange: GRID_COLORS,
      opacity: 0.9,
      pickable: true
    });
  }

  function makeBase() {
    return new deck.ScatterplotLayer({
      id: 'alert-base',
      data: sites,
      getPosition: pos,
      getRadius: 1.8,
      radiusUnits: 'pixels',
      getFillColor: [88, 122, 172, 120],
      pickable: false
    });
  }

  function makePulse() {
    return new deck.ScatterplotLayer({
      id: 'alert-pulse',
      data: alertData,
      getPosition: pos,
      getRadius: pulseRadius,
      updateTriggers: { getRadius: phase },
      radiusUnits: 'pixels',
      filled: true,
      getFillColor: [255, 96, 62, 70],
      stroked: true,
      getLineColor: [255, 168, 128, 225],
      lineWidthUnits: 'pixels',
      lineWidthMinPixels: 1,
      pickable: true
    });
  }

  var gridLayer = makeGrid();
  var baseLayer = makeBase();

  function frameLayers() {
    return [gridLayer, baseLayer, makePulse()];
  }

  document.getElementById('n').textContent = sites.length.toLocaleString();
  refilter();

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    initialViewState: {
      longitude: 116.39,
      latitude: 39.93,
      zoom: 11.5,
      pitch: 0,
      bearing: 0
    },
    controller: true,
    layers: frameLayers(),
    getTooltip: function (info) {
      var o = info.object;
      if (!o) return null;
      if (o.rate === undefined) return '格内超时率权重和 ' + Math.round(o.value || 0);
      return '超时率 ' + o.rate.toFixed(1) + '%' +
        (o.rate >= threshold ? ' · 超阈值' : ' · 正常');
    }
  });

  var slider = document.getElementById('th');
  var label = document.getElementById('thv');

  slider.addEventListener('input', function (e) {
    threshold = Number(e.target.value);
    label.textContent = threshold + '%';
    refilter();
    deckgl.setProps({ layers: frameLayers() });
  });

  document.getElementById('pulse').addEventListener('change', function (e) {
    pulseOn = e.target.checked;
    deckgl.setProps({ layers: frameLayers() });
  });

  var t = 0;
  var last = performance.now();
  function frame(now) {
    var dt = (now - last) / 1000;
    last = now;
    if (pulseOn) {
      t += dt;
      phase = 0.5 + 0.5 * Math.sin(t / 1.6 * Math.PI * 2);
      deckgl.setProps({ layers: frameLayers() });
    }
    requestAnimationFrame(frame);
  }
  requestAnimationFrame(frame);

  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 · APIScatterplotLayer deck.gl · APIScreenGridLayer deck.gl · APIDeck