cesium用primitive画线
时间: 2023-11-21 07:56:21 浏览: 224
以下是使用Cesium的Primitive绘制线的示例代码:
```javascript
// 创建Cesium Viewer对象
var viewer = new Cesium.Viewer('cesiumContainer');
// 创建一个PrimitiveCollection对象
var primitives = new Cesium.PrimitiveCollection();
viewer.scene.primitives.add(primitives);
// 定义线的顶点坐标
var positions = Cesium.Cartesian3.fromDegreesArray([
-75, 35,
-125, 35,
-125, 65,
-75, 65,
-75, 35
]);
// 创建一个Geometry对象
var geometry = new Cesium.PolylineGeometry({
positions: positions,
width: 5.0,
vertexFormat: Cesium.VertexFormat.ALL
});
// 创建一个Appearance对象
var appearance = new Cesium.PolylineMaterialAppearance({
material: Cesium.Material.fromType('Color', {
color: Cesium.Color.RED
})
});
// 创建一个Primitive对象
var primitive = new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: geometry
}),
appearance: appearance,
asynchronous: false
});
// 将Primitive对象添加到PrimitiveCollection中
primitives.add(primitive);
```
阅读全文