Czml Polyline Volume
Runnable Cesium example: Czml Polyline Volume. 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 折线体挤出管道
说明:shape 给出矩形截面,positions 给中心线,cornerType 控制转角处理
核心逻辑:shape.cartesian2 是米为单位的二维轮廓 → 沿中心线挤出 → 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;
scene.globe.enableLighting = true;
/* 中心线:一条折线,含两次转弯 */
var centerline = [
116.330, 39.900, 200,
116.372, 39.918, 260,
116.386, 39.884, 200,
116.432, 39.906, 300
];
var data = [
{ id: 'document', name: '折线体', version: '1.0' },
{
id: 'pipe-beveled',
name: '矩形截面 · BEVELED 转角',
polylineVolume: {
positions: { cartographicDegrees: centerline },
shape: {
cartesian2: [-2600, -2600, 2600, -2600, 2600, 2600, -2600, 2600]
},
cornerType: 'BEVELED',
material: { solidColor: { color: { rgba: [77, 155, 255, 225] } } }
}
},
{
id: 'pipe-mitered',
name: '圆形截面 · MITERED 转角',
polylineVolume: {
positions: {
cartographicDegrees: [
116.330, 39.870, 120,
116.372, 39.888, 180,
116.386, 39.854, 120,
116.432, 39.876, 220
]
},
shape: {
cartesian2: [
3000, 0,
2121, 2121,
0, 3000,
-2121, 2121,
-3000, 0,
-2121, -2121,
0, -3000,
2121, -2121
]
},
cornerType: 'MITERED',
material: { solidColor: { color: { rgba: [57, 192, 160, 225] } } }
}
},
{
id: 'caption',
position: { cartographicDegrees: [116.386, 39.846, 0] },
label: {
text: '上:矩形截面 下:八边形近似圆',
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.386, 39.838, 30000),
orientation: {
heading: 0,
pitch: Cesium.Math.toRadians(-40),
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.