Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / Work Order Grid Statistics
deck.gl · Business scenario

Work Order Grid Statistics

80,000 work orders compressed into a screen grid; switching between 16, 28 and 44 pixel cells, with Top5 hotspot centroids and counts labelled on top.

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

Business context

District operations centres and performance review units use it to check work order volume by district and to judge whether staffing matches demand density. Data comes from the work order system joined with the grid partition table: order id, governing grid, report time and category. A district platform receives a few thousand orders per day and roughly 100,000 per year. Administrative grids and responsibility grids usually exist as two separate systems, and the mapping must be reconciled first, or the same order lands in different cells.

The aggregation grain is chosen before rendering. ScreenGridLayer cells are measured in screen pixels, so the geographic area they cover changes with zoom, which suits the question of where the screen is densest. If review needs fixed administrative units, use GridLayer with cellSize in metres or a pre-aggregated H3 grid instead. Coordinates are normalised to WGS84, each order weighs 1, Top5 centroids reuse the district generation parameters rather than rescanning 80,000 points, and switching grain only changes cellSizePixels.

Misreading centres on taking a cell value as the total volume of that area. Pixel cells change with zoom, the same area is divided into different numbers of cells at different levels, so per-cell counts cannot be compared across zoom levels and do not equal administrative grid totals. Colours are normalised to the largest cell value currently rendered, so switching to finer cells lowers that maximum and the surface turns redder overall, which reads as more orders. The Top5 labels sit at district centres, not at the true centroid of a hotspot.

How it works

Six districts are generated with 21,000, 17,000, 14,000, 11,000, 9,000 and 8,000 orders and scatter radii of 0.015–0.022 degrees, for a fixed total of 80,000 points. ScreenGridLayer is configured only with getPosition, getWeight returning 1, cellSizePixels 28 and a five-band colorRange; aggregation is left to the GPU. The colour domain is not hardcoded but normalised to the largest cell value currently rendered, so switching to 16 pixels automatically adapts to smaller per-cell counts. Top5 centroids take the district centres and counts straight from the generation parameters instead of scanning the point set, and ScatterplotLayer radius maps count/21000 to 9–22 pixels.

ScreenGridLayer cells are measured in screen pixels, so zooming changes how much geography each cell covers while the number of cells and their screen coverage stay the same; GridLayer cellSize is in metres, so cells grow and shrink with the map and one cell can hold an entire district at city scale. At 44 pixels per-cell counts rise and the ramp reaches red sooner; at 16 pixels the density gradient inside a district becomes visible, but the greater number of cells fragments the shape. The checkbox unmounts only TextLayer, while the centroid ScatterplotLayer always stays, so labels and colour blocks can be checked against each other.

ConfigurationWhat it does
cellSizePixelsScreen-pixel cell width; 16/28/44 switch the aggregation grain
getWeight 1One count per order, so the cell value is the number of orders inside
Top5 centroidsReuse district generation parameters instead of rescanning 80,000 points
TextLayerLabels counts at hotspots and mounts or unmounts with the checkbox

Note. Zoom two levels and look at the 28-pixel grid again: cell pixels stay the same while coverage grows, the clearest difference between ScreenGridLayer and GridLayer.

Source

