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

Czml Colors

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

Source

demos/cesium-czml-colors.html
<!--
  示例:CZML 的 rgba 与 rgbaf 两种颜色写法
  说明:三块半透明多边形部分重叠,用来观察颜色叠加,另有一条发光折线
  核心逻辑:material.solidColor.color 写 rgba 或 rgbaf → 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;

  var data = [
    { id: 'document', name: '颜色表达', version: '1.0' },
    {
      id: 'polygon-blue',
      position: { cartographicDegrees: [116.370, 39.900, 0] },
      polygon: {
        positions: {
          cartographicDegrees: [
            116.348, 39.886, 0,
            116.392, 39.888, 0,
            116.396, 39.916, 0,
            116.352, 39.914, 0
          ]
        },
        material: { solidColor: { color: { rgba: [64, 132, 235, 150] } } }
      }
    },
    {
      id: 'polygon-orange',
      position: { cartographicDegrees: [116.384, 39.900, 20] },
      polygon: {
        positions: {
          cartographicDegrees: [
            116.368, 39.880, 20,
            116.412, 39.884, 20,
            116.414, 39.912, 20,
            116.366, 39.908, 20
          ]
        },
        material: { solidColor: { color: { rgbaf: [0.95, 0.66, 0.25, 0.55] } } }
      }
    },
    {
      id: 'polygon-green',
      position: { cartographicDegrees: [116.392, 39.892, 40] },
      polygon: {
        positions: {
          cartographicDegrees: [
            116.380, 39.874, 40,
            116.424, 39.876, 40,
            116.420, 39.898, 40,
            116.378, 39.896, 40
          ]
        },
        material: { solidColor: { color: { rgbaf: [0.22, 0.83, 0.62, 0.45] } } }
      }
    },
    {
      id: 'line',
      position: { cartographicDegrees: [116.370, 39.870, 200] },
      polyline: {
        positions: {
          cartographicDegrees: [
            116.348, 39.872, 200,
            116.386, 39.922, 200,
            116.424, 39.876, 200
          ]
        },
        width: 4,
        material: { polylineGlow: { color: { rgba: [255, 214, 102, 255] }, glowPower: 0.25 } }
      },
      label: {
        text: 'polylineGlow',
        font: '500 12px "Microsoft YaHei", sans-serif',
        fillColor: { rgba: [255, 232, 190, 255] },
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    }
  ];

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

  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(116.386, 39.862, 13000),
    orientation: {
      heading: 0,
      pitch: Cesium.Math.toRadians(-47),
      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 Cones Cylinders Cesium · EXAMPLECzml Corridor Cesium · EXAMPLECzml Custom Properties