37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { DetectionData } from '@/types';
|
|
import { DETECTION_TYPES } from '@/constants/detectionModeConfig';
|
|
|
|
export const useGpsMap = (data: DetectionData) => {
|
|
const gpsMap = useMemo(() => {
|
|
const map = new Map<number, { lat: number; lng: number }>();
|
|
|
|
const addItemsToMap = (list?: any[]) => {
|
|
if (!list || !Array.isArray(list)) return;
|
|
list.forEach((item) => {
|
|
const id =
|
|
(item as any).pothole_id ?? (item as any).signboard_id ?? (item as any).detection_id;
|
|
if (item.lat !== undefined && item.lng !== undefined && id !== undefined) {
|
|
map.set(id, { lat: item.lat, lng: item.lng });
|
|
}
|
|
});
|
|
};
|
|
|
|
// Dynamically add items from all configured detection lists
|
|
Object.values(DETECTION_TYPES).forEach((type) => {
|
|
if (type.listKey) {
|
|
addItemsToMap((data as any)[type.listKey]);
|
|
}
|
|
});
|
|
|
|
// Backward compatibility for generic signboard_list
|
|
if ((data as any).signboard_list) {
|
|
addItemsToMap((data as any).signboard_list);
|
|
}
|
|
|
|
return map;
|
|
}, [data]);
|
|
|
|
return gpsMap;
|
|
};
|