Atlaslog
Atlaslog / Examples / Cesium / Flyline
Cesium · Runnable Example

Flyline

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

Source

demos/cesium-flyline.html
<!--
  示例:城市之间的飞线动画
  要点:用 EllipsoidGeodesic 沿大圆插值再叠加抛物线高度,光点按时间循环跑完整条弧线
  依赖: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}
  .hud button:hover{background:#262d37}
  .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">0 条航线</div>
  <div class="row"><button id="toggle">暂停光点</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;

  var HUB = { lng: 116.391263, lat: 39.907359, name: '北京' };
  var CITIES = [
    { lng: 121.473701, lat: 31.230416, name: '上海', peak: 240000, color: '#4d9bff' },
    { lng: 113.264385, lat: 23.129112, name: '广州', peak: 280000, color: '#3fe0b0' },
    { lng: 104.066541, lat: 30.572269, name: '成都', peak: 300000, color: '#ffb13d' },
    { lng: 87.616848, lat: 43.825592, name: '乌鲁木齐', peak: 360000, color: '#ff7f7f' },
    { lng: 126.642464, lat: 45.756967, name: '哈尔滨', peak: 200000, color: '#a78bfa' },
    { lng: 110.350000, lat: 20.020000, name: '海口', peak: 320000, color: '#38d9d0' }
  ];

  var t0 = Date.now();
  var running = true;

  function arcPoints(a, b, peak) {
    var geo = new Cesium.EllipsoidGeodesic(
      Cesium.Cartographic.fromDegrees(a.lng, a.lat),
      Cesium.Cartographic.fromDegrees(b.lng, b.lat)
    );
    var pts = [];
    var STEP = 72;
    for (var i = 0; i <= STEP; i++) {
      var t = i / STEP;
      var c = geo.interpolateUsingFraction(t);
      var h = 4 * peak * t * (1 - t);
      pts.push(Cesium.Cartesian3.fromRadians(c.longitude, c.latitude, h));
    }
    return pts;
  }

  function addLabel(lng, lat, text, color) {
    viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(lng, lat),
      point: { pixelSize: 5, color: Cesium.Color.WHITE.withAlpha(0.9) },
      label: {
        text: text,
        font: '500 11px "Microsoft YaHei", sans-serif',
        fillColor: color,
        pixelOffset: new Cesium.Cartesian2(0, -16),
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    });
  }

  addLabel(HUB.lng, HUB.lat, HUB.name, Cesium.Color.WHITE);

  CITIES.forEach(function (city, idx) {
    var color = Cesium.Color.fromCssColorString(city.color);
    var pts = arcPoints(HUB, city, city.peak);

    viewer.entities.add({
      polyline: {
        positions: pts,
        width: 2,
        material: new Cesium.PolylineGlowMaterialProperty({
          glowPower: 0.16,
          color: color.withAlpha(0.85)
        })
      }
    });

    addLabel(city.lng, city.lat, city.name, color.withAlpha(0.85));

    var phase = idx / CITIES.length;
    viewer.entities.add({
      position: new Cesium.CallbackProperty(function () {
        if (!running) return pts[0];
        var t = ((Date.now() - t0) / 2600 + phase) % 1;
        return pts[Math.min(pts.length - 1, Math.floor(t * (pts.length - 1)))];
      }, false),
      point: {
        pixelSize: 7,
        color: Cesium.Color.WHITE,
        outlineColor: color,
        outlineWidth: 3,
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    });
  });

  document.getElementById('info').textContent = CITIES.length + ' 条航线 · 光点往返循环';

  document.getElementById('toggle').addEventListener('click', function () {
    running = !running;
    this.textContent = running ? '暂停光点' : '继续光点';
  });

  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(106, 33, 8200000),
    orientation: { heading: 0, pitch: Cesium.Math.toRadians(-88), 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 · EXAMPLEFog Post Process Cesium · EXAMPLEFxaa Cesium · EXAMPLEGeoJSON and Topojson