From 687749f431b0a869f231a136c595d0e07d158034 Mon Sep 17 00:00:00 2001 From: tsuki Date: Tue, 26 Aug 2025 18:48:11 +0800 Subject: [PATCH] fix loading error --- hooks/use-radartile.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hooks/use-radartile.ts b/hooks/use-radartile.ts index e84e635..d03e172 100644 --- a/hooks/use-radartile.ts +++ b/hooks/use-radartile.ts @@ -86,6 +86,7 @@ export function useRadarTile({ const cachedBitmap = getFrame(frameIndex) if (cachedBitmap) { setCurrentBitmap(cachedBitmap) + preCacheAroundTime(timestamp) setIsLoading(false) return cachedBitmap } @@ -108,8 +109,7 @@ export function useRadarTile({ // 使用高优先级加载当前帧 loadFrame(url, frameIndex, 'high') - // 触发预缓存 - await preCacheAroundTime(timestamp) + preCacheAroundTime(timestamp) return null // 实际的bitmap会通过订阅通知获取 } catch (err) { @@ -125,10 +125,10 @@ export function useRadarTile({ }, [generateUrl, getFrameIndex, getFrame, loadFrame, subscribeToFrame]) // 在指定时间前后预缓存N个帧 - const preCacheAroundTime = useCallback(async (centerTimestamp: number, timeInterval: number = 360000) => { // 默认5分钟间隔 + const preCacheAroundTime = useCallback((centerTimestamp: number, timeInterval: number = 360000) => { // 默认5分钟间隔 if (!generateUrl) return - const urlsWithFrameIndices: Array<{url: string, frameIndex: number}> = [] + const urlsWithFrameIndices: Array<{ url: string, frameIndex: number }> = [] // 生成前后各N个时间点的URL和对应的frameIndex for (let i = -preCacheCount; i <= preCacheCount; i++) { @@ -137,6 +137,11 @@ export function useRadarTile({ const timestamp = centerTimestamp + (i * timeInterval) const url = generateUrl(timestamp) const frameIndex = getFrameIndex(timestamp) + + if (isFrameCached(frameIndex)) { + continue + } + urlsWithFrameIndices.push({ url, frameIndex }) } @@ -165,10 +170,6 @@ export function useRadarTile({ } }, [frameLoaderError, error]) - useEffect(() => { - setIsLoading(frameLoaderIsLoading) - }, [frameLoaderIsLoading]) - // 高级功能:清空缓存 const clearAllCache = useCallback(() => { if (unsubscribeRef.current) { @@ -187,7 +188,7 @@ export function useRadarTile({ const preCacheTimeRange = useCallback(async (startTime: number, endTime: number, timeInterval: number = 300000) => { if (!generateUrl) return - const urlsWithFrameIndices: Array<{url: string, frameIndex: number}> = [] + const urlsWithFrameIndices: Array<{ url: string, frameIndex: number }> = [] for (let timestamp = startTime; timestamp <= endTime; timestamp += timeInterval) { const url = generateUrl(timestamp)