原文链接及内容

效果如下视频所示:

示例代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 夜晚的地球,也被称为 Black Marble 2017 和 Night Lights
const viewer = new Cesium.Viewer("cesiumContainer", {
geocoder: false,
sceneModePicker: false,
homeButton: false,
navigationHelpButton: false,
baseLayerPicker: false,
navigationInstructionsInitiallyVisible: false,
fullscreenButton: false,
selectionIndicator: false,
skyBox: false,
timeline: false,
animation: false,
shouldAnimate: true,
baseLayer: new Cesium.ImageryLayer.fromProviderAsync(
Cesium.IonImageryProvider.fromAssetId(3812)
),
});

viewer.cesiumWidget.creditContainer.style.display = "none";

// 其余代码用于动态光照
const dynamicLighting = false;

viewer.clock.multiplier = 4000;

const imageryLayers = viewer.imageryLayers;
const nightLayer = imageryLayers.get(0);
const dayLayer = Cesium.ImageryLayer.fromProviderAsync(
Cesium.IonImageryProvider.fromAssetId(3845)
);
imageryLayers.add(dayLayer);
imageryLayers.lowerToBottom(dayLayer);

function updateLighting(dynamicLighting) {
dayLayer.show = dynamicLighting;
viewer.scene.globe.enableLighting = dynamicLighting;
viewer.clock.shouldAnimate = dynamicLighting;

// 如果启用了动态照明,则夜间图像在地球照亮的一侧不可见。
nightLayer.dayAlpha = dynamicLighting ? 0.0 : 1.0;
}

updateLighting(dynamicLighting);

Sandcastle.addToggleButton(
"启用动态照明",
dynamicLighting,
function (checked) {
updateLighting(checked);
}
);