Atlaslog
Atlaslog / Examples / Cesium / Czml Position Definitions
Cesium · Runnable Example

Czml Position Definitions

Runnable Cesium example: Czml Position Definitions. 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-czml-position-definitions.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/cesium-czml-position-definitions.html
<!--
  示例:CZML 位置的三种写法
  说明:经纬高数组、ECEF 笛卡尔数组、引用其他对象,三种写法摆在一起对比
  核心逻辑:cartographicDegrees 与 cartesian 互换 → reference 复用位置 → CzmlDataSource.load
  依赖: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>CZML 位置写法</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%}
  .cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
  .cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></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.moon.show = false;
  if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;

  /* 提前算一组 ECEF 坐标,用来演示 cartesian 写法 */
  var ecef = Cesium.Cartesian3.fromDegrees(116.392, 39.913, 1200);

  var data = [
    { id: 'document', name: '位置写法', version: '1.0' },
    {
      id: 'by-degrees',
      name: 'cartographicDegrees',
      position: { cartographicDegrees: [116.352, 39.900, 1200] },
      point: {
        pixelSize: 14,
        color: { rgba: [77, 155, 255, 255] },
        outlineColor: { rgba: [255, 255, 255, 255] },
        outlineWidth: 2,
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      },
      label: {
        text: '经纬高',
        font: '500 13px "Microsoft YaHei", sans-serif',
        fillColor: { rgba: [216, 232, 250, 255] },
        pixelOffset: { cartesian2: [0, -24] },
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    },
    {
      id: 'by-cartesian',
      name: 'cartesian',
      position: { cartesian: [ecef.x, ecef.y, ecef.z] },
      point: {
        pixelSize: 14,
        color: { rgba: [57, 192, 160, 255] },
        outlineColor: { rgba: [255, 255, 255, 255] },
        outlineWidth: 2,
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      },
      label: {
        text: 'ECEF 笛卡尔',
        font: '500 13px "Microsoft YaHei", sans-serif',
        fillColor: { rgba: [212, 245, 236, 255] },
        pixelOffset: { cartesian2: [0, -24] },
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    },
    {
      id: 'anchor',
      name: '被引用的锚点',
      position: { cartographicDegrees: [116.432, 39.900, 2000] },
      point: {
        pixelSize: 10,
        color: { rgba: [255, 214, 102, 255] },
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    },
    {
      id: 'by-reference',
      name: 'reference',
      position: { reference: 'anchor#position' },
      label: {
        text: '引用 anchor#position',
        font: '500 13px "Microsoft YaHei", sans-serif',
        fillColor: { rgba: [255, 236, 200, 255] },
        pixelOffset: { cartesian2: [0, -24] },
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    },
    {
      id: 'line',
      name: '三个点的连线',
      polyline: {
        positions: {
          cartographicDegrees: [
            116.352, 39.900, 1200,
            116.392, 39.913, 1200,
            116.432, 39.900, 2000
          ]
        },
        width: 2,
        clampToGround: false,
        material: { solidColor: { color: { rgba: [150, 190, 240, 160] } } }
      }
    }
  ];

  Cesium.CzmlDataSource.load(data).then(function (ds) {
    viewer.dataSources.add(ds);
  });

  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(116.392, 39.878, 16000),
    orientation: {
      heading: 0,
      pitch: Cesium.Math.toRadians(-38),
      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 · EXAMPLECzml Rectangle Cesium · EXAMPLECzml Reference Properties Cesium · EXAMPLECzml Spheres Ellipsoids