AroundView.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * @Description: 相机绕地旋转
  3. * @Version: 1.0
  4. * @Author: joy
  5. * @Date: 2023-04-11 21:42:26
  6. * @LastEditors: joy
  7. * @LastEditTime: 2023-04-12 16:32:25
  8. */
  9. class AroundView {
  10. constructor(viewer, amount) {
  11. this._viewer = viewer;
  12. this._amount = amount;
  13. }
  14. // 绑定事件
  15. _bindEvent() {
  16. let _self = this;
  17. this._viewer.clock.onTick.addEventListener(this._aroundView, this);
  18. //监听点击事件
  19. var handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
  20. handler.setInputAction(function(click) {
  21. _self.stop();
  22. }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
  23. }
  24. // 解除绑定
  25. _unbindEvent() {
  26. this._viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
  27. this._viewer.clock.onTick.removeEventListener(this._aroundView, this);
  28. }
  29. // 开始
  30. start() {
  31. this._viewer.clock.shouldAnimate = true;
  32. this._unbindEvent();
  33. this._bindEvent();
  34. return this;
  35. }
  36. // 停止
  37. stop() {
  38. this._unbindEvent();
  39. return this;
  40. }
  41. // 相机绕地旋转函数
  42. _aroundView() {
  43. let heading = this._viewer.camera.heading;
  44. let pitch = this._viewer.camera.pitch;
  45. let roll = this._viewer.camera.roll;
  46. heading += Cesium.Math.toRadians(this._amount);
  47. if (heading >= Math.PI * 2 || heading <= -Math.PI * 2) {
  48. heading = 0;
  49. }
  50. this._viewer.camera.setView({
  51. orientation: {
  52. heading: heading,
  53. pitch: pitch,
  54. roll: roll
  55. }
  56. })
  57. }
  58. }
  59. export default AroundView