cesium绘制区域边界
时间: 2023-11-05 09:00:24 浏览: 176
要在Cesium中绘制区域边界,可以使用以下步骤:
1. 创建一个Polygon实例,设置其位置和边界点坐标。
```javascript
let polygon = viewer.entities.add({
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([
-115.0, 37.0,
-115.0, 32.0,
-107.0, 33.0,
-102.0, 31.0,
-102.0, 35.0
]),
material: Cesium.Color.RED.withAlpha(0.5),
outline: true,
outlineWidth: 2,
outlineColor: Cesium.Color.BLACK
}
});
```
2. 将Polygon实例添加到场景中。
```javascript
viewer.entities.add(polygon);
```
3. 设置Polygon实例的材质和边框属性。
```javascript
polygon.polygon.material = Cesium.Color.RED.withAlpha(0.5);
polygon.polygon.outline = true;
polygon.polygon.outlineWidth = 2;
polygon.polygon.outlineColor = Cesium.Color.BLACK;
```
4. 通过设置Polygon实例的高度来使其浮在地球表面上。
```javascript
polygon.polygon.height = 0;
```
完整的示例代码如下:
```javascript
let viewer = new Cesium.Viewer("cesiumContainer");
let polygon = viewer.entities.add({
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([
-115.0, 37.0,
-115.0, 32.0,
-107.0, 33.0,
-102.0, 31.0,
-102.0, 35.0
]),
material: Cesium.Color.RED.withAlpha(0.5),
outline: true,
outlineWidth: 2,
outlineColor: Cesium.Color.BLACK,
height: 0
}
});
viewer.entities.add(polygon);
```
阅读全文