Atlaslog
Atlaslog / Examples / Cesium / Radar Scan
Cesium · Runnable Example

Radar Scan

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

Source

demos/cesium-radar-scan.html
<!--
  示例:雷达扫描扇形
  要点:扇区多边形顶点由 CallbackProperty 按时间旋转,同心圆用 EllipseGraphics 描边表示量程
  依赖: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:#173f36;border-color:#2c8f79;color:#9ff0d8}
  .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">量程 24 km · 三档距离圈</div>
  <div class="row"><button id="toggle" class="on">暂停扫描</button></div>
  <div class="row" id="info">扇区宽度 50°</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 CENTER = { lng: 121.4737, lat: 31.2304 };
  var RADIUS = 24000;
  var dLat = RADIUS / 111320;
  var dLng = dLat / Math.cos(Cesium.Math.toRadians(CENTER.lat));
  var SWEEP = Cesium.Math.toRadians(50);

  var running = true;
  var frozen = 0;

  function angle() {
    if (!running) return frozen;
    return (Date.now() % 6000) / 6000 * Math.PI * 2;
  }

  function sector() {
    var a0 = angle();
    var flat = [CENTER.lng, CENTER.lat];
    for (var i = 0; i <= 18; i++) {
      var a = a0 - SWEEP / 2 + (SWEEP * i) / 18;
      flat.push(CENTER.lng + Math.cos(a) * dLng, CENTER.lat + Math.sin(a) * dLat);
    }
    return Cesium.Cartesian3.fromDegreesArray(flat);
  }

  viewer.entities.add({
    polygon: {
      hierarchy: new Cesium.CallbackProperty(sector, false),
      height: 0,
      material: new Cesium.ColorMaterialProperty(
        Cesium.Color.fromCssColorString('#3fe0b0').withAlpha(0.30)
      )
    }
  });

  /* 距离圈 */
  [0.33, 0.66, 1.0].forEach(function (k) {
    viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(CENTER.lng, CENTER.lat, 0),
      ellipse: {
        semiMajorAxis: RADIUS * k,
        semiMinorAxis: RADIUS * k,
        height: 0,
        fill: false,
        outline: true,
        outlineColor: Cesium.Color.fromCssColorString('#3fe0b0').withAlpha(0.55)
      }
    });
  });

  /* 雷达站 */
  viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(CENTER.lng, CENTER.lat, 0),
    point: {
      pixelSize: 9,
      color: Cesium.Color.WHITE,
      outlineColor: Cesium.Color.fromCssColorString('#3fe0b0'),
      outlineWidth: 3,
      disableDepthTestDistance: Number.POSITIVE_INFINITY
    },
    label: {
      text: '雷达站',
      font: '500 12px "Microsoft YaHei", sans-serif',
      fillColor: Cesium.Color.WHITE,
      pixelOffset: new Cesium.Cartesian2(0, -20),
      disableDepthTestDistance: Number.POSITIVE_INFINITY
    }
  });

  /* 三个目标,均在量程内 */
  var TARGETS = [
    { lng: 121.56, lat: 31.29, name: '目标 A' },
    { lng: 121.38, lat: 31.18, name: '目标 B' },
    { lng: 121.50, lat: 31.15, name: '目标 C' }
  ];

  TARGETS.forEach(function (t) {
    viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(t.lng, t.lat, 0),
      point: {
        pixelSize: 7,
        color: Cesium.Color.fromCssColorString('#ffb13d'),
        outlineColor: Cesium.Color.WHITE,
        outlineWidth: 1.5,
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      },
      label: {
        text: t.name,
        font: '500 11px "Microsoft YaHei", sans-serif',
        fillColor: Cesium.Color.fromCssColorString('#ffb13d'),
        pixelOffset: new Cesium.Cartesian2(0, -16),
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    });
  });

  var toggle = document.getElementById('toggle');
  toggle.addEventListener('click', function () {
    if (running) frozen = angle();
    running = !running;
    this.textContent = running ? '暂停扫描' : '继续扫描';
    this.className = running ? 'on' : '';
  });

  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(121.4737, 31.1000, 30000),
    orientation: {
      heading: Cesium.Math.toRadians(0),
      pitch: Cesium.Math.toRadians(-55),
      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 · EXAMPLERectangle Cesium · EXAMPLERender Mode Cesium · EXAMPLEResolution Scaling