Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / Population Density and Competitor Stores
deck.gl · Business scenario

Population Density and Competitor Stores

120,000 sample points cluster into five trade areas, GridLayer extrudes a column field, and 18 own stores plus 26 competitor stores sit on top of the columns.

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

Business context

Expansion and trade-area analysis teams at retail chains overlay population density with competitor stores to judge where openings remain, and to review the siting quality of existing stores. Data comes from anonymized location sampling, footfall counts, trade-area boundaries and competitor locations; a city typically uses hundreds of thousands of sample points and a few dozen stores, on a quarterly or semiannual update cycle suited to mid-level decisions.

Sample points are cleaned by trade-area assignment and stripped of duplicates and drift outliers before being counted onto a metric grid, whose cell size is chosen for the city scale and should then stay fixed. GridLayer is chosen because it bins by real ground size and column height expresses an area total directly, making density gradients easier to read than scattered points; stores are layered with ScatterplotLayer so they remain pickable precisely among the columns.

Changing the cell size is the biggest trap in this kind of view: larger cells merge adjacent trade areas into one tall column and make demand look concentrated at a single point, while smaller cells split one area into several short columns and dilute density. Column height also represents total people, not density; without dividing by area, comparing cities with different populations misleads.

How it works

The 120,000 sample points combine three uniform distributions around five trade areas, dense at the center and sparse at the rim. GridLayer starts at cellSize 500 m with coverage 0.9 for gaps; getColorWeight and getElevationWeight both return 1 with SUM aggregation, color takes a five-step blue-to-orange-red ramp, and elevationDomain is left empty so heights normalize to elevationRange [0,1000] by the largest count in the current grid, lifting the densest cell of about 400 points close to 1000 m.

Widening cells from 500 m to 900 m merges two adjacent trade areas into one cell, turning two high columns into one and suggesting demand concentrated at a single point, which biases siting toward a false merged center; narrowing to 300 m splits one area into several short columns and dilutes density. Stores use a 4.5 px radius with a white 1.5 px stroke, teal for own and orange-red for competitors, neither overlapping the grid's blue-orange ramp, or they become invisible in dense cells.

ConfigurationWhat it does
cellSize 300–900 mAggregation grain, deciding whether trade areas merge or split
colorAggregation: 'SUM'Cell color expresses total people, not a per-capita value
elevationRange [0,1000]Heights normalize to the current maximum count, so changing cell size reshuffles all heights
getRadius: 4.5 pxStore points independent of zoom, keeping strokes legible

Note. After changing the cell size, count the columns first: a sudden drop means trade areas were merged, and any conclusion about a center has to be rechecked.

Source

demos/deckgl-biz-retail-density.html
<!--
  示例:人群密度与竞品门店
  要点:GridLayer 按米制网格求和人群采样点,门店用描边散点叠在柱阵上方
  依赖: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 .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="m">18 自家 · 26 竞品</b></span>
  <span class="sep"></span>
  <span>网格边长</span>
  <input id="cell" type="range" min="300" max="900" step="50" value="500">
  <span><b id="cellv">500 m</b></span>
  <span class="sep"></span>
  <label><input id="onlyComp" type="checkbox">只显示竞品</label>
  <label><input id="hideGrid" type="checkbox">隐藏网格</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.90, 0.030], [116.47, 39.87, 0.028],
    [116.36, 39.99, 0.024], [116.53, 39.98, 0.026],
    [116.24, 39.83, 0.022]
  ];

  var rand = rng(740021);
  var points = [];
  for (var i = 0; i < 120000; i++) {
    var h = HUBS[i % HUBS.length];
    points.push({
      lng: h[0] + (rand() + rand() + rand() - 1.5) * h[2],
      lat: h[1] + (rand() + rand() + rand() - 1.5) * h[2] * 0.8
    });
  }

  var stores = [];
  for (var o = 0; o < 18; o++) {
    var ho = HUBS[o % HUBS.length];
    stores.push({
      lng: ho[0] + (rand() - 0.5) * 0.03,
      lat: ho[1] + (rand() - 0.5) * 0.024,
      rival: false
    });
  }
  for (var r = 0; r < 26; r++) {
    var hr = HUBS[r % HUBS.length];
    stores.push({
      lng: hr[0] + (rand() - 0.5) * 0.05,
      lat: hr[1] + (rand() - 0.5) * 0.04,
      rival: true
    });
  }

  var rivalOnly = [];
  for (var q = 0; q < stores.length; q++) {
    if (stores[q].rival) rivalOnly.push(stores[q]);
  }

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

  var GRID_COLORS = [
    [22, 40, 78, 165],
    [30, 92, 148, 190],
    [58, 160, 176, 205],
    [250, 198, 92, 220],
    [236, 92, 60, 235]
  ];

  var cellSize = 500;
  var hideGrid = false;
  var storeData = stores;

  function buildLayers() {
    return [
      new deck.GridLayer({
        id: 'crowd-grid',
        data: points,
        getPosition: pos,
        cellSize: cellSize,
        coverage: 0.9,
        extruded: true,
        getColorWeight: function () { return 1; },
        colorAggregation: 'SUM',
        getElevationWeight: function () { return 1; },
        elevationAggregation: 'SUM',
        elevationRange: [0, 1000],
        colorRange: GRID_COLORS,
        visible: !hideGrid,
        pickable: true
      }),
      new deck.ScatterplotLayer({
        id: 'shops',
        data: storeData,
        getPosition: pos,
        getRadius: 4.5,
        radiusUnits: 'pixels',
        filled: true,
        getFillColor: function (d) {
          return d.rival ? [240, 96, 72, 235] : [72, 214, 168, 235];
        },
        stroked: true,
        getLineColor: [245, 248, 252, 225],
        lineWidthUnits: 'pixels',
        lineWidthMinPixels: 1.5,
        pickable: true
      })
    ];
  }

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

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    initialViewState: {
      longitude: 116.39,
      latitude: 39.91,
      zoom: 11.4,
      pitch: 44,
      bearing: -18
    },
    controller: true,
    layers: buildLayers(),
    getTooltip: function (info) {
      var o = info.object;
      if (!o) return null;
      if (o.rival === undefined) return '格内采样点 ' + o.count;
      return (o.rival ? '竞品门店' : '自家门店') + ' · 户数密度网格见柱高';
    }
  });

  document.getElementById('cell').addEventListener('input', function (e) {
    cellSize = Number(e.target.value);
    document.getElementById('cellv').textContent = cellSize + ' m';
    deckgl.setProps({ layers: buildLayers() });
  });

  document.getElementById('onlyComp').addEventListener('change', function (e) {
    storeData = e.target.checked ? rivalOnly : stores;
    deckgl.setProps({ layers: buildLayers() });
  });

  document.getElementById('hideGrid').addEventListener('change', function (e) {
    hideGrid = e.target.checked;
    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 · APIGridLayer deck.gl · APIScatterplotLayer deck.gl · APIColumnLayer