demos/deckgl-biz-city-workorder-grid.html
<!--
  示例:工单网格统计
  要点:ScreenGridLayer 在屏幕空间按像素分格,格子大小不随缩放变化,叠加 Top5 热点质心与数量标注
  依赖: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 label{display:flex;align-items:center;gap:5px;cursor:pointer}
  .bar input[type=checkbox]{accent-color:#4f9ef8;margin:0}
  #cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
  <span>工单 <b>80,000</b></span>
  <span class="sep"></span>
  <span>网格 <b id="cs">28</b> px</span>
  <button data-cell="16">16 px</button>
  <button data-cell="28" class="on">28 px</button>
  <button data-cell="44">44 px</button>
  <span class="sep"></span>
  <label><input id="lb" 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 rand = rng(77031);

  // 六个片区的工单量与散布半径,总数 80000
  var hubs = [
    { lng: 116.352, lat: 39.902, spread: 0.020, count: 21000 },
    { lng: 116.448, lat: 39.958, spread: 0.018, count: 17000 },
    { lng: 116.300, lat: 39.965, spread: 0.016, count: 14000 },
    { lng: 116.505, lat: 39.900, spread: 0.020, count: 11000 },
    { lng: 116.395, lat: 40.015, spread: 0.015, count: 9000 },
    { lng: 116.470, lat: 39.830, spread: 0.022, count: 8000 }
  ];

  var points = [];
  for (var i = 0; i < hubs.length; i++) {
    var h = hubs[i];
    for (var k = 0; k < h.count; k++) {
      var rad = Math.sqrt(rand()) * h.spread;
      var ang = rand() * Math.PI * 2;
      points.push({
        lng: h.lng + Math.cos(ang) * rad,
        lat: h.lat + Math.sin(ang) * rad * 0.82
      });
    }
  }

  // 质心固定取生成参数,避免每次重算 8 万点
  var top5 = hubs.slice(0, 5);

  var gridLayer = null;
  var cellSize = 28;

  function makeGrid(px) {
    return new deck.ScreenGridLayer({
      id: 'workorder-screen-grid',
      data: points,
      getPosition: function (d) { return [d.lng, d.lat]; },
      getWeight: function () { return 1; },
      cellSizePixels: px,
      colorRange: [
        [22, 38, 82, 130],
        [28, 96, 150, 175],
        [60, 168, 176, 200],
        [250, 200, 90, 220],
        [232, 92, 62, 240]
      ],
      opacity: 0.78,
      pickable: true
    });
  }

  var hotLayer = new deck.ScatterplotLayer({
    id: 'workorder-hot-centroid',
    data: top5,
    getPosition: function (d) { return [d.lng, d.lat]; },
    getRadius: function (d) { return 9 + d.count / 21000 * 13; },
    radiusUnits: 'pixels',
    getFillColor: [255, 214, 120, 60],
    stroked: true,
    getLineColor: [255, 226, 150, 245],
    lineWidthUnits: 'pixels',
    getLineWidth: 1.6
  });

  var labelLayer = new deck.TextLayer({
    id: 'workorder-hot-label',
    data: top5,
    getText: function (d) { return d.count.toLocaleString(); },
    getPosition: function (d) { return [d.lng, d.lat]; },
    getSize: 12,
    sizeUnits: 'pixels',
    getColor: [238, 242, 250, 245],
    getPixelOffset: [0, -30],
    background: true,
    getBackgroundColor: [14, 20, 28, 215],
    backgroundPadding: [5, 2],
    fontFamily: 'Segoe UI, PingFang SC, sans-serif'
  });

  gridLayer = makeGrid(cellSize);

  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: [gridLayer, hotLayer, labelLayer],
    getTooltip: function (info) {
      if (!info.object) return null;
      return '格内工单 ' + Math.round(info.object.count || info.object.value || 0);
    }
  });

  var showLabels = true;

  function sync() {
    document.getElementById('cs').textContent = cellSize;
    var layers = [gridLayer, hotLayer];
    if (showLabels) layers.push(labelLayer);
    deckgl.setProps({ layers: layers });
  }

  var buttons = document.querySelectorAll('[data-cell]');
  for (var b = 0; b < buttons.length; b++) {
    buttons[b].addEventListener('click', function (e) {
      cellSize = Number(e.currentTarget.getAttribute('data-cell'));
      for (var j = 0; j < buttons.length; j++) {
        buttons[j].classList.toggle('on', buttons[j] === e.currentTarget);
      }
      gridLayer = makeGrid(cellSize);
      sync();
    });
  }

  document.getElementById('lb').addEventListener('change', function (e) {
    showLabels = e.currentTarget.checked;
    sync();
  });

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