| | |
| | | const isColorRenderEnabled = ref(false); // 假设这是你的颜色渲染开关状态 |
| | | const isWaterPrimitiveCreated = ref(false); |
| | | let playInterval = null; |
| | | let timeStepInfo = null; |
| | | let rainTotalInfo = ([]); |
| | | const isRainEnabled = ref(false); |
| | | const rainParams = reactive({ |
| | |
| | | const rainfallList = data.rainfalls; |
| | | console.log("最终的 rainfallList:", rainfallList); |
| | | rainTotalInfo.value = rainfallList |
| | | calculateTimeStep(rainTotalInfo.value) |
| | | // 使用示例 |
| | | timeStepInfo = calculateTimeStep(rainTotalInfo.value); |
| | | |
| | | // 提取 intensity 值 |
| | | rainFallValues.value = rainfallList.map((r) => r.intensity); |
| | |
| | | } |
| | | } |
| | | // 默认无雨状态 |
| | | |
| | | |
| | | return { name: "无雨", size: 0.3, speed: 10, density: 10, color: "#F0F8FF" }; |
| | | } |
| | | // 根据播放进度更新天气效果(已优化) |
| | | let lastUsedIndex = -1; // 缓存上一次使用的索引,防止重复更新 |
| | | let lastRainValue = null; |
| | | |
| | | function calculateTimeStep(dataArray) { |
| | | if (!dataArray || dataArray.length < 2) { |
| | | console.warn('数据不足,无法计算时间步长'); |
| | | return null; |
| | | } |
| | | |
| | | // 解析时间字符串为 Date 对象 |
| | | function parseTime(timeStr) { |
| | | return new Date(timeStr.replace(' ', 'T')); // 兼容 ISO 格式 |
| | | } |
| | | |
| | | const firstTime = parseTime(dataArray[0].time); |
| | | const secondTime = parseTime(dataArray[1].time); |
| | | |
| | | // 计算时间差(毫秒) |
| | | const diffMs = Math.abs(secondTime - firstTime); |
| | | |
| | | // 转换为小时数(保留小数) |
| | | let timeStepHours = diffMs / (1000 * 60 * 60); // 毫秒 -> 小时 |
| | | |
| | | // 可选:遍历所有相邻项检查是否一致 |
| | | for (let i = 1; i < dataArray.length - 1; i++) { |
| | | const current = parseTime(dataArray[i].time); |
| | | const next = parseTime(dataArray[i + 1].time); |
| | | const step = Math.abs(next - current) / (1000 * 60 * 60); // 毫秒 -> 小时 |
| | | if (Math.abs(step - timeStepHours) > 0.01) { |
| | | console.warn(`在索引 ${i} 处发现了不同的时间步长: ${step.toFixed(2)} 小时`); |
| | | } |
| | | } |
| | | |
| | | return timeStepHours; |
| | | } |
| | | |
| | | function updateWaterColorByTime() { |
| | | if (!rainTotalInfo.value || rainTotalInfo.value.length === 0) return; |
| | | const progress = currentTime.value / duration.value; |
| | |
| | | const currentTotal = currentData.total; |
| | | const nextTotal = nextData.total; |
| | | const total = currentTotal + (nextTotal - currentTotal) * alpha; |
| | | console.log(`计算得到的时间步长为: ${timeStepInfo} 小时`); |
| | | // 根据 total 设置颜色 |
| | | let color = '#D4F2E7'; // 默认蓝色 |
| | | |
| | | if (total >= 150) { |
| | | color = '#663300'; // 黄 - 大雨 |
| | | color = '#663300'; |
| | | } else if (total >= 125) { |
| | | color = '#B26633'; // 黄绿 - 中雨 |
| | | color = '#B26633'; |
| | | } else if (total >= 100) { |
| | | color = '#CC9966'; // 绿 - 中雨 |
| | | color = '#CC9966'; |
| | | } else if (total >= 75) { |
| | | color = '#CCE5FF'; // 青绿 - 小雨 |
| | | color = '#CCE5FF'; |
| | | } else if (total >= 50) { |
| | | color = '#99CCFF'; // 天蓝 - 小雨 |
| | | color = '#99CCFF'; |
| | | } else if (total >= 25) { |
| | | color = '#66B3FF'; // 浅蓝 - 微量 |
| | | color = '#66B3FF'; |
| | | } |
| | | // console.log(`当前 total: ${total.toFixed(2)}, 颜色: ${color}`); |
| | | // updateWaterColor(color) |