赞
踩
场景中加载了多个 Cesium.ImageryLayer,计算它们的最大包围盒并定位。
- /**
- * @param {Array} layers,Cesium.ImageryLayer 对象数组
- */
- function flyToMaxRect(layers) {
- // 第一个开始,赋初始值
- let firstLayer = layers[0];
- let firstR = firstLayer._rectangle;
- let west = firstR.west;
- let south = firstR.south;
- let east = firstR.east;
- let north = firstR.north;
-
- // 注意 i 从 1 开始,计算最大包围盒
- for (let i = 1; i < layers.length; i++) {
- let layer = layers[i];
- // {
- // "west": 1.9989153146743774,
- // "south": 0.5340262055397034,
- // "east": 2.0006167888641357,
- // "north": 0.5354444980621338
- // }
- // Cesium.Rectangle 对象,注意单位是 弧度
- let r = layer._rectangle;
- // 西,南 取最小
- west = west > r.west ? r.west : west;
- south = south > r.south ? r.south : south;
- // 东,北 取最大
- east = r.east > east ? r.east : east;
- north = r.north > north ? r.north : north;
- }
- // 定位
- viewer.camera.flyTo({
- destination : new Cesium.Rectangle(west, south, east, north)
- });
- }

范围说明,详见 Cesium.ImageryLayer 对象
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。