| | |
| | | ).map((date) => dayjs(date).toDate()) |
| | | ); |
| | | const currentTimeFormatted = computed(() => formatTime(currentTime.value)); |
| | | |
| | | // 播放控制 |
| | | // 播放控制 |
| | | const togglePlay = () => { |
| | | if (!isPlaying.value && currentTime.value >= duration.value) |
| | | currentTime.value = 0; // 如果已经播放完毕,重置时间 |
| | | |
| | | isPlaying.value = !isPlaying.value; |
| | | emit("isPlaying", isPlaying.value); |
| | | |
| | | if (isPlaying.value) { |
| | | startPlayback(); |
| | | if (!isWaterPrimitiveCreated.value) { |
| | |
| | | // 后续播放时调用恢复接口 |
| | | resumeWaterSimulation(); |
| | | } |
| | | |
| | | if (currentTime.value === 0) emit("playbackFinished", false); |
| | | |
| | | // 恢复下雨效果 |
| | | if (isRainEnabled.value) { |
| | | mapUtils.toggleRain(rainParams, true); |
| | |
| | | } else { |
| | | stopPlayback(); |
| | | pauseWaterSimulation(); // 调用暂停接口 |
| | | |
| | | // 停止下雨效果 |
| | | isRainEnabled.value = true; // 保存当前需要下雨的状态 |
| | | setTimeout(() => { |
| | |
| | | console.warn("selectedScheme 或 data 不存在"); |
| | | return; |
| | | } |
| | | |
| | | // 注意:有时 data 可能是一个字符串(例如 JSON 字符串) |
| | | let data = selectedScheme.value.data; |
| | | |
| | | // 如果是字符串,则尝试解析成对象 |
| | | if (typeof data === 'string') { |
| | | try { |
| | |
| | | rainFallValues.value = rainfallList.map(r => r.intensity); |
| | | minRainValue.value = Math.min(...rainFallValues.value); |
| | | maxRainValue.value = Math.max(...rainFallValues.value); |
| | | |
| | | console.log(minRainValue.value, maxRainValue.value, 'min and max rain values'); |
| | | } |
| | | // 定义降雨等级及其对应的视觉参数 |
| | |
| | | // 根据播放进度更新天气效果(已优化) |
| | | let lastUsedIndex = -1; // 缓存上一次使用的索引,防止重复更新 |
| | | let lastRainValue = null; |
| | | |
| | | function updateWeatherByProgress() { |
| | | if (rainFallValues.value.length === 0) return; |
| | | |
| | | console.log(`时间轴总时长: ${duration.value}, 当前时间: ${currentTime.value}`); // 打印时间轴信息 |
| | | |
| | | const progress = currentTime.value / duration.value; |
| | | const floatIndex = progress * (rainFallValues.value.length - 1); |
| | | const index = Math.floor(floatIndex); // 当前索引 |
| | | const nextIndex = Math.min(index + 1, rainFallValues.value.length - 1); // 下一索引 |
| | | |
| | | const currentRain = rainFallValues.value[index]; |
| | | const nextRain = rainFallValues.value[nextIndex]; |
| | | |
| | | // 启用插值(alpha 平滑过渡) |
| | | const alpha = floatIndex - index; |
| | | const rainValue = currentRain + (nextRain - currentRain) * alpha; |
| | | |
| | | // 打印当前处理的雨量数据 |
| | | console.log(`正在处理的雨量数据点: 当前=${currentRain}, 下一个=${nextRain}, 插值后=${rainValue.toFixed(2)}, 索引=${index}`); |
| | | |