计算高度
function getHeightByLevel(level) {
var A = 40487.57
var B = 0.00007096758
var C = 91610.74
var D = -40467.74
return Math.pow((A - D) / (level - D) - 1, 1 / B) * C
}
两种飞行方式
第一种,直接cesium.flyTo或cesium.camera.flyTo
第二种,根据一系列的经纬度坐标点,取中心范围值来飞行,cesium.camera.flyToBoundingSphere
function flyTo(option) {
return new Promise(function (resolve, reject) {
var destination = option.destination
if (!option.objects) {
if (option.position) {
option.position.forEach((x, index) => {
option.position[index] = parseFloat(x)
})
if (option.position.length == 2) {
option.position.push(0)
}
if (!isNaN(option.level)) {
option.position[2] = getHeightByLevel(option.level)
}
if (!isNaN(option.height)) {
option.position[2] = option.height
}
destination = Cesium.Cartesian3.fromDegrees(
option.position[0],
option.position[1],
option.position[2],
)
}
var config = {
destination: destination,
duration: isNaN(option.duration) ? 3 : option.duration,
complete: function () {
resolve()
},
easingFunction: option.easingFunction
? option.easingFunction
: Cesium.EasingFunction.EXPONENTIAL_IN_OUT,
}
if (option.up && option.direction) {
config.orientation = {
direction: option.direction,
up: option.up,
}
} else if (!isNaN(option.heading) && !isNaN(option.pitch) && !isNaN(option.roll)) {
config.orientation = {
heading: option.heading,
pitch: option.pitch,
roll: option.roll,
}
}
window._cesium.camera.flyTo(config)
} else {
let config = {
duration: isNaN(option.duration) ? 3 : option.duration,
}
if (!isNaN(option.heading) && !isNaN(option.pitch) && !isNaN(option.distance)) {
config.offset = new Cesium.HeadingPitchRange(option.heading, option.pitch, option.distance)
}
if (Array.isArray(option.objects)) {
window._cesium.flyTo(option.objects, config).then(function () {
resolve()
})
} else if (option.objects instanceof Cesium.BoundingSphere) {
config.complete = function () {
resolve()
}
window._cesium.camera.flyToBoundingSphere(option.objects, config)
}
}
})
}