一、viewer的flyTo内部调用的是camera的相关定位方法,针对不同的定位对象,计算出合适的位置和相机视角。viewer可以定位到entity、dataSource、Cesium3DTileset、ImageLayer等。
var rect = [116.490401, 39.964771, 116.499623, 39.977102];var heading = Cesium.Math.toRadians(0.0);var pitch = Cesium.Math.toRadians(-45.0);var roll = Cesium.Math.toRadians(0);var range = 0;
var entity = viewer.entities.add({rectangle: {coordinates: Cesium.Rectangle.fromDegrees(...rect),material: Cesium.Color.GREEN.withAlpha(1.0),height: 10.0,outline: false,},});viewer.flyTo(entity, {duration: 0.5,offset: new Cesium.HeadingPitchRange(heading, pitch, range),});
二、camera的flyTo定位到某一位置或者Rectangle,默认是90度pitch,当使用camera加上pitch定位时,定位的位置并不在屏幕中心位置,有较大误差。
viewer.camera.flyTo({duration: 0.5,destination: Cesium.Rectangle.fromDegrees(...rect),// 加上pitch之后有较大偏差,不加pitch就是90度pitch// orientation: new Cesium.HeadingPitchRoll(heading, pitch, roll),});