Czml Polyline
Runnable Cesium example: Czml Polyline. 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 折线的三种材质
说明:同一组坐标分别用实色、polylineGlow 与 polylineOutline,另有贴地折线
核心逻辑:polyline.width / material / clampToGround → 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 ring(lat) {
return [
116.330, lat, 0,
116.360, lat + 0.018, 0,
116.400, lat + 0.024, 0,
116.440, lat + 0.016, 0,
116.462, lat - 0.004, 0
];
}
var data = [
{ id: 'document', name: '折线', version: '1.0' },
{
id: 'plain',
position: { cartographicDegrees: [116.400, 39.940, 0] },
polyline: {
positions: { cartographicDegrees: ring(39.942) },
width: 3,
material: { solidColor: { color: { rgba: [210, 226, 245, 230] } } }
}
},
{
id: 'glow',
position: { cartographicDegrees: [116.400, 39.922, 0] },
polyline: {
positions: { cartographicDegrees: ring(39.922) },
width: 6,
material: { polylineGlow: { color: { rgba: [255, 190, 60, 255] }, glowPower: 0.3 } }
}
},
{
id: 'outline',
position: { cartographicDegrees: [116.400, 39.902, 0] },
polyline: {
positions: { cartographicDegrees: ring(39.902) },
width: 8,
material: {
polylineOutline: {
color: { rgba: [77, 155, 255, 255] },
outlineColor: { rgba: [20, 40, 80, 255] },
outlineWidth: 2
}
}
}
},
{
id: 'dash',
position: { cartographicDegrees: [116.400, 39.882, 0] },
polyline: {
positions: { cartographicDegrees: ring(39.882) },
width: 4,
clampToGround: true,
material: { polylineDash: { color: { rgba: [57, 192, 160, 255] }, dashLength: 18 } }
}
},
{
id: 'caption',
position: { cartographicDegrees: [116.400, 39.860, 0] },
label: {
text: '实色 / 发光 / 描边 / 虚线贴地',
font: '500 13px "Microsoft YaHei", sans-serif',
fillColor: { rgba: [214, 228, 245, 255] },
disableDepthTestDistance: Number.POSITIVE_INFINITY
}
}
];
Cesium.CzmlDataSource.load(data).then(function (ds) {
viewer.dataSources.add(ds);
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.400, 39.852, 26000),
orientation: {
heading: 0,
pitch: Cesium.Math.toRadians(-42),
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.