PolylineGeometry(折线几何体)是一个用于在Cesium中创建折线实体的几何体,它由N个顶点(Cartesian3类型)组成。
有两种构造函数可用于创建折线几何体:
PolylineGeometry(options)
PolylineGeometry.fromPositions(positions, [options])
PolylineGeometry.createGeometry(polylineGeometry)
创建折线几何体的实例。
以下示例代码演示了如何创建一个具有不同线宽和颜色的折线几何体:
var viewer = new Cesium.Viewer('cesiumContainer');
var positions = [
Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
Cesium.Cartesian3.fromDegrees(-82.50572, 35.18593),
Cesium.Cartesian3.fromDegrees(-99.77759, 32.76727),
Cesium.Cartesian3.fromDegrees(-106.01083, 39.80355),
Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)
];
// 创建折线几何体
var polylineGeometry = new Cesium.PolylineGeometry({
positions : positions,
width : 5.0,
colors : [
Cesium.Color.RED,
Cesium.Color.GREEN,
Cesium.Color.BLUE,
Cesium.Color.YELLOW
]
});
viewer.scene.primitives.add(new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: Cesium.PolylineGeometry.createGeometry(polylineGeometry),
attributes: {
color: Cesium.PolylineColorAppearance.VERTEX_COLOR
}
}),
appearance: new Cesium.PolylineColorAppearance()
}));