Atlaslog
Atlaslog / Examples / Cesium / Manually Controlled Animation
Cesium · Runnable Example

Manually Controlled Animation

Runnable Cesium example: Manually Controlled Animation. 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 Cesium examples
/demos/cesium-manually-controlled-animation.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/cesium-manually-controlled-animation.html
<!--
  示例:手动控制时间轴
  说明:关闭自动播放,用定时器按固定速率推进时钟,飞机沿采样轨迹移动
  核心逻辑:clock.shouldAnimate = false → 定时器改 currentTime → SampledPositionProperty 自动取值
  依赖: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%}
  .tip{position:absolute;left:12px;top:12px;z-index:5;
       background:rgba(23,28,35,.9);border:1px solid #2a313b;border-radius:6px;
       padding:8px 12px;font-size:12px;color:#a2a9b6;max-width:320px;line-height:1.6}

  .cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
  .cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="tip">动画不是自动播放,而是每 100 毫秒把时钟往前推 0.6 秒。</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('#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;

  var start = Cesium.JulianDate.fromIso8601('2026-10-28T00:00:00Z');
  var stop = Cesium.JulianDate.addSeconds(start, 24, new Cesium.JulianDate());

  viewer.clock.startTime = start.clone();
  viewer.clock.stopTime = stop.clone();
  viewer.clock.currentTime = start.clone();
  viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
  viewer.clock.shouldAnimate = false;      /* 交给外部推进 */

  var path = new Cesium.SampledPositionProperty();
  var pts = [
    [116.3830, 39.9020, 40], [116.3870, 39.9055, 80],
    [116.3910, 39.9028, 60], [116.3950, 39.9050, 90], [116.3985, 39.9022, 45]
  ];
  for (var i = 0; i < pts.length; i++) {
    path.addSample(
      Cesium.JulianDate.addSeconds(start, i * 6, new Cesium.JulianDate()),
      Cesium.Cartesian3.fromDegrees(pts[i][0], pts[i][1], pts[i][2])
    );
  }

  viewer.entities.add({
    position: path,
    point: { pixelSize: 14, color: Cesium.Color.fromCssColorString('#ffb13d') },
    path: { width: 2, material: Cesium.Color.fromCssColorString('#ffb13d'), leadTime: 0, trailTime: 6 }
  });

  /* 每 100 毫秒推进 0.6 秒,到末尾回到起点 */
  setInterval(function () {
    var next = Cesium.JulianDate.addSeconds(
      viewer.clock.currentTime, 0.6, new Cesium.JulianDate()
    );
    if (Cesium.JulianDate.greaterThan(next, stop)) {
      viewer.clock.currentTime = start.clone();
    } else {
      viewer.clock.currentTime = next;
    }
  }, 100);
  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(116.3905, 39.8988, 620),
    orientation: { heading: Cesium.Math.toRadians(0), pitch: Cesium.Math.toRadians(-26), 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.

More Cesium examples

Cesium · EXAMPLEMaterial Canvas Cesium · EXAMPLEMaterials Cesium · EXAMPLEMaterial Stripe