heading (方位角),pitch (倾角),roll(旋转角), range(距离中心距离)
let opt = {
position: [117.74447781803329, 30.663937066156883, 225.23452906567712],
heading: 4.7124621698699425,
pitch: -0.17465633785744084,
roll: 6.283185197024551,
duration:5
};
let entity = new Cesium.Entity({
name: "飞行",
position: Cesium.Cartesian3.fromDegrees(
opt.position[0],opt.position[1],opt.position[2]
),
point: {
pixelSize: 10,
color: Cesium.Color.WHITE.withAlpha(0),
outlineColor: Cesium.Color.WHITE.withAlpha(0),
outlineWidth: 0
}
});
viewer.entities.add(entity);
1.viewer.zoomTo
viewer.zoomTo(entity ,{
heading:opt.heading,
pitch:opt.pitch,
range:opt.range
})
//或者 viewer.zoomTo(viewer.entities)
2.viewer.flyTo
viewer
.flyTo(entity, {
offset: {
heading: opt.heading,
pitch:opt.pitch,
roll: opt.roll
},
duration: opt.duration // 设置飞行持续时间,默认会根据距离来计算
})
.then(e => {
func & func();
});
3.viewer.camera.flyTo
viewer.camera.flyTo 也是通过动画的方式转移到某个位置, 参数比viewer.flyTo要多
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(107.0, 40.0, 5000000), //摄像机的最终位置
duration: 3, //飞行所用时间
maximumHeight: 20000, //飞行高峰时的最大高度。
pitchAdjustHeight: 1500, //如果摄像机的飞行高于此值,请调整俯仰航向以降低俯仰,并将地球保持在视野中
orientation: {
heading: opt.heading, //方位角
pitch: opt.pitch, //倾角
roll: opt.roll //旋转角
}
});
4.viewer.camera.lookAt
立即定位到某个位置, 而且相机锁住此位置。
var center = Cesium.Cartesian3.fromDegrees(-107,40,0)//目标位置
viewer.camera.lookAt(center, new Cesium.Cartesian3(x,x,x);//三个参数数字分别是:方位角,倾角,俯角
5.viewer.camera.setView
将摄像机定位到某个位置
viewer.camera.setView({
destination : Cesium.Cartesian3.fromDegrees(107.0, 40.0, 5000000),//相机位置
orientation: {
heading :opt.heading, //方位角
pitch : opt.pitch, //倾角
roll : opt.roll //旋转角
}
});
附:相机参数获取
//将坐标转化为84坐标
get84Cood(positon) {
let zb = Cesium.Cartographic.fromCartesian(positon);
let lat = Cesium.Math.toDegrees(zb.latitude);
let lon = Cesium.Math.toDegrees(zb.longitude);
let height = zb.height;
return {
lon,
lat,
height
};
}
//获取相机参数
getCamera() {
let p = this.get84Cood(viewer.camera.position);
let position = [p.lon, p.lat, p.height];
return {
position,
heading: viewer.camera.heading,
pitch: viewer.camera.pitch,
roll: viewer.camera.roll
};
}