cesium shp居中
时间: 2023-09-04 12:09:22 浏览: 94
cesium 加载shp原文件
要将Cesium中的SHP文件居中,可以使用以下代码:
```javascript
var dataSource = new Cesium.GeoJsonDataSource();
var promise = dataSource.load('./path/to/your/file.shp');
promise.then(function() {
var entities = dataSource.entities.values;
var west = Number.MAX_VALUE;
var south = Number.MAX_VALUE;
var east = Number.MIN_VALUE;
var north = Number.MIN_VALUE;
entities.forEach(function(entity) {
var rectangle = entity.rectangle;
if (rectangle) {
west = Math.min(west, rectangle.west);
south = Math.min(south, rectangle.south);
east = Math.max(east, rectangle.east);
north = Math.max(north, rectangle.north);
}
});
var rectangle = Cesium.Rectangle.fromDegrees(west, south, east, north);
var center = Cesium.Rectangle.center(rectangle);
viewer.camera.flyTo({
destination: center,
duration: 3
});
});
```
这个代码会加载SHP文件并获取其所有实体的边框范围,然后计算出中心点,并使用Cesium的`flyTo`方法将相机移动到该点。这样,SHP文件就会居中显示在Cesium场景中。
阅读全文