diff --git a/src/app/OlMap/Controls/Timeline.tsx b/src/app/OlMap/Controls/Timeline.tsx index 0e8ebb2..1953e2f 100644 --- a/src/app/OlMap/Controls/Timeline.tsx +++ b/src/app/OlMap/Controls/Timeline.tsx @@ -426,6 +426,41 @@ const Timeline: React.FC = ({ } }, [map, handlePause]); + const clearCacheAndRefetch = (date: Date, timeInMinutes: number) => { + const dateStr = date.toISOString().split("T")[0]; + + const clearCache = ( + cacheRef: React.MutableRefObject> + ) => { + const cacheKeys = Array.from(cacheRef.current.keys()); + cacheKeys.forEach((key) => { + const keyParts = key.split("_"); + const cacheDate = keyParts[0].split("T")[0]; + const cacheTimeStr = keyParts[0].split("T")[1]; + + if (cacheDate === dateStr && cacheTimeStr) { + const [hours, minutes] = cacheTimeStr.split(":"); + const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes); + + if (cacheTimeInMinutes >= timeInMinutes) { + cacheRef.current.delete(key); + } + } + }); + }; + + clearCache(nodeCacheRef); + clearCache(linkCacheRef); + + // 重新获取当前时刻的新数据 + fetchFrameData( + currentTimeToDate(selectedDate, currentTime), + junctionText, + pipeText, + schemeName + ); + }; + const handleForceCalculate = async () => { if (!NETWORK_NAME) { open?.({ @@ -467,43 +502,8 @@ const Timeline: React.FC = ({ ); if (response.ok) { - // 清空当天当前时刻及之后的缓存 - const currentDateStr = calculationDateStr; - const currentTimeInMinutes = calculationTime; - - // 清空node缓存 - const nodeCacheKeys = Array.from(nodeCacheRef.current.keys()); - nodeCacheKeys.forEach((key) => { - const keyParts = key.split("_"); - const cacheDate = keyParts[0].split("T")[0]; - const cacheTimeStr = keyParts[0].split("T")[1]; - - if (cacheDate === currentDateStr && cacheTimeStr) { - const [hours, minutes] = cacheTimeStr.split(":"); - const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes); - - if (cacheTimeInMinutes >= currentTimeInMinutes) { - nodeCacheRef.current.delete(key); - } - } - }); - - // 清空link缓存 - const linkCacheKeys = Array.from(linkCacheRef.current.keys()); - linkCacheKeys.forEach((key) => { - const keyParts = key.split("_"); - const cacheDate = keyParts[0].split("T")[0]; - const cacheTimeStr = keyParts[0].split("T")[1]; - - if (cacheDate === currentDateStr && cacheTimeStr) { - const [hours, minutes] = cacheTimeStr.split(":"); - const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes); - - if (cacheTimeInMinutes >= currentTimeInMinutes) { - linkCacheRef.current.delete(key); - } - } - }); + // 清空当天当前时刻及之后的缓存并重新获取数据 + clearCacheAndRefetch(calculationDate, calculationTime); open?.({ type: "success",