fix(web): retry transient map load failures

This commit is contained in:
lingniu
2026-07-16 07:13:23 +08:00
parent 970ef5d7c0
commit a0448d6615
5 changed files with 29 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import { IconEyeClosed, IconEyeOpened, IconMapPin } from '@douyinfe/semi-icons';
import { IconEyeClosed, IconEyeOpened, IconMapPin, IconRefresh } from '@douyinfe/semi-icons';
import { useEffect, useMemo, useRef, useState } from 'react';
import { getAMapConfig, isAMapConfigured } from '../../config/appConfig';
import {
@@ -169,6 +169,7 @@ export function FleetMap({ vehicles, selectedVin, onSelect, monitorMap, onSelect
const centeredVinRef = useRef('');
const followSelectedRef = useRef(true);
const [state, setState] = useState<'loading' | 'ready' | 'fallback' | 'error'>('loading');
const [loadAttempt, setLoadAttempt] = useState(0);
const [showLabels, setShowLabels] = useState(true);
const [followSelected, setFollowSelected] = useState(true);
const [mapZoom, setMapZoom] = useState(5);
@@ -314,7 +315,7 @@ export function FleetMap({ vehicles, selectedVin, onSelect, monitorMap, onSelect
amapRef.current = null;
mapRef.current = null;
};
}, []);
}, [loadAttempt]);
useEffect(() => {
const mass = massRef.current;
@@ -511,7 +512,7 @@ export function FleetMap({ vehicles, selectedVin, onSelect, monitorMap, onSelect
<div className={`v2-map-state is-${state}`}>
{state === 'loading' ? <><span className="v2-spinner" /></> : null}
{state === 'fallback' ? `地图未配置,当前已载入 ${renderedPointCount} 个有效坐标` : null}
{state === 'error' ? '地图加载失败,请检查高德 Key、域名白名单和网络' : null}
{state === 'error' ? <><span> Key</span><button type="button" onClick={() => setLoadAttempt((value) => value + 1)}><IconRefresh /></button></> : null}
</div>
) : null}
<div className="v2-map-legend" aria-label="车辆状态图例">