cesium用primitive画图形
时间: 2023-11-21 08:56:22 浏览: 200
使用Cesium的Primitive可以绘制各种形状,包括点、线、多边形等。下面是一个使用Primitive绘制多边形的例子:
```javascript
// 创建多边形的顶点数组
var positions = Cesium.Cartesian3.fromDegreesArray([
-72.0, 40.0,
-70.0, 35.0,
-75.0, 30.0,
-70.0, 30.0,
-68.0, 40.0
]);
// 创建多边形的颜色数组
var colors = [];
for (var i = 0; i < positions.length / 3; i++) {
colors.push(1.0);
colors.push(0.0);
colors.push(0.0);
colors.push(1.0);
}
// 创建多边形的索引数组
var indices = [0,1, 2, 0, 2, 3, 0, 3, 4];
// 创建多边形的Primitive
var polygon = new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy(positions),
vertexFormat: Cesium.VertexFormat.POSITION_AND_COLOR
}),
attributes: {
color: new Cesium.ColorGeometryInstanceAttribute.fromColors(colors)
},
indices: indices
}),
appearance: new Cesium.PerInstanceColorAppearance({
flat: true,
translucent: false
})
});
// 将多边形添加到场景中
viewer.scene.primitives.add(polygon);
```
阅读全文
相关推荐

















