// Create the viewer.
var viewer = new Cesium.Viewer("cesiumContainer",{
terrainProvider: new Cesium.createWorldTerrain({
requestWaterMask: true,
requestVertexNormals: true,
})});
var scene = viewer.scene;
// Example 1: Draw the outline of a corridor on the globe surface.
//在地球表面绘制走廊的轮廓
// Create the corridor outline geometry.
//创建道路轮廓几何图形
var corridorOutlineGeometry = new Cesium.CorridorOutlineGeometry({
positions: Cesium.Cartesian3.fromDegreesArray([
-100.0, 40.0,
-105.0, 40.0,
-105.0, 35.0,
]),
width: 200000.0,
});
// Create the geometry instance.
//创建几何体实例
var corridorOutline = new Cesium.GeometryInstance({
geometry: corridorOutlineGeometry,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
Cesium.Color.RED
),
},
});
// Example 2: Draw the outline of an extruded corridor.
// Create the corridor geometry. To extrude, specify the
// height of the geometry with the extrudedHeight option.
corridorOutlineGeometry = new Cesium.CorridorOutlineGeometry({
positions: Cesium.Cartesian3.fromDegreesArray([
-90.0, 40.0,
-95.0, 40.0,
-95.0,35.0,
]),
width: 200000.0,
//确定角点的样式。
//NONE 与椭圆表面不符的直线
//GEODESIC 遵循测地路径
//RHUMB 遵循大黄蜂或恶魔般的道路
//MITERED 直角
cornerType: Cesium.CornerType.GEODESIC,
extrudedHeight: 100000.0,
});
// Create the geometry instance.
var extrudedCorridorOutline = new Cesium.GeometryInstance({
geometry: corridorOutlineGeometry,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
Cesium.Color.WHITE
),
},
});
// Add both corridor outline instances to primitives
scene.primitives.add(
new Cesium.Primitive({
//要渲染的几何实例-或单个几何实例。
geometryInstances: [corridorOutline, extrudedCorridorOutline],
//用于渲染图元的外观。
appearance: new Cesium.PerInstanceColorAppearance({
//当 true 时,片段着色器中将使用平面阴影,这意味着不考虑照明。
flat: true,
renderState: {
lineWidth: Math.min(2.0, scene.maximumAliasedLineWidth),
},
}),
})
);
结果:

原文:https://www.cnblogs.com/191080438qq/p/14767465.html