当前位置:   article > 正文

《Cesium 进阶知识点》- 计算多个 ImageryLayer 的最大包围盒_cesium 包围盒

cesium 包围盒

需求说明

场景中加载了多个 Cesium.ImageryLayer,计算它们的最大包围盒并定位。

计算说明

  • 代码 6 和 14 行,注意循环是从 1 开始;
  • 代码 23 - 29 行,西,南 取最小,东,北 取最大。参考图如下;
  • 代码 33 行,注意要加上关键字 new;
  1. /**
  2. * @param {Array} layers,Cesium.ImageryLayer 对象数组
  3. */
  4. function flyToMaxRect(layers) {
  5. // 第一个开始,赋初始值
  6. let firstLayer = layers[0];
  7. let firstR = firstLayer._rectangle;
  8. let west = firstR.west;
  9. let south = firstR.south;
  10. let east = firstR.east;
  11. let north = firstR.north;
  12. // 注意 i 从 1 开始,计算最大包围盒
  13. for (let i = 1; i < layers.length; i++) {
  14. let layer = layers[i];
  15. // {
  16. // "west": 1.9989153146743774,
  17. // "south": 0.5340262055397034,
  18. // "east": 2.0006167888641357,
  19. // "north": 0.5354444980621338
  20. // }
  21. // Cesium.Rectangle 对象,注意单位是 弧度
  22. let r = layer._rectangle;
  23. // 西,南 取最小
  24. west = west > r.west ? r.west : west;
  25. south = south > r.south ? r.south : south;
  26. // 东,北 取最大
  27. east = r.east > east ? r.east : east;
  28. north = r.north > north ? r.north : north;
  29. }
  30. // 定位
  31. viewer.camera.flyTo({
  32. destination : new Cesium.Rectangle(west, south, east, north)
  33. });
  34. }

范围说明,详见 Cesium.ImageryLayer 对象

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/99744
推荐阅读
相关标签
  

闽ICP备14008679号