效果
// 监听相机的改变 用来设置相机飞行到哪里
window.viewer.camera.changed.addEventListener(function () {
// 当相机改变时,获取相机的参数
let camera = window.viewer.camera;
// 获取当前摄像机的位置(经纬度)
let cameraPosition = window.viewer.camera.position;
let cartographic = Cesium.Cartographic.fromCartesian(cameraPosition);
let longitude = Cesium.Math.toDegrees(cartographic.longitude);
let latitude = Cesium.Math.toDegrees(cartographic.latitude);
let height = cartographic.height;
console.log("这是camera", camera);
console.log("这是longitude", longitude);
console.log("这是latitude", latitude);
console.log("这是height", height);
});
flyCamera(objects) {
let {
x = 112.582590,
y = 31.170320,
z = 500,
// 垂直方向
heading = Cesium.Math.toRadians(0),
pitch = Cesium.Math.toRadians(-90),
roll = 0,
} = objects || {}
this.viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(x, y, z),
orientation: {
heading,
pitch,
roll,
}
});
}
window.mapCeFun.flyCamera({
//这里的xy则是上面打印的经纬度的值,z就是height的值
x: 112.59652732156285,
y: 31.11775227001935,
z: 47.195746815815795,
//这下面三个值直接用上面打印的camera.的heading,pitch,roll直接就是弧度
heading: 0.002975580802861977,
pitch: -0.2504325212185343,
roll: 1.4109491353053727e-8,
});