Blue Marble
Runnable Cesium example: Blue Marble. 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
<!--
示例:在 canvas 上画出全球海陆轮廓并作为整幅影像
说明:用一组经纬度多边形近似大陆,配合海洋渐变与极地冰盖,交给 SingleTileImageryProvider
核心逻辑:经纬度顶点换算像素 → 填色与描边 → dataURL → 覆盖全球的单张影像
依赖:CesiumJS 1.121 · 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>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Widgets/widgets.css">
<style>
html,body{height:100%;margin:0}
body{background:#0e1116;color:#e6e8ec;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif}
#c{height:100%}
.hud{position:absolute;left:12px;top:12px;z-index:5;background:rgba(23,28,35,.9);
border:1px solid #2a313b;border-radius:6px;padding:9px 12px;font-size:12px;
color:#a2a9b6;max-width:260px}
.hud b{color:#e6e8ec;font-weight:600}
.hud .row{margin-top:7px}
.cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="hud">
<div><b>程序化全球影像</b></div>
<div class="row">大陆轮廓由经纬度多边形近似</div>
<div class="row"><label><input id="show" type="checkbox" checked> 显示影像</label></div>
<div class="row">取消勾选可对比纯色球体</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Cesium.js"></script>
<script>
(function () {
'use strict';
var viewer = new Cesium.Viewer('c', {
baseLayer: false,
baseLayerPicker: false, geocoder: false, homeButton: false,
sceneModePicker: false, navigationHelpButton: false,
animation: false, timeline: false, fullscreenButton: false,
infoBox: false, selectionIndicator: false
});
var scene = viewer.scene;
scene.globe.baseColor = Cesium.Color.fromCssColorString('#143a57');
scene.backgroundColor = Cesium.Color.fromCssColorString('#0e1116');
scene.skyBox.show = false;
scene.sun.show = false;
scene.moon.show = false;
if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;
var CW = 2048;
var CH = 1024;
var canvas = document.createElement('canvas');
canvas.width = CW;
canvas.height = CH;
var g = canvas.getContext('2d');
function px(lon) { return (lon + 180) / 360 * CW; }
function py(lat) { return (90 - lat) / 180 * CH; }
/* ---------- 海洋:纬度渐变的底色 ---------- */
var sea = g.createLinearGradient(0, 0, 0, CH);
sea.addColorStop(0.0, '#0d2b45');
sea.addColorStop(0.4, '#14547f');
sea.addColorStop(0.6, '#155c88');
sea.addColorStop(1.0, '#0d2b45');
g.fillStyle = sea;
g.fillRect(0, 0, CW, CH);
/* 几道浅色波纹,让海面不至于死板 */
g.globalAlpha = 0.08;
g.fillStyle = '#8fd3ff';
for (var i = 0; i < 22; i++) {
g.fillRect(0, i * 46 + 12, CW, 3);
}
g.globalAlpha = 1;
/* ---------- 大陆 ---------- */
var lands = [
[[-168, 65], [-140, 70], [-95, 73], [-62, 61], [-55, 45], [-66, 25],
[-82, 25], [-97, 18], [-105, 23], [-118, 32], [-125, 48], [-140, 60]],
[[-81, 10], [-60, 12], [-35, -5], [-38, -22], [-48, -33], [-70, -52],
[-75, -45], [-73, -18], [-81, -5]],
[[-17, 15], [10, 36], [32, 32], [43, 12], [51, 11], [40, -5],
[38, -20], [20, -35], [12, -18], [9, 4], [-8, 5]],
[[-10, 36], [0, 44], [5, 52], [30, 70], [60, 72], [140, 72], [160, 68],
[140, 50], [122, 40], [120, 22], [105, 10], [100, 5], [92, 21],
[80, 8], [72, 20], [60, 25], [45, 40], [28, 36], [18, 40], [10, 44]],
[[114, -22], [122, -18], [130, -12], [142, -10], [150, -25], [153, -38],
[140, -38], [128, -32], [115, -34]],
[[-45, 83], [-20, 80], [-22, 68], [-42, 60], [-55, 68], [-55, 78]]
];
function path(ring) {
g.beginPath();
ring.forEach(function (p, i) {
var x = px(p[0]);
var y = py(p[1]);
i === 0 ? g.moveTo(x, y) : g.lineTo(x, y);
});
g.closePath();
}
lands.forEach(function (ring) {
path(ring);
g.fillStyle = '#3f6b3f';
g.fill();
g.strokeStyle = '#2b4a2b';
g.lineWidth = 2;
g.stroke();
});
/* 沙漠带:撒哈拉与中亚一带的暖色 */
g.save();
path([[-17, 30], [35, 32], [55, 28], [55, 15], [10, 12], [-17, 20]]);
g.clip();
g.fillStyle = 'rgba(190, 160, 96, .75)';
g.fillRect(0, 0, CW, CH);
g.restore();
/* 极地冰盖 */
g.fillStyle = 'rgba(236, 244, 250, .92)';
g.fillRect(0, 0, CW, py(74));
g.fillRect(0, py(-64), CW, CH - py(-64));
/* 默认网格,方便判断经纬度是否对齐 */
g.strokeStyle = 'rgba(255, 255, 255, .06)';
g.lineWidth = 1;
for (var lon = -180; lon <= 180; lon += 30) {
g.beginPath(); g.moveTo(px(lon), 0); g.lineTo(px(lon), CH); g.stroke();
}
for (var lat = -60; lat <= 60; lat += 30) {
g.beginPath(); g.moveTo(0, py(lat)); g.lineTo(CW, py(lat)); g.stroke();
}
var provider = new Cesium.SingleTileImageryProvider({
url: canvas.toDataURL('image/png'),
rectangle: Cesium.Rectangle.MAX_VALUE,
tileWidth: CW,
tileHeight: CH
});
var layer = viewer.imageryLayers.addImageryProvider(provider);
document.getElementById('show').addEventListener('change', function () {
layer.show = this.checked;
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(20, 10, 22000000),
orientation: {
heading: 0,
pitch: Cesium.Math.toRadians(-90),
roll: 0
},
duration: 0
});
})();
</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.