Atlaslog
Atlaslog / Examples / deck.gl / Business scenarios / Base Station Sectors and Device Distribution
deck.gl · Business scenario

Base Station Sectors and Device Distribution

60 base stations grow 600 m sectors from azimuth and beamwidth, 20,000 device points are coloured by band, and a slider changes the beamwidth in real time.

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

Business context

Radio planning and optimisation teams use sector maps to verify antenna directions, investigate weak or overshooting coverage, and to review sites and plan new ones. Data comes from the network management parameter table — site id, lng/lat, azimuth, downtilt, band — plus terminal-side MR samples. A prefecture-level city has tens of thousands of sites and hundreds of millions of samples per day; the demo compresses this to 60 sites and 20,000 devices.

Parameters are corrected and duplicate sites merged before rendering, and azimuths are normalised to 0 at true north increasing clockwise. Each sector takes arc points along 18 segments between azimuth minus and plus half the beamwidth; the longitude offset must divide by cos(lat) to convert metres to degrees, otherwise sectors deform at high latitude. Device points inherit the band of their serving site and are drawn with ScatterplotLayer. PolygonLayer is chosen over a raster heatmap because the business question concerns geometry: direction and beamwidth.

Sectors are easily mistaken for real coverage: 600 m here is a configured radius, while actual coverage depends on downtilt, blockage and transmit power, so sector area is not effective coverage area. Filtering to 5G reduces device points and looks like degraded coverage, but only the population changed. Coverage rates also differ between counting sample points and counting raster area, often by more than ten percentage points.

How it works

The 60 sites are placed randomly within 116.18–116.62, 39.80–40.06 with azimuths from 0 to 360 degrees, and i%3 assigns roughly two thirds to 5G and one third to 4G. sectorRing pushes the centre first, then takes 19 arc points across 18 segments within azimuth ± half beamwidth, and appends the centre again to close the ring. Arc points use a 600 m metric radius: the longitude offset is 600·sin(azimuth)/(111320·cos(lat)) and the latitude offset is 600·cos(azimuth)/110540, because azimuth is zero at true north and grows clockwise, so sin maps to east-west and cos to north-south. The 20,000 device points scatter within 1.4 km of their site with a sqrt-uniform radius and inherit its band.

Dragging the beamwidth slider rebuilds all 60 sector rings: 30 degrees gives a narrow beam, 120 degrees opens to a third of the circle, and fill opacity stays at 80 so overlapping sectors do not merge into one mass. Checking the 5G-only box filters both sectors and device points, leaving about 13,300 5G and 6,700 4G points; the original array references are kept and only data is swapped. A common mistake is omitting the closing stroke back to the centre, which makes PolygonLayer connect the arc ends directly and cuts the sector into a bow; another is swapping the lng/lat offsets, which points a 90-degree sector north instead of east.

ConfigurationWhat it does
Azimuth + half beamwidthSets the arc start and end; half beamwidth is half the slider value
600 m radiusSector reach; the longitude axis must be divided by cos(lat)
18-segment arc1.7–6.7 degrees per segment, under 2 m of polyline error at 600 m
Closed ringThe centre point is appended at the end, otherwise the sector becomes a bow

Note. Swap sin for cos in the longitude offset and open the page: the 0-degree sector lies on its side, the fastest self-check of true-north conversion.

Source

demos/deckgl-biz-telecom-sector.html
<!--
  示例:基站扇区与终端分布
  要点:按方位角与张角参数化生成 600 m 扇形,18 段折线闭合,终端点按频段着色
  依赖: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}
  .bar input[type=range]{width:140px;accent-color:#4f9ef8}
  #cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
  <span>基站 <b>60</b> · 终端 <b>20,000</b></span>
  <span class="sep"></span>
  <span>张角 <b id="bwv">60</b>°</span>
  <input id="bw" type="range" min="30" max="120" step="5" value="60">
  <span class="sep"></span>
  <label><input id="only5" type="checkbox"> 只显示 5G 频段</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(335544);
  var R = 600;

  var stations = [];
  for (var i = 0; i < 60; i++) {
    var is5g = i % 3 !== 2;
    stations.push({
      lng: 116.18 + rand() * 0.44,
      lat: 39.80 + rand() * 0.26,
      az: rand() * 360,
      is5g: is5g
    });
  }

  // 从中心出发画弧、再回到中心,扇形必须闭合
  function sectorRing(st, half) {
    var ring = [[st.lng, st.lat]];
    var kx = 111320 * Math.cos(st.lat * Math.PI / 180);
    for (var s = 0; s <= 18; s++) {
      // 方位角以正北为 0 顺时针增大:sin 给经度偏移,cos 给纬度偏移
      var b = (st.az - half + 2 * half * s / 18) * Math.PI / 180;
      ring.push([
        st.lng + R * Math.sin(b) / kx,
        st.lat + R * Math.cos(b) / 110540
      ]);
    }
    ring.push([st.lng, st.lat]);
    return ring;
  }

  var termAll = [];
  var term5g = [];
  for (var t = 0; t < 20000; t++) {
    var base = stations[t % stations.length];
    var d = Math.sqrt(rand()) * 1400;
    var a = rand() * Math.PI * 2;
    var p = {
      lng: base.lng + Math.cos(a) * d / (111320 * Math.cos(base.lat * Math.PI / 180)),
      lat: base.lat + Math.sin(a) * d / 110540,
      is5g: base.is5g
    };
    termAll.push(p);
    if (base.is5g) term5g.push(p);
  }

  var half = 30;
  var only5g = false;

  function rebuild() {
    var polys = [];
    for (var i = 0; i < stations.length; i++) {
      if (only5g && !stations[i].is5g) continue;
      polys.push({ ring: sectorRing(stations[i], half), is5g: stations[i].is5g });
    }

    var polyLayer = new deck.PolygonLayer({
      id: 'sector-polys',
      data: polys,
      getPolygon: function (d) { return d.ring; },
      filled: true,
      getFillColor: function (d) {
        return d.is5g ? [64, 206, 226, 80] : [176, 132, 255, 80];
      },
      stroked: true,
      getLineColor: function (d) {
        return d.is5g ? [126, 238, 252, 235] : [210, 180, 255, 235];
      },
      getLineWidth: 1.4,
      lineWidthUnits: 'pixels'
    });

    var termLayer = new deck.ScatterplotLayer({
      id: 'sector-terminals',
      data: only5g ? term5g : termAll,
      getPosition: function (d) { return [d.lng, d.lat]; },
      getRadius: 1.7,
      radiusUnits: 'pixels',
      getFillColor: function (d) {
        return d.is5g ? [146, 238, 250, 135] : [206, 176, 255, 135];
      },
      stroked: false,
      opacity: 0.9
    });

    deckgl.setProps({ layers: [polyLayer, termLayer] });
  }

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    initialViewState: {
      longitude: 116.41,
      latitude: 39.93,
      zoom: 10.4,
      pitch: 0,
      bearing: 0
    },
    controller: true,
    layers: [],
    getTooltip: function (info) {
      if (!info.object) return null;
      if (info.layer && info.layer.id === 'sector-terminals') {
        return info.object.is5g ? '5G 终端' : '4G 终端';
      }
      return info.object.is5g ? '5G 扇区 · 600 m' : '4G 扇区 · 600 m';
    }
  });

  rebuild();

  document.getElementById('bw').addEventListener('input', function (e) {
    half = Number(e.currentTarget.value) / 2;
    document.getElementById('bwv').textContent = e.currentTarget.value;
    rebuild();
  });

  document.getElementById('only5').addEventListener('change', function (e) {
    only5g = e.currentTarget.checked;
    rebuild();
  });

  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 · APIPathLayer