Czml Animated Property
Runnable Cesium example: Czml Animated Property. 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
<!--
示例:CZML 的属性随时间自动变化
要点:color 与 pixelSize 用 epoch 加采样数组声明,clock 推进时数值自动插值
依赖:CesiumJS 1.121 · jsDelivr CDN,CZML 写在页面里,无外部数据
-->
<!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>CZML 属性动画</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:250px}
.hud b{color:#e6e8ec;font-weight:600}
.hud .row{margin-top:6px}
.hud button{font:inherit;font-size:12px;padding:3px 9px;margin-right:4px;border-radius:4px;
cursor:pointer;border:1px solid #343b46;background:#1d232b;color:#cfd6e2}
.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>CZML 属性动画</b></div>
<div class="row" id="state">属性随 clock 变化</div>
<div class="row">
<button id="toggle">暂停</button>
<button id="restart">重播</button>
</div>
<div class="row">126 秒一轮 · 颜色 3 个关键帧</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Cesium.js"></script>
<script>
(function () {
'use strict';
var START = '2026-03-01T08:00:00Z';
var STOP = '2026-03-01T08:02:06Z';
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('#1c2733');
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;
/* 半径、颜色、大小的采样都以 epoch 为时间零点 */
var czml = [
{
id: 'document',
version: '1.0',
clock: {
interval: START + '/' + STOP,
currentTime: START,
multiplier: 4,
range: 'LOOP_STOP',
step: 'SYSTEM_CLOCK_MULTIPLIER'
}
},
{
id: 'pulse',
name: '脉冲点',
availability: START + '/' + STOP,
position: { cartographicDegrees: [116.389, 39.906, 240] },
point: {
pixelSize: { epoch: START, number: [0, 10, 30, 30, 60, 10, 90, 30, 126, 10] },
color: {
epoch: START,
rgba: [
0, 90, 200, 255, 255,
42, 120, 235, 255, 255,
63, 255, 255, 255, 255,
105, 95, 208, 168, 255,
126, 90, 200, 255, 255
]
},
outlineColor: { rgba: [255, 255, 255, 160] },
outlineWidth: 2
},
label: {
text: '属性动画',
font: '600 13px sans-serif',
fillColor: { rgba: [255, 255, 255, 255] },
pixelOffset: { cartesian2: [0, -28] }
}
}
];
Cesium.CzmlDataSource.load(czml).then(function (ds) {
viewer.dataSources.add(ds);
viewer.clock.startTime = Cesium.JulianDate.fromIso8601(START);
viewer.clock.stopTime = Cesium.JulianDate.fromIso8601(STOP);
viewer.clock.currentTime = Cesium.JulianDate.fromIso8601(START);
viewer.clock.multiplier = 4;
viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
viewer.clock.shouldAnimate = true;
});
/* 参考点位,衬托脉冲点的位置 */
var RING = [
[116.377, 39.906], [116.389, 39.894], [116.401, 39.906], [116.389, 39.918]
];
RING.forEach(function (p) {
viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(p[0], p[1]),
point: { pixelSize: 5, color: Cesium.Color.fromCssColorString('#3f5a78') }
});
});
var paused = false;
document.getElementById('toggle').addEventListener('click', function () {
paused = !paused;
viewer.clock.shouldAnimate = !paused;
this.textContent = paused ? '继续' : '暂停';
document.getElementById('state').textContent = paused ? '已暂停' : '属性随 clock 变化';
});
document.getElementById('restart').addEventListener('click', function () {
viewer.clock.currentTime = Cesium.JulianDate.fromIso8601(START);
paused = false;
viewer.clock.shouldAnimate = true;
document.getElementById('toggle').textContent = '暂停';
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.389, 39.890, 1900),
orientation: {
heading: 0,
pitch: Cesium.Math.toRadians(-16),
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.