12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /*
- * @Description: 相机绕点旋转
- * @Version: 1.0
- * @Author: joy
- * @Date: 2023-04-11 21:42:26
- * @LastEditors: joy
- * @LastEditTime: 2023-04-12 16:32:25
- */
- class AroundPoint {
- constructor(viewer, amount, position) {
- this._viewer = viewer;
- this._amount = amount;
- this._position = position;
- this._range = this._viewer.camera.positionCartographic.height;
- }
- _bindEvent() {
- let _self = this;
- this._viewer.clock.onTick.addEventListener(this._aroundPoint, 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._aroundPoint, this);
- }
- start() {
- this._viewer.clock.shouldAnimate = true;
- this._unbindEvent();
- this._bindEvent();
- return this;
- }
- stop() {
- this._unbindEvent();
- return this;
- }
- // 相机绕点旋转函数
- _aroundPoint() {
- let heading = this._viewer.camera.heading;
- let pitch = this._viewer.camera.pitch;
- let range = this._range;
- heading += Cesium.Math.toRadians(this._amount);
- if (heading >= Math.PI * 2 || heading <= -Math.PI * 2) {
- heading = 0;
- }
- this._viewer.camera.lookAt(
- this._position,
- new Cesium.HeadingPitchRange(
- heading,
- pitch,
- range,
- )
- )
- }
- }
- export default AroundPoint
|