refactor: video section
This commit is contained in:
27
src/hooks/use-gps-map.ts
Normal file
27
src/hooks/use-gps-map.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { useMemo } from 'react';
|
||||
import { DetectionData } from '@/types';
|
||||
|
||||
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 });
|
||||
}
|
||||
});
|
||||
};
|
||||
addItemsToMap(data.pothole_list);
|
||||
addItemsToMap(data.signboard_list);
|
||||
addItemsToMap(data.defected_sign_board_list);
|
||||
addItemsToMap(data.road_crack_list);
|
||||
addItemsToMap(data.damaged_road_marking_list);
|
||||
addItemsToMap(data.good_sign_board_list);
|
||||
return map;
|
||||
}, [data]);
|
||||
|
||||
return gpsMap;
|
||||
};
|
||||
Reference in New Issue
Block a user