Atlaslog
Atlaslog / Examples / Cesium / Dynamic Wall
Cesium · Runnable Example

Dynamic Wall

Runnable Cesium example: Dynamic Wall. 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-dynamic-wall.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/cesium-dynamic-wall.html
<!--
  示例:随时间起伏的动态墙
  要点:WallGraphics 的 maximumHeights 用 CallbackProperty 逐帧返回数组,墙顶再叠一条同步折线
  依赖: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:7px}
  .hud button{font:inherit;font-size:12px;padding:3px 9px;border-radius:4px;cursor:pointer;
       border:1px solid #343b46;background:#1d232b;color:#cfd6e2}
  .hud button.on{background:#1d3a5c;border-color:#3d6f9e;color:#cfe4ff}
  input[type=range]{width:100%}
  .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="info">峰值 1800 米 · 波动 600 米</div>
  <div class="row"><input id="amp" type="range" min="200" max="1200" step="50" value="600"></div>
  <div class="row"><button id="toggle" class="on">暂停波动</button></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;
  scene.globe.enableLighting = true;

  var N = 56;
  var BASE_LNG = 116.300;
  var BASE_LAT = 39.930;
  var positions = [];
  var cartos = [];

  for (var i = 0; i <= N; i++) {
    var f = i / N;
    var lng = BASE_LNG + f * 0.36;
    var lat = BASE_LAT + Math.sin(f * Math.PI) * 0.030;
    positions.push(Cesium.Cartesian3.fromDegrees(lng, lat, 0));
    cartos.push({ lng: lng, lat: lat });
  }

  var amplitude = 600;
  var running = true;
  var frozenPhase = 0;

  function phase() {
    if (!running) return frozenPhase;
    return (Date.now() % 8000) / 8000 * Math.PI * 2;
  }

  function heights() {
    var t = phase();
    var out = [];
    for (var i = 0; i <= N; i++) {
      var f = i / N;
      var wave = Math.sin(f * Math.PI * 3 - t) * 0.5 + 0.5;
      out.push(1200 + wave * amplitude);
    }
    return out;
  }

  function crestPositions() {
    var hs = heights();
    var out = [];
    for (var i = 0; i <= N; i++) {
      out.push(Cesium.Cartesian3.fromDegrees(cartos[i].lng, cartos[i].lat, hs[i]));
    }
    return out;
  }

  var WALL_COLOR = Cesium.Color.fromCssColorString('#2f6fd0').withAlpha(0.42);

  viewer.entities.add({
    wall: {
      positions: positions,
      maximumHeights: new Cesium.CallbackProperty(heights, false),
      minimumHeights: positions.map(function () { return 0; }),
      material: new Cesium.ColorMaterialProperty(WALL_COLOR)
    }
  });

  viewer.entities.add({
    polyline: {
      positions: new Cesium.CallbackProperty(crestPositions, false),
      width: 3,
      material: new Cesium.PolylineGlowMaterialProperty({
        glowPower: 0.22,
        color: Cesium.Color.fromCssColorString('#7fc4ff')
      })
    }
  });

  var info = document.getElementById('info');
  var toggle = document.getElementById('toggle');

  document.getElementById('amp').addEventListener('input', function () {
    amplitude = parseFloat(this.value);
    info.textContent = '峰值 1800 米 · 波动 ' + amplitude + ' 米';
  });

  toggle.addEventListener('click', function () {
    if (running) frozenPhase = phase();
    running = !running;
    this.textContent = running ? '暂停波动' : '继续波动';
    this.className = running ? 'on' : '';
  });

  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(116.36, 39.860, 7200),
    orientation: {
      heading: Cesium.Math.toRadians(6),
      pitch: Cesium.Math.toRadians(-22),
      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 · EXAMPLEEarth At Night Cesium · EXAMPLEElevation Band Material Cesium · EXAMPLEEllipse Fan