Atlaslog
Atlaslog / Examples / deck.gl / Column Density
deck.gl · Runnable Example

Column Density

Runnable deck.gl example: Column Density. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.

Open standalone → Chinese notes All deck.gl examples
/demos/deckgl-column-density.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/deckgl-column-density.html
<!--
  示例:柱状密度
  要点:ColumnLayer 在规则网格上画一千根柱体,diskResolution 控制截面
  依赖: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:14px;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:4px;cursor:pointer;
       border:1px solid #2f3947;background:#1d242e;color:#c9d3e0}
  .bar button:hover{background:#26303d}
  #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>截面 6 边形 · 半径 160 m</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;
  }
  var cols = [];
  var GX = 36, GY = 24;
  for (var x = 0; x < GX; x++) {
    for (var y = 0; y < GY; y++) {
      var lng = 116.24 + x * 0.0092;
      var lat = 39.80 + y * 0.0078;
      var d = Math.sqrt(Math.pow(x - GX * 0.62, 2) + Math.pow(y - GY * 0.55, 2));
      var v = Math.max(0, 1 - d / (GX * 0.62)) * (0.6 + Math.random() * 0.8);
      if (v < 0.06) continue;
      cols.push({ lng: lng, lat: lat, v: v });
    }
  }

  document.getElementById('n').textContent = cols.length;

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    initialViewState: { longitude: 116.40, latitude: 39.89, zoom: 10.3, pitch: 45, bearing: 18 },
    controller: true,
    layers: [
      new deck.ColumnLayer({
        id: 'cols',
        data: cols,
        diskResolution: 6,
        radius: 160,
        getPosition: function (d) { return [d.lng, d.lat]; },
        getElevation: function (d) { return d.v * 900; },
        elevationScale: 1,
        getFillColor: function (d) {
          var t = d.v;
          return [Math.round(40 + 200 * t), Math.round(190 - 90 * t), Math.round(220 - 150 * t), 220];
        },
        pickable: true
      })
    ],
    getTooltip: function (info) {
      if (!info.object) return null;
      return '强度 ' + info.object.v.toFixed(2);
    }
  });
  window.__deck = deckgl;
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.

More deck.gl examples

deck.gl · EXAMPLEComposite Layer deck.gl · EXAMPLEContour deck.gl · EXAMPLEData Filter