Boilerplate
Runnable deck.gl example: Boilerplate. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:deck.gl 最小骨架
核心逻辑:一个 Deck 实例加一个 ScatterplotLayer,不用 React、不接底图
数据:页面内写死的 16 个城市坐标与人口权重
依赖: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}
#cv{flex:1 1 auto;min-height:0;width:100%}
</style>
</head>
<body>
<div class="bar">
<span>图层 <b>1</b></span>
<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 data = [
['北京', 116.39, 39.90, 2189], ['上海', 121.47, 31.23, 2487],
['广州', 113.26, 23.12, 1868], ['深圳', 114.06, 22.54, 1756],
['成都', 104.06, 30.57, 2094], ['重庆', 106.55, 29.56, 3205],
['武汉', 114.30, 30.59, 1365], ['西安', 108.94, 34.34, 1295],
['杭州', 120.15, 30.28, 1194], ['南京', 118.80, 32.06, 931],
['沈阳', 123.43, 41.80, 902], ['哈尔滨', 126.64, 45.75, 1001],
['昆明', 102.71, 25.04, 846], ['乌鲁木齐', 87.61, 43.82, 405],
['拉萨', 91.11, 29.65, 87], ['海口', 110.20, 20.04, 287]
].map(function (d) {
return { name: d[0], lng: d[1], lat: d[2], pop: d[3] };
});
document.getElementById('n').textContent = data.length;
var scatter = new deck.ScatterplotLayer({
id: 'city-points',
data: data,
getPosition: function (d) { return [d.lng, d.lat]; },
/* 半径跟人口走,再用像素上下限兜住极端值 */
getRadius: function (d) { return Math.sqrt(d.pop) * 40; },
radiusUnits: 'meters',
radiusMinPixels: 4,
radiusMaxPixels: 26,
getFillColor: function (d) { return d.pop > 1500 ? [255, 138, 76] : [64, 156, 255]; },
stroked: true,
lineWidthMinPixels: 1,
getLineColor: [220, 235, 255, 120],
pickable: true
});
var deckgl = new deck.Deck({
canvas: document.getElementById('cv'),
width: '100%',
height: '100%',
initialViewState: {
longitude: 108,
latitude: 34,
zoom: 3,
pitch: 0,
bearing: 0,
maxPitch: 60
},
controller: true,
layers: [scatter],
getTooltip: function (info) {
if (!info.object) return null;
return info.object.name + ' · 常住人口 ' + info.object.pop + ' 万';
}
});
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.