Cesium中控制相机Camera的方法
常规的相机视角查看
viewer.camera.flyTo({
camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(103.19, 30.25, 5000.0),
duration: 1,
orientation: {
heading: Cesium.Math.toRadians(),
pitch: Cesium.Math.toRadians(),
roll: Cesium.Math.toRadians()
},
});
- setViewer: 三维球立即转到对应的视角和位置上
- flyTo: 通过转动的动画,三维球转到对应的视角和位置上
- lookAt: 直接到对应的视角和位置上
1、第一种方式setView
// Catesian3 方式
viewer.camera.setView({
// fromDegrees()方法,将经纬度和高程转换为世界坐标
destination:Cesium.Cartesian3.fromDegrees(117.48,30.67,15000.0), //设置位置
orientation:{
// 方向
heading:Cesium.Math.toRadians(90,0),
// 视角、倾斜角度
pitch:Cesium.Math.toRadians(-90),
roll:0.0
}
})
// rectangle方法
view.camera.setView({
destination: Cesium.Rectangle.fromDegrees(0.0,20.0,10.0,30.0),//west,south,east,north
orientation: {
heading: Cesium.Math.toRadians(20.0),//方向
pitch: Cesium.Math.toRadians(-90.0),// 亲斜角度
roll: 0
}
})
2、第二种方式 flyTo
viewer.camera.flyTo({
// fromDegrees()方法,将经纬度和高程转换为世界坐标
destination:Cesium.Cartesian3.fromDegrees(103.48,30.55,15000.0), // 设置位置
orientation:{
// 指向
heading:Cesium.Math.toRadians(90,0),
// 视角
pitch:Cesium.Math.toRadians(-90),
roll:0.0
},
duration: 5, 设置飞行时间,默认会根据距离来计算
complete: function (){
//到达位置后执行的回调函数
},
cancle: function() {
//如多取消飞行则会调用此函数
},
pitchAdjustHeight: -90, // 如果摄像机飞越高于该值,则调整俯仰的俯仰角度,并将地球保持在视口中
maximumHeight: 5000,// 相机最大飞行高度
flyOverLongitude:100, // 如果到达目的地有2种方式,设置具体值后会强制选择方向飞过这个经度
})
3、第三种方式 lookAt
var center = Cesium.Cartesian3.fromDegrees(103.44455,30.0444);//camera视野中心点坐标
var heading = Cesium.Math.toRadians(0.0);
var pitch = Cesium.Math.toRadians(-90.0);
var range = 5000.0;
viewer.camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, range))
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);