|
|
|
@ -17,41 +17,82 @@ export const useTrajectoryControls = () => { |
|
|
|
}) |
|
|
|
|
|
|
|
// 轨迹播放定时器
|
|
|
|
const trajectoryPlayTimer = ref<number | null>(null) |
|
|
|
// const trajectoryPlayTimer = ref<number | null>(null)
|
|
|
|
|
|
|
|
let animationId: number | null = null |
|
|
|
let lastTime = performance.now() |
|
|
|
|
|
|
|
const run = () => { |
|
|
|
if (!trajectoryPlayState.value.isPlaying) return |
|
|
|
|
|
|
|
const currentTime = performance.now() |
|
|
|
const deltaTime = currentTime - lastTime |
|
|
|
|
|
|
|
if (deltaTime > 1000 / trajectoryPlayState.value.speed) { |
|
|
|
lastTime = currentTime |
|
|
|
|
|
|
|
trajectoryPlayState.value.currentTime += 1000 |
|
|
|
if ( |
|
|
|
trajectoryPlayState.value.endTime && |
|
|
|
trajectoryPlayState.value.currentTime >= trajectoryPlayState.value.endTime |
|
|
|
) { |
|
|
|
trajectoryPlayState.value.currentTime = trajectoryPlayState.value.endTime |
|
|
|
trajectoryPlayState.value.isPlaying = false |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
animationId = requestAnimationFrame(() => run()) |
|
|
|
} |
|
|
|
/** |
|
|
|
* 播放轨迹 |
|
|
|
*/ |
|
|
|
const playTrajectory = () => { |
|
|
|
if (trajectoryPlayTimer.value) { |
|
|
|
window.clearInterval(trajectoryPlayTimer.value) |
|
|
|
// if (trajectoryPlayTimer.value) {
|
|
|
|
// window.clearInterval(trajectoryPlayTimer.value)
|
|
|
|
// }
|
|
|
|
if (animationId) { |
|
|
|
window.cancelAnimationFrame(animationId) |
|
|
|
} |
|
|
|
if (trajectoryPlayState.value.currentTime >= trajectoryPlayState.value.endTime) { |
|
|
|
// 已播放完的重置时间到开始时间
|
|
|
|
trajectoryPlayState.value.currentTime = trajectoryPlayState.value.startTime |
|
|
|
} |
|
|
|
trajectoryPlayState.value.isPlaying = true |
|
|
|
trajectoryPlayTimer.value = window.setInterval(() => { |
|
|
|
trajectoryPlayState.value.currentTime += 1000 * trajectoryPlayState.value.speed |
|
|
|
}, 500) |
|
|
|
run() |
|
|
|
// trajectoryPlayTimer.value = window.setInterval(() => {
|
|
|
|
// trajectoryPlayState.value.currentTime += 1000 * trajectoryPlayState.value.speed
|
|
|
|
// }, 500)
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 暂停轨迹 |
|
|
|
*/ |
|
|
|
const pauseTrajectory = () => { |
|
|
|
if (trajectoryPlayTimer.value) { |
|
|
|
window.clearInterval(trajectoryPlayTimer.value) |
|
|
|
} |
|
|
|
trajectoryPlayTimer.value = null |
|
|
|
// if (trajectoryPlayTimer.value) {
|
|
|
|
// window.clearInterval(trajectoryPlayTimer.value)
|
|
|
|
// }
|
|
|
|
trajectoryPlayState.value.isPlaying = false |
|
|
|
if (animationId) { |
|
|
|
window.cancelAnimationFrame(animationId) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 停止轨迹 |
|
|
|
*/ |
|
|
|
const stopTrajectory = () => { |
|
|
|
if (trajectoryPlayTimer.value) { |
|
|
|
window.clearInterval(trajectoryPlayTimer.value) |
|
|
|
} |
|
|
|
trajectoryPlayTimer.value = null |
|
|
|
// if (trajectoryPlayTimer.value) {
|
|
|
|
// window.clearInterval(trajectoryPlayTimer.value)
|
|
|
|
// }
|
|
|
|
trajectoryPlayState.value.isPlaying = false |
|
|
|
if (animationId) { |
|
|
|
window.cancelAnimationFrame(animationId) |
|
|
|
} |
|
|
|
|
|
|
|
if (trajectoryPlayState.value.startTime) { |
|
|
|
trajectoryPlayState.value.currentTime = trajectoryPlayState.value.startTime |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -81,9 +122,12 @@ export const useTrajectoryControls = () => { |
|
|
|
*/ |
|
|
|
const setTrajectoryTimeRange = (range: { startTime: number; endTime: number }) => { |
|
|
|
// 停止当前播放
|
|
|
|
if (trajectoryPlayTimer.value) { |
|
|
|
window.clearInterval(trajectoryPlayTimer.value) |
|
|
|
trajectoryPlayTimer.value = null |
|
|
|
// if (trajectoryPlayTimer.value) {
|
|
|
|
// window.clearInterval(trajectoryPlayTimer.value)
|
|
|
|
// trajectoryPlayTimer.value = null
|
|
|
|
// }
|
|
|
|
if (animationId) { |
|
|
|
window.cancelAnimationFrame(animationId) |
|
|
|
} |
|
|
|
|
|
|
|
// 更新轨迹播放状态的时间范围
|
|
|
|
@ -123,10 +167,13 @@ export const useTrajectoryControls = () => { |
|
|
|
* 清理轨迹控制器 |
|
|
|
*/ |
|
|
|
const cleanup = () => { |
|
|
|
if (trajectoryPlayTimer.value) { |
|
|
|
window.clearInterval(trajectoryPlayTimer.value) |
|
|
|
// if (trajectoryPlayTimer.value) {
|
|
|
|
// window.clearInterval(trajectoryPlayTimer.value)
|
|
|
|
// }
|
|
|
|
// trajectoryPlayTimer.value = null
|
|
|
|
if (animationId) { |
|
|
|
window.cancelAnimationFrame(animationId) |
|
|
|
} |
|
|
|
trajectoryPlayTimer.value = null |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
|