我们用typescript 实现一个地球自转工具类、
```javascript
/**
地球自转
/ export class GlobalRotate{ private viewer: any = null; private delta = 0; private delayTime: any = null; constructor(_viewer: any) { this.viewer = _viewer; } /*
开启地图自转效果/和时钟无关
@paramdelta 每帧旋转的角度,正负值代表方向
@paramdelay 执行多少时间后结束,单位:ms 0为不自动结束
@paramcb 结束后执行的回调函数
/ public start(delta: number = 0.006, delay: number = 0, cb: any = null) { this.stop(); this.delta = delta; this.viewer.scene.postUpdate.addEventListener(this.onTickCallback, this); if (delay > 0) { this.delayTime = setTimeout(() => { this.stop(); cb && cb(); }, delay); } } /*
停止自转
*/
public stop() {
this.viewer.clock.multiplier = 1; //速度
this.viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
this.viewer.scene.postUpdate.removeEventListener(this.onTickCallback, this);
this.viewer.scene.postUpdate.removeEventListener(this.onPostUpdate, this);
clearTimeout(this.delayTime);
}
/**
* 开启地图自转效果/和时钟无关
*@parammultiplier clock的multiplier属性
*@paramdelay 执行多少时间后结束,单位:ms 0为不自动结束
更多参考 https://xiaozhuanlan.com/topic/2063589174
网友评论