12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /*
- * @Description: 相机绕地旋转
- * @Version: 1.0
- * @Author: joy
- * @Date: 2023-04-11 21:42:26
- * @LastEditors: joy
- * @LastEditTime: 2023-04-12 16:32:25
- */
- class AroundView {
- constructor(viewer, amount) {
- this._viewer = viewer;
- this._amount = amount;
- }
- // 绑定事件
- _bindEvent() {
- let _self = this;
-
- this._viewer.clock.onTick.addEventListener(this._aroundView, this);
- //监听点击事件
- var handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas);
- handler.setInputAction(function(click) {
- _self.stop();
- }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
- }
- // 解除绑定
- _unbindEvent() {
- this._viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
- this._viewer.clock.onTick.removeEventListener(this._aroundView, this);
- }
- // 开始
- start() {
- this._viewer.clock.shouldAnimate = true;
- this._unbindEvent();
- this._bindEvent();
- return this;
- }
- // 停止
- stop() {
- this._unbindEvent();
- return this;
- }
- // 相机绕地旋转函数
- _aroundView() {
- let heading = this._viewer.camera.heading;
- let pitch = this._viewer.camera.pitch;
- let roll = this._viewer.camera.roll;
- heading += Cesium.Math.toRadians(this._amount);
- if (heading >= Math.PI * 2 || heading <= -Math.PI * 2) {
- heading = 0;
- }
- this._viewer.camera.setView({
- orientation: {
- heading: heading,
- pitch: pitch,
- roll: roll
- }
- })
- }
- }
- export default AroundView
|