diff --git a/client/admin/components_amap.tsx b/client/admin/components_amap.tsx index d3fa203..fc0cb3e 100644 --- a/client/admin/components_amap.tsx +++ b/client/admin/components_amap.tsx @@ -308,7 +308,7 @@ export const useAMapMarkers = ({ }; useEffect(() => { - if (!map) return; + if (!map || !Array.isArray(markers)) return; // 清理旧的标记点和聚合点 if (clusterInstance.current) { @@ -319,10 +319,12 @@ export const useAMapMarkers = ({ markersRef.current = []; // 根据配置添加新的标记点 - if (showCluster) { - handleCluster(); - } else { - handleMarkers(); + if (markers.length > 0) { + if (showCluster) { + handleCluster(); + } else { + handleMarkers(); + } } return () => { diff --git a/client/admin/pages_map.tsx b/client/admin/pages_map.tsx index 2d1e9a2..6d13eee 100644 --- a/client/admin/pages_map.tsx +++ b/client/admin/pages_map.tsx @@ -107,9 +107,11 @@ export const LoginMapPage = () => { }; // 渲染地图标记点 - const renderMarkers = (locations: LoginLocation[]): MarkerData[] => { + const renderMarkers = (locations: LoginLocation[] = []): MarkerData[] => { + if (!Array.isArray(locations)) return []; + return locations - .filter(location => location.longitude !== null && location.latitude !== null) + .filter(location => location?.longitude !== null && location?.latitude !== null) .map(location => ({ id: location.id?.toString() || '', longitude: location.longitude as number, @@ -157,7 +159,7 @@ export const LoginMapPage = () => {