Corridor Band
Runnable Cesium example: Corridor Band. 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
<!--
示例:沿一条路径铺出走廊带
要点:CorridorGraphics 以折线为中心向两侧扩展宽度,cornerType 决定拐角形状
依赖: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>走廊带道路</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%}
.hud{position:absolute;left:12px;top:12px;z-index:5;background:rgba(23,28,35,.9);
border:1px solid #2a313b;border-radius:6px;padding:9px 12px;font-size:12px;
color:#a2a9b6;max-width:250px}
.hud b{color:#e6e8ec;font-weight:600}
.hud .row{margin-top:6px}
select{font:inherit;font-size:12px;background:#1d232b;color:#cfd6e2;
border:1px solid #343b46;border-radius:4px;padding:2px 4px;width:100%}
input[type=range]{width:100%}
.cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="hud">
<div><b>走廊带</b></div>
<div class="row">宽度 <span id="wVal">130</span> 米</div>
<div class="row"><input id="width" type="range" min="40" max="360" step="10" value="130"></div>
<div class="row">拐角</div>
<div class="row">
<select id="corner">
<option value="ROUNDED">ROUNDED 圆角</option>
<option value="MITERED">MITERED 斜接</option>
<option value="BEVELED">BEVELED 平切</option>
</select>
</div>
</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.sun.show = false;
scene.moon.show = false;
if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;
/* 一条带三个拐弯的路径,全部用经纬度表示 */
var PATH = [
[116.360, 39.930], [116.372, 39.921], [116.381, 39.913],
[116.392, 39.915], [116.401, 39.906], [116.413, 39.900],
[116.425, 39.905]
];
var positions = [];
PATH.forEach(function (p) {
positions.push(Cesium.Cartesian3.fromDegrees(p[0], p[1], 0));
});
/* 外层:半透明路面 */
viewer.entities.add({
corridor: {
positions: positions,
width: 300,
cornerType: Cesium.CornerType.ROUNDED,
material: Cesium.Color.fromCssColorString('#2d3d50').withAlpha(0.75)
}
});
/* 内层:实际走廊带,宽度与拐角可调 */
var band = viewer.entities.add({
corridor: {
positions: positions,
width: 130,
cornerType: Cesium.CornerType.ROUNDED,
material: Cesium.Color.fromCssColorString('#4d9bff').withAlpha(0.62),
outline: true,
outlineColor: Cesium.Color.fromCssColorString('#cfe4ff'),
height: 1
}
});
/* 中心线 */
viewer.entities.add({
polyline: {
positions: positions,
width: 2,
material: new Cesium.PolylineDashMaterialProperty({
color: Cesium.Color.fromCssColorString('#eaf2ff').withAlpha(0.8),
dashLength: 16
}),
clampToGround: true
}
});
document.getElementById('width').addEventListener('input', function () {
document.getElementById('wVal').textContent = this.value;
band.corridor.width = parseInt(this.value, 10);
});
document.getElementById('corner').addEventListener('change', function () {
band.corridor.cornerType = Cesium.CornerType[this.value];
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.393, 39.906, 7800),
orientation: {
heading: Cesium.Math.toRadians(2),
pitch: Cesium.Math.toRadians(-52),
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.