如何获取cesium上多边行的可视区域的经纬度
时间: 2023-05-30 07:06:28 浏览: 524
Cesium绘制区域面积测量
要获取Cesium上多边形的可视区域的经纬度,可以使用Cesium的Camera对象和BoundingSphere对象。以下是一个示例代码:
```javascript
//获取多边形的BoundingSphere对象
var boundingSphere = Cesium.BoundingSphere.fromPoints(polygonPositions);
//获取当前Camera的视图范围
var camera = viewer.camera;
var frustum = new Cesium.PerspectiveFrustum();
frustum.aspectRatio = camera.frustum.aspectRatio;
frustum.fov = camera.frustum.fov;
frustum.near = camera.frustum.near;
frustum.far = camera.frustum.far;
var cullingVolume = new Cesium.CullingVolume(frustum, camera.positionWC);
//获取多边形的可视区域
var visible = cullingVolume.computeVisibility(boundingSphere);
//如果多边形在可视范围内,则获取其经纬度范围
if (visible !== Cesium.Intersect.OUTSIDE) {
var cartographic = Cesium.Rectangle.fromBoundingSphere(boundingSphere);
var west = Cesium.Math.toDegrees(cartographic.west);
var south = Cesium.Math.toDegrees(cartographic.south);
var east = Cesium.Math.toDegrees(cartographic.east);
var north = Cesium.Math.toDegrees(cartographic.north);
console.log(west, south, east, north);
}
```
在代码中,首先通过多边形的顶点位置创建一个BoundingSphere对象,然后获取当前Camera的视图范围,将其与BoundingSphere对象进行比较,从而确定多边形是否在可视范围内。如果多边形在可视范围内,则使用Rectangle.fromBoundingSphere()方法获取其经纬度范围,并将其转换为度数并打印输出。
阅读全文