Atlaslog
Atlaslog / Examples / deck.gl / Contour
deck.gl · Runnable Example

Contour

Runnable deck.gl example: Contour. 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-contour.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/deckgl-contour.html
<!--
  示例:等值线
  要点:ContourLayer 把散点温度聚合成等值带,阈值与颜色逐级配置
  依赖: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>颜色按温度分层</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 samples = [];
  for (var i = 0; i < 420; i++) {
    var lng = 116.24 + Math.random() * 0.32;
    var lat = 39.79 + Math.random() * 0.18;
    var wave = Math.sin((lng - 116.24) * 18) * 1.6 + Math.cos((lat - 39.79) * 22) * 1.4;
    samples.push({ lng: lng, lat: lat, temp: 16 + wave + Math.random() * 1.2 });
  }

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

  var layer = new deck.ContourLayer({
    id: 'contour',
    data: samples,
    getPosition: function (d) { return [d.lng, d.lat]; },
    getWeight: function (d) { return d.temp; },
    cellSize: 500,
    aggregation: 'MEAN',
    contours: [
      { threshold: 14, color: [46, 82, 152], strokeWidth: 1 },
      { threshold: 15.5, color: [44, 140, 176], strokeWidth: 1 },
      { threshold: 17, color: [72, 178, 152], strokeWidth: 1 },
      { threshold: 18.5, color: [236, 190, 82], strokeWidth: 1 },
      { threshold: 20, color: [226, 96, 66], strokeWidth: 1 }
    ],
    pickable: true
  });

  var deckgl = new deck.Deck({
    canvas: 'cv',
    width: '100%',
    height: '100%',
    initialViewState: { longitude: 116.40, latitude: 39.88, zoom: 10.4, pitch: 0, bearing: 0 },
    controller: true,
    layers: [layer],
    getTooltip: function (info) {
      if (!info.object) return null;
      return '温度 ' + (info.object.colorValue || 0).toFixed(1) + ' 度';
    }
  });
  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 · EXAMPLEData Filter deck.gl · EXAMPLEData Update deck.gl · EXAMPLEFill Pattern