Czml Polygon
Runnable Cesium example: Czml Polygon. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:CZML 多边形挖洞
说明:外环写在 positions,内环写在 holes.cartographicDegrees 的嵌套数组里
核心逻辑:hole 顶点顺序与外环相反 → height 0 铺在椭球面 → 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-solid',
name: '实心多边形',
position: { cartographicDegrees: [116.362, 39.902, 0] },
polygon: {
positions: {
cartographicDegrees: [
116.336, 39.884, 0,
116.388, 39.886, 0,
116.386, 39.920, 0,
116.334, 39.916, 0
]
},
height: 0,
material: { solidColor: { color: { rgba: [77, 155, 255, 165] } } },
outline: true,
outlineColor: { rgba: [200, 224, 255, 235] }
}
},
{
id: 'polygon-holes',
name: '带两个洞的多边形',
position: { cartographicDegrees: [116.420, 39.902, 60] },
polygon: {
positions: {
cartographicDegrees: [
116.396, 39.884, 60,
116.446, 39.886, 60,
116.448, 39.922, 60,
116.394, 39.920, 60
]
},
holes: {
cartographicDegrees: [
[116.404, 39.892, 60, 116.404, 39.904, 60, 116.418, 39.904, 60, 116.418, 39.892, 60],
[116.426, 39.900, 60, 116.438, 39.902, 60, 116.430, 39.912, 60]
]
},
height: 60,
material: { solidColor: { color: { rgba: [240, 170, 70, 165] } } },
outline: true,
outlineColor: { rgba: [255, 226, 184, 235] }
}
},
{
id: 'caption',
position: { cartographicDegrees: [116.392, 39.870, 0] },
label: {
text: '左:实心 右:holes 挖出两个洞',
font: '500 13px "Microsoft YaHei", sans-serif',
fillColor: { rgba: [216, 230, 246, 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.856, 15000),
orientation: {
heading: 0,
pitch: Cesium.Math.toRadians(-45),
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.