Atlaslog
Atlaslog / Examples / Cesium / Camera Tour
Cesium · Runnable Example

Camera Tour

Runnable Cesium example: Camera Tour. 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-camera-tour.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/cesium-camera-tour.html
<!--
  示例:相机沿多点位循环巡航
  要点:flyTo 的 complete 回调里启动下一段,用一个令牌避免取消飞行后重复排队
  依赖: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: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>相机巡航</b></div>
  <div class="row" id="leg">第 1 站 · 南侧俯瞰</div>
  <div class="row">
    <button id="toggle">暂停</button>
    <button id="reset">从第一站重来</button>
  </div>
  <div class="row">5 站 · 每段 4 秒</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('#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 ROUTE = [
    { name: '南侧俯瞰', dest: [116.389, 39.880, 2600], h: 0, p: -32 },
    { name: '东南斜视', dest: [116.412, 39.888, 1800], h: 42, p: -20 },
    { name: '东北低空', dest: [116.404, 39.930, 900], h: 128, p: -12 },
    { name: '正北回望', dest: [116.389, 39.936, 2200], h: 180, p: -28 },
    { name: '高空全景', dest: [116.360, 39.860, 6200], h: 20, p: -52 }
  ];

  /* 一组方块,让巡航时画面里始终有参照物 */
  var BLOCKS = [
    [116.380, 39.900, 160, 160, 260],
    [116.392, 39.898, 220, 140, 180],
    [116.400, 39.904, 140, 200, 340],
    [116.386, 39.912, 180, 180, 140],
    [116.398, 39.918, 160, 160, 240]
  ];
  BLOCKS.forEach(function (b) {
    viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(b[0], b[1], b[4] / 2),
      box: {
        dimensions: new Cesium.Cartesian3(b[2], b[3], b[4]),
        material: Cesium.Color.fromCssColorString('#4d9bff').withAlpha(0.62),
        outline: true,
        outlineColor: Cesium.Color.fromCssColorString('#cfe4ff')
      }
    });
  });

  viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(116.39, 39.907, 0),
    label: {
      text: '巡航中心',
      font: '600 13px "Microsoft YaHei", sans-serif',
      fillColor: Cesium.Color.fromCssColorString('#ffd18a'),
      disableDepthTestDistance: Number.POSITIVE_INFINITY
    }
  });

  var token = 0;
  var current = 0;
  var paused = false;
  var legEl = document.getElementById('leg');

  function flyNext(i) {
    var my = ++token;
    current = i;
    var leg = ROUTE[i];
    legEl.textContent = '第 ' + (i + 1) + ' 站 · ' + leg.name;

    viewer.camera.flyTo({
      destination: Cesium.Cartesian3.fromDegrees(leg.dest[0], leg.dest[1], leg.dest[2]),
      orientation: {
        heading: Cesium.Math.toRadians(leg.h),
        pitch: Cesium.Math.toRadians(leg.p),
        roll: 0
      },
      duration: 4,
      complete: function () {
        if (paused || token !== my) return;
        flyNext((i + 1) % ROUTE.length);
      }
    });
  }

  document.getElementById('toggle').addEventListener('click', function () {
    paused = !paused;
    if (paused) {
      viewer.camera.cancelFlight();
      this.textContent = '继续';
    } else {
      this.textContent = '暂停';
      flyNext(current);
    }
  });

  document.getElementById('reset').addEventListener('click', function () {
    paused = false;
    document.getElementById('toggle').textContent = '暂停';
    flyNext(0);
  });

  flyNext(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 · EXAMPLECardboard Cesium · EXAMPLECartographic Limit Rectangle Cesium · EXAMPLECesium Inspector