Cesium绕点飞行
上代码, 简单点
enableRotation(position, hpr) {
// this.stopRotation()
hpr = hpr || {}
let heading = hpr.heading || Cesium.Math.toDegrees(this.viewer.baseViewer.camera.heading)
const pitch = hpr.pitch || Cesium.Math.toDegrees(this.viewer.baseViewer.camera.pitch)
const range = hpr.range || CesiumUtils.distance(this.viewer.baseViewer.camera.position, position)
let pre = Date.now()
let now
let cur
this._rotationRender = () => {
cur = Date.now()
now = cur - pre
pre = cur
heading = (heading - now / 1000 * this.rotationSpeed) % 360
// 相机移动到指定位置
this.viewer.lookAt(
position,
{
heading, // 平视角
pitch, // 倾斜角
range // 距离中心点距离
}
)
}
// 这里需要你们自己监听渲染器事件
this.viewer.eventManager.addEventListener(EventConstant.RENDER, this._rotationRender)
}
我们用时间控制旋转角度, 这样会让旋转看上去更匀速,
lookAt(position, headingPitchRange) {
if (!position) return
if (position.alt) {
position = CesiumUtils.transformWGS84ToCartesian(position)
} else if (position.x) {
position = new Cesium.Cartesian3(position.x, position.y, position.z)
} else {
console.warn('错误的参数!')
return
}
this.baseViewer.camera.lookAt(
position,
new Cesium.HeadingPitchRange(Cesium.Math.toRadians(headingPitchRange.heading),
Cesium.Math.toRadians(headingPitchRange.pitch),
headingPitchRange.range
)
)
}
无非就是利用lookAt 更改偏航角, 你学废了吗?