思路:
1、获取当前相机位置 P1
2、获取屏幕中心点位置 P2
3、计算亮点的经度差和纬度差
4、飞行的目标减去dx、dy
注: 当飞行前后高度变化时,此方法不适用,需另外计算比例。
var p = viewer.camera._positionCartographic
var left = $('#cesiumContainer').offset().left
var top = $('#cesiumContainer').offset().top
var width = parseFloat($('#cesiumContainer').css('width').split('px')[0])
var height = parseFloat($('#cesiumContainer').css('height').split('px')[0])
var x = left + width / 2
var y = top + height / 2
var _center = new Cesium.Cartesian2(x, y);
var __center = viewer.scene.globe.pick(viewer.camera.getPickRay(_center), viewer.scene);
var center = viewer.scene.globe.ellipsoid.cartesianToCartographic(__center);
dx = (center.longitude - p.longitude) / Math.PI * 180
dy = (center.latitude - p.latitude) / Math.PI * 180
var heading = viewer.camera.heading
var pitch = viewer.camera.pitch
var height = p.height
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.4997625442 - dx, 39.9843650681 - dy, height ),
orientation: {
heading: heading ,
pitch: pitch
}
})