fix loading error

This commit is contained in:
tsuki 2025-08-26 18:48:11 +08:00
parent c6a59c48a5
commit 687749f431

View File

@ -86,6 +86,7 @@ export function useRadarTile({
const cachedBitmap = getFrame(frameIndex) const cachedBitmap = getFrame(frameIndex)
if (cachedBitmap) { if (cachedBitmap) {
setCurrentBitmap(cachedBitmap) setCurrentBitmap(cachedBitmap)
preCacheAroundTime(timestamp)
setIsLoading(false) setIsLoading(false)
return cachedBitmap return cachedBitmap
} }
@ -108,8 +109,7 @@ export function useRadarTile({
// 使用高优先级加载当前帧 // 使用高优先级加载当前帧
loadFrame(url, frameIndex, 'high') loadFrame(url, frameIndex, 'high')
// 触发预缓存 preCacheAroundTime(timestamp)
await preCacheAroundTime(timestamp)
return null // 实际的bitmap会通过订阅通知获取 return null // 实际的bitmap会通过订阅通知获取
} catch (err) { } catch (err) {
@ -125,7 +125,7 @@ export function useRadarTile({
}, [generateUrl, getFrameIndex, getFrame, loadFrame, subscribeToFrame]) }, [generateUrl, getFrameIndex, getFrame, loadFrame, subscribeToFrame])
// 在指定时间前后预缓存N个帧 // 在指定时间前后预缓存N个帧
const preCacheAroundTime = useCallback(async (centerTimestamp: number, timeInterval: number = 360000) => { // 默认5分钟间隔 const preCacheAroundTime = useCallback((centerTimestamp: number, timeInterval: number = 360000) => { // 默认5分钟间隔
if (!generateUrl) return if (!generateUrl) return
const urlsWithFrameIndices: Array<{ url: string, frameIndex: number }> = [] const urlsWithFrameIndices: Array<{ url: string, frameIndex: number }> = []
@ -137,6 +137,11 @@ export function useRadarTile({
const timestamp = centerTimestamp + (i * timeInterval) const timestamp = centerTimestamp + (i * timeInterval)
const url = generateUrl(timestamp) const url = generateUrl(timestamp)
const frameIndex = getFrameIndex(timestamp) const frameIndex = getFrameIndex(timestamp)
if (isFrameCached(frameIndex)) {
continue
}
urlsWithFrameIndices.push({ url, frameIndex }) urlsWithFrameIndices.push({ url, frameIndex })
} }
@ -165,10 +170,6 @@ export function useRadarTile({
} }
}, [frameLoaderError, error]) }, [frameLoaderError, error])
useEffect(() => {
setIsLoading(frameLoaderIsLoading)
}, [frameLoaderIsLoading])
// 高级功能:清空缓存 // 高级功能:清空缓存
const clearAllCache = useCallback(() => { const clearAllCache = useCallback(() => {
if (unsubscribeRef.current) { if (unsubscribeRef.current) {