Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / Candidate Warehouse Coverage
deck.gl · Business scenario

Candidate Warehouse Coverage

Two candidate warehouses each draw a 5 km coverage circle over 60,000 order points colored by coverage, and switching candidates shows how coverage changes.

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

Business context

Warehouse network planning and site selection teams compare candidate coverage to estimate how many existing orders a new warehouse would serve, giving a quantitative basis for siting reviews that feeds directly into rent and delivery cost estimates. Data comes from historical order coordinates, candidate locations and a shared service-radius assumption; a typical review uses tens of thousands of order samples and only two or three candidates.

Order coordinates are deduplicated and denoised, candidate locations unified to one coordinate system, and coverage computed once at generation time, so switching candidates replaces only the test criterion rather than recomputing data. PolygonLayer draws the active candidate and PathLayer assembles the comparison candidate from short arcs to separate primary from secondary at a glance, without adding an extension package for dashes and while keeping the layer count minimal.

Both candidates must share one radius and one order set to be comparable; once each uses its own so-called optimal radius, the coverage difference absorbs a definitional gap and cannot be attributed to siting. Another trap is concluding from coverage alone, ignoring the density and fulfillment cost of the covered orders; equal coverage can hide very different costs.

How it works

Candidate A sits at 116.33/39.955 and B at 116.48/39.855, both locked to a 5000 m radius over the same 60,000-point order set, so switching changes only the geometry test, not the data. The active candidate's 96-gon uses filled: true and a 2 px stroke; the other is broken into 72 short arcs (2.75° each, 2.25° gaps) handed to PathLayer at 1 px width and alpha 190, which reads as dashed without adding PathStyleExtension.

Coverage counts points: covered orders over total orders, with the uncovered count shown in the bar, never an area ratio. Both candidates must share radius and data to be comparable; once each is drawn at its own optimal radius, the gap between A's 5 km and B's 6 km absorbs a definitional difference and the siting conclusion no longer holds.

ConfigurationWhat it does
RADIUS constant 5000Shared by both candidates so coverage is comparable
72 short arcs + PathLayerBuilds a dashed look from geometry, avoiding an extra extension
updateTriggers.getFillColorOnly color recomputes on candidate switch; positions are reused
Point-count definitionCoverage is the share of orders, not of service area

Note. Keep radius, order set and membership function as constants when comparing candidates and vary only the station coordinates; otherwise the difference cannot be attributed to siting.

Source

demos/deckgl-biz-new-warehouse.html
<!--
  示例:新仓选址覆盖对比
  要点:两个候选仓同半径 5 km,订单点按距离判覆盖,未覆盖点红色高亮
  依赖: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}
  #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 class="sep"></span>
  <span>候选仓</span>
  <button data-cand="0" class="on">A 东北</button>
  <button data-cand="1">B 西南</button>
  <span class="sep"></span>
  <span>覆盖率 <b id="cov">—</b></span>
  <span>未覆盖 <b id="miss">—</b></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 KX = 111320;
  var KY = 110540;
  var RADIUS = 5000;

  function ringOf(lng, lat, radius) {
    var ring = [];
    var kx = KX * Math.cos(lat * Math.PI / 180);
    for (var i = 0; i < 96; i++) {
      var a = i / 96 * Math.PI * 2;
      ring.push([lng + Math.cos(a) * radius / kx, lat + Math.sin(a) * radius / KY]);
    }
    return ring;
  }

  function dashOf(lng, lat, radius) {
    var segs = [];
    var kx = KX * Math.cos(lat * Math.PI / 180);
    var count = 72;
    var step = 360 / count;
    for (var i = 0; i < count; i++) {
      var a0 = i * step * Math.PI / 180;
      var a1 = (i * step + step * 0.55) * Math.PI / 180;
      segs.push([
        [lng + Math.cos(a0) * radius / kx, lat + Math.sin(a0) * radius / KY],
        [lng + Math.cos(a1) * radius / kx, lat + Math.sin(a1) * radius / KY]
      ]);
    }
    return segs;
  }

  var CAND = [
    { name: 'A', lng: 116.33, lat: 39.955 },
    { name: 'B', lng: 116.48, lat: 39.855 }
  ];
  for (var c = 0; c < CAND.length; c++) {
    CAND[c].ring = ringOf(CAND[c].lng, CAND[c].lat, RADIUS);
    CAND[c].dash = dashOf(CAND[c].lng, CAND[c].lat, RADIUS);
  }

  var rand = rng(51734);
  var orders = [];
  var CLUSTERS = [[116.30, 39.98, 0.05], [116.46, 39.90, 0.05],
    [116.36, 39.84, 0.04], [116.54, 39.99, 0.04]];

  for (var i = 0; i < 60000; i++) {
    var p;
    if (i % 4 !== 3) {
      var cl = CLUSTERS[i % CLUSTERS.length];
      p = {
        lng: cl[0] + (rand() + rand() + rand() - 1.5) * cl[2],
        lat: cl[1] + (rand() + rand() + rand() - 1.5) * cl[2] * 0.8
      };
    } else {
      p = { lng: 116.20 + rand() * 0.42, lat: 39.79 + rand() * 0.28 };
    }
    for (var k = 0; k < CAND.length; k++) {
      var dx = (p.lng - CAND[k].lng) * KX * Math.cos(CAND[k].lat * Math.PI / 180);
      var dy = (p.lat - CAND[k].lat) * KY;
      if (k === 0) p.a = dx * dx + dy * dy < RADIUS * RADIUS;
      else p.b = dx * dx + dy * dy < RADIUS * RADIUS;
    }
    orders.push(p);
  }
  function pos(d) { return [d.lng, d.lat]; }

  var active = 0;
  function updateStats() {
    var hit = 0;
    for (var i = 0; i < orders.length; i++) {
      if (active === 0 ? orders[i].a : orders[i].b) hit++;
    }
    document.getElementById('cov').textContent =
      (hit / orders.length * 100).toFixed(1) + '%';
    document.getElementById('miss').textContent =
      (orders.length - hit).toLocaleString();
  }

  function buildLayers() {
    var cur = CAND[active];
    var other = CAND[1 - active];
    return [
      new deck.PolygonLayer({
        id: 'candidate-zone',
        data: [cur.ring],
        getPolygon: function (d) { return d; },
        filled: true,
        getFillColor: active === 0 ? [86, 214, 168, 30] : [64, 154, 255, 30],
        stroked: true,
        getLineColor: active === 0 ? [110, 240, 196, 235] : [110, 180, 255, 235],
        getLineWidth: 2,
        lineWidthUnits: 'pixels',
        lineWidthMinPixels: 1,
        pickable: false
      }),
      new deck.PathLayer({
        id: 'candidate-ghost',
        data: other.dash,
        getPath: function (d) { return d; },
        getColor: [146, 158, 176, 190],
        getWidth: 1,
        widthUnits: 'pixels',
        widthMinPixels: 1,
        pickable: false
      }),
      new deck.ScatterplotLayer({
        id: 'order-points',
        data: orders,
        getPosition: pos,
        getRadius: 1.8,
        radiusUnits: 'pixels',
        updateTriggers: { getFillColor: active },
        getFillColor: function (d) {
          var hit = active === 0 ? d.a : d.b;
          return hit ? [86, 214, 168, 170] : [255, 88, 72, 225];
        },
        pickable: true
      })
    ];
  }

  document.getElementById('n').textContent = orders.length.toLocaleString();
  updateStats();
  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    initialViewState: {
      longitude: 116.40,
      latitude: 39.91,
      zoom: 11.5,
      pitch: 0,
      bearing: 0
    },
    controller: true,
    layers: buildLayers(),
    getTooltip: function (info) {
      var o = info.object;
      if (!o || o.a === undefined) return null;
      var hit = active === 0 ? o.a : o.b;
      return '候选 ' + CAND[active].name + ':' + (hit ? '覆盖' : '未覆盖');
    }
  });

  var buttons = document.querySelectorAll('[data-cand]');
  for (var b = 0; b < buttons.length; b++) {
    buttons[b].addEventListener('click', function (e) {
      active = Number(e.currentTarget.getAttribute('data-cand'));
      for (var j = 0; j < buttons.length; j++) {
        buttons[j].classList.toggle('on', buttons[j] === e.currentTarget);
      }
      updateStats();
      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 · APIPolygonLayer deck.gl · APIPathLayer deck.gl · APIScatterplotLayer