Atlaslog
Atlaslog / Examples / Cesium / Czml Zindex
Cesium · Runnable Example

Czml Zindex

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

Source

demos/cesium-czml-zindex.html
<!--
  示例:用 CZML 的 zIndex 控制共面多边形的压盖顺序
  说明:三块半透明多边形重叠,各自 zIndex 不同,数值大的盖在上面
  核心逻辑:polygon.zIndex + 半透明填充 → 观察混合结果 → 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;

  function poly(id, z, color) {
    return {
      id: id,
      position: { cartographicDegrees: [116.392 + (z - 2) * 0.008, 39.900, 0] },
      polygon: {
        positions: {
          cartographicDegrees: [
            116.360, 39.884, 0,
            116.420, 39.884, 0,
            116.420, 39.918, 0,
            116.360, 39.918, 0
          ]
        },
        height: 0,
        zIndex: z,
        material: { solidColor: { color: color } },
        outline: true,
        outlineColor: { rgba: [235, 242, 252, 180] }
      }
    };
  }

  var data = [
    { id: 'document', name: '绘制顺序', version: '1.0' },
    poly('poly-1', 1, { rgba: [77, 155, 255, 110] }),
    poly('poly-2', 2, { rgba: [240, 170, 70, 110] }),
    poly('poly-3', 3, { rgba: [228, 92, 122, 110] }),
    {
      id: 'caption',
      position: { cartographicDegrees: [116.392, 39.872, 0] },
      label: {
        text: 'zIndex 1 蓝 · 2 橙 · 3 红,三块完全重叠',
        font: '500 13px "Microsoft YaHei", sans-serif',
        fillColor: { rgba: [216, 232, 250, 255] },
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    }
  ];

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

  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(116.392, 39.862, 9000),
    orientation: {
      heading: 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 · EXAMPLEDatasource Ordering Cesium · EXAMPLEDebug Stats Cesium · EXAMPLEDepth of Field