From 17a3cbe6a746a72ecf32936b9fb96c5df0743278 Mon Sep 17 00:00:00 2001 From: santiago <108626122+marcosantiagomuro@users.noreply.github.com> Date: Tue, 12 Dec 2023 13:23:05 +0100 Subject: [PATCH] wip show only dashcam images in range --- .../Components/RoadDetails/ImageGallery.tsx | 29 +++++++++++++++++-- .../src/Components/RoadDetails/MapArea.tsx | 14 +++++++-- frontend/src/models/models.ts | 6 ++++ frontend/src/pages/Inspect.tsx | 28 +++++++++++++++++- 4 files changed, 70 insertions(+), 7 deletions(-) diff --git a/frontend/src/Components/RoadDetails/ImageGallery.tsx b/frontend/src/Components/RoadDetails/ImageGallery.tsx index 7db6b9ad..4f5b872a 100644 --- a/frontend/src/Components/RoadDetails/ImageGallery.tsx +++ b/frontend/src/Components/RoadDetails/ImageGallery.tsx @@ -3,14 +3,19 @@ import ImageZoom from './ImageAbleZoom'; import { IImage } from '../../models/path'; import { getImagesForASurvey, getImagesForWays } from '../../queries/images'; import { useParams } from 'react-router-dom'; +import { IRangeForDashCam } from '../../models/models'; +interface Props { + /** The distance from left to right displayed on surface images to display nearby dashcam images*/ + rangeDashCamImages?: IRangeForDashCam | null; +} /** * React functional component for the Image Gallery of Dash Camera image. * Image gallery is for show the real road image, and user can scroll to check * * @author: Chen, Lyons */ -const ImageGallery: React.FC = () => { +const ImageGallery: React.FC = ({ rangeDashCamImages }) => { /** The id and type of the object to display (in the url) */ const { id, type } = useParams(); @@ -34,14 +39,32 @@ const ImageGallery: React.FC = () => { if (type === 'surveys') { getImagesForASurvey(id, true, (images) => { - setCameraImages(images); + setCameraImages( + images.filter((image) => { + console.log('santi0', rangeDashCamImages); + if (rangeDashCamImages === undefined || rangeDashCamImages === null) + return true; + return ( + image.distance_way >= + (rangeDashCamImages.minRange - 5 > 0 + ? rangeDashCamImages.minRange - 5 + : 0) && + image.distance_way <= + (rangeDashCamImages.maxRange + 5 < + rangeDashCamImages.maxRangeSurvey + ? rangeDashCamImages.maxRange + 5 + : rangeDashCamImages.maxRangeSurvey) + ); + }), + ); + console.log('santiVIVA', cameraImages); }); } else if (type === 'paths') { getImagesForWays(id.split(','), true, (images) => { setCameraImages(images); }); } - }, [id]); + }, [id, rangeDashCamImages]); // Function to open the pop-up const openImageInPopup = useCallback( diff --git a/frontend/src/Components/RoadDetails/MapArea.tsx b/frontend/src/Components/RoadDetails/MapArea.tsx index 2c22180a..7347261a 100644 --- a/frontend/src/Components/RoadDetails/MapArea.tsx +++ b/frontend/src/Components/RoadDetails/MapArea.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ImageGallery from './ImageGallery'; import MapWrapper from '../Map/MapWrapper'; import ForceMapUpdate from '../Map/Hooks/ForceMapUpdate'; -import { LatLng } from '../../models/models'; +import { IRangeForDashCam, LatLng } from '../../models/models'; interface Props { /** The trigger to update the map */ @@ -11,11 +11,18 @@ interface Props { children?: React.ReactNode; /** The center of the map */ center?: LatLng; + /** The distance from left to right displayed on surface images */ + rangeDashCamImages?: IRangeForDashCam | null; } /** * The map area op the road details(road inspect) page */ -const MapArea: React.FC = ({ triggerUpdate, children, center }) => { +const MapArea: React.FC = ({ + triggerUpdate, + children, + center, + rangeDashCamImages, +}) => { return (
= ({ triggerUpdate, children, center }) => { className="imageGallery_container" style={{ height: '95px', overflow: 'hidden' }} > - {/* Use the imageGallery component */} + {' '} + {/* Use the imageGallery component */}
); diff --git a/frontend/src/models/models.ts b/frontend/src/models/models.ts index 9e74ec6c..87a2fe39 100644 --- a/frontend/src/models/models.ts +++ b/frontend/src/models/models.ts @@ -40,6 +40,12 @@ export interface Conditions { distance: number; } +export interface IRangeForDashCam { + minRange: number; + maxRange: number; + maxRangeSurvey: number; +} + export interface PathWithConditions { geometry: number[][]; data: Conditions[]; diff --git a/frontend/src/pages/Inspect.tsx b/frontend/src/pages/Inspect.tsx index 4f9c45c8..9285f7fd 100644 --- a/frontend/src/pages/Inspect.tsx +++ b/frontend/src/pages/Inspect.tsx @@ -13,6 +13,7 @@ import { useParams } from 'react-router-dom'; import { Conditions, ImageType, + IRangeForDashCam, LatLng, PathWithConditions, } from '../models/models'; @@ -110,6 +111,9 @@ const Inspect: FC = () => { /** The data to display */ const [data, setData] = useState(); + const [rangeForDashCamImages, setRangeForDashCamImages] = + useState({ minRange: 0, maxRange: 0, maxRangeSurvey: 0 }); + const availableGraphIndicatorType = useMemo(() => { return Array.from( new Set( @@ -120,6 +124,24 @@ const Inspect: FC = () => { ); }, [data]); + useEffect(() => { + console.log('santi33', roadDistanceLeftToRight); + console.log('santi44', chartData); + if ( + gradientLineData === undefined || + roadDistanceLeftToRight === null || + chartData === undefined + ) + return; + + setRangeForDashCamImages({ + minRange: roadDistanceLeftToRight[0], + maxRange: roadDistanceLeftToRight[1], + maxRangeSurvey: Math.max(...chartData.map((item) => item.maxX)) + 1, + }); + console.log('santi55 rangeForDashCamImages', rangeForDashCamImages); + }, [roadDistanceLeftToRight]); + useEffect(() => { if (id === undefined || type === undefined) return; @@ -252,7 +274,11 @@ const Inspect: FC = () => {
- +