Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / Delivery Coverage and Order Points
deck.gl · Business scenario

Delivery Coverage and Order Points

Eight delivery stations draw service areas as 96-gons while 120,000 order points are classified by distance to station, with a toggle for out-of-area orders.

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

Business context

Planning teams for instant delivery and parcel networks overlay service areas with order points to judge whether station coverage is reasonable and to decide on new stations, boundary extensions or contractions. Data comes from coordinates derived by geocoding order addresses plus service-area configuration; a city can take several hundred thousand orders per day, and the sampled points drawn on the map usually number tens to hundreds of thousands.

Addresses are geocoded first and unlocatable records removed, then inside-outside relations are precomputed by station assignment and baked into the data as a boolean, so no distance calculation runs on every interaction. PolygonLayer draws areas and ScatterplotLayer draws points because area expresses extent and points express distribution; kept as two layers, the fill can be very light and still not hide the points beneath.

Coverage by point count and by area give entirely different conclusions: the point measure reflects the share of orders covered, while the area measure is easily inflated by large low-density zones. A circular service area is also only an approximation; districts split by rivers or expressways have far worse real accessibility, and treating the geometric circle as the true range understates missed deliveries.

How it works

Service radii run 3.5–5 km and the circles are assembled from 96 segments, longitude by radius/(111320*cos(lat)) and latitude by radius/110540, so at 5 km the chord error of 96 segments is about 2.7 m, under 1 px on screen. PolygonLayer sets filled: true with getFillColor alpha 24, a 1.6 px stroke and lineWidthUnits: 'pixels', so the fill does not cover the order points beneath.

Of the 120,000 orders, 70% are generated in polar coordinates around their station and the rest scattered inside a 116.18–116.64 bounding box, then all judged uniformly by dx²+dy²<r², keeping generation logic and display definition consistent so red points in the out-of-area view are genuine misses. A circle only holds on flat terrain with an even road network; areas split by rivers or ring roads need road-network isochrones, or points unreachable in ten minutes get counted as covered.

ConfigurationWhat it does
96-segment polygonApproximates the circular service area; segment count sets smoothness and vertex cost
getFillColor alpha 24Range backdrop only, so order points stay visible
getRadius: 1.6 pxScreen-pixel radius for 120,000 points, stable density perception under zoom
in boolean fieldPoint-in-area result baked into the data; switching views swaps arrays only

Note. Compute service-area membership at generation time rather than in a render callback; 120,000 points against eight stations would add nearly a million square roots on every interaction.

Source

demos/deckgl-biz-delivery-coverage.html
<!--
  示例:配送范围与订单点
  要点:96 边形近似圆形服务区,12 万订单点用站点距离做点面判断并分色
  依赖: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>区外 <b id="out">—</b></span>
  <span class="sep"></span>
  <button data-view="all" class="on">全部</button>
  <button data-view="in">区内</button>
  <button data-view="out">区外</button>
  <span class="sep"></span>
  <span>8 个配送站 · 半径 3.5–5 km</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 STATIONS = [
    [116.28, 39.89, 4200], [116.36, 39.94, 5000],
    [116.44, 39.86, 3800], [116.50, 39.95, 4600],
    [116.32, 39.83, 3500], [116.42, 40.00, 4800],
    [116.22, 39.97, 3900], [116.55, 39.88, 4400]
  ];

  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;
  }

  var zones = [];
  for (var s = 0; s < STATIONS.length; s++) {
    zones.push(ringOf(STATIONS[s][0], STATIONS[s][1], STATIONS[s][2]));
  }

  function inAnyService(lng, lat) {
    for (var i = 0; i < STATIONS.length; i++) {
      var st = STATIONS[i];
      var dx = (lng - st[0]) * KX * Math.cos(st[1] * Math.PI / 180);
      var dy = (lat - st[1]) * KY;
      if (dx * dx + dy * dy < st[2] * st[2]) return true;
    }
    return false;
  }

  var rand = rng(8801);
  var all = [];
  var inZone = [];
  var outZone = [];

  for (var i = 0; i < 120000; i++) {
    var p;
    if (i % 10 < 7) {
      var st = STATIONS[i % STATIONS.length];
      var a = rand() * Math.PI * 2;
      var r = Math.sqrt(rand()) * st[2] * 0.93;
      p = {
        lng: st[0] + Math.cos(a) * r / (KX * Math.cos(st[1] * Math.PI / 180)),
        lat: st[1] + Math.sin(a) * r / KY
      };
    } else {
      p = { lng: 116.18 + rand() * 0.46, lat: 39.78 + rand() * 0.28 };
    }
    p.in = inAnyService(p.lng, p.lat);
    all.push(p);
    if (p.in) inZone.push(p); else outZone.push(p);
  }

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

  var viewData = all;

  function buildLayers() {
    return [
      new deck.PolygonLayer({
        id: 'service-zones',
        data: zones,
        getPolygon: function (d) { return d; },
        filled: true,
        getFillColor: [64, 154, 255, 24],
        stroked: true,
        getLineColor: [96, 180, 255, 205],
        getLineWidth: 1.6,
        lineWidthUnits: 'pixels',
        lineWidthMinPixels: 1,
        pickable: false
      }),
      new deck.ScatterplotLayer({
        id: 'order-points',
        data: viewData,
        getPosition: pos,
        getRadius: 1.6,
        radiusUnits: 'pixels',
        getFillColor: function (d) {
          return d.in ? [86, 214, 168, 205] : [255, 96, 80, 220];
        },
        pickable: true
      })
    ];
  }

  document.getElementById('n').textContent = all.length.toLocaleString();
  document.getElementById('out').textContent = outZone.length.toLocaleString();

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    initialViewState: {
      longitude: 116.40,
      latitude: 39.91,
      zoom: 11.4,
      pitch: 0,
      bearing: 0
    },
    controller: true,
    layers: buildLayers(),
    getTooltip: function (info) {
      var o = info.object;
      if (!o) return null;
      return o.in ? '在服务区内' : '不在任何服务区内';
    }
  });

  var buttons = document.querySelectorAll('[data-view]');
  for (var b = 0; b < buttons.length; b++) {
    buttons[b].addEventListener('click', function (e) {
      var mode = e.currentTarget.getAttribute('data-view');
      if (mode === 'in') viewData = inZone;
      else if (mode === 'out') viewData = outZone;
      else viewData = all;
      for (var k = 0; k < buttons.length; k++) {
        buttons[k].classList.toggle('on', buttons[k] === e.currentTarget);
      }
      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 · APIScatterplotLayer deck.gl · APIView