From eca5efdb32c0d4ba04e342655f4c0a73532c7a0c Mon Sep 17 00:00:00 2001 From: Maxence Date: Tue, 12 Mar 2024 17:23:47 +0100 Subject: [PATCH] style(map): updated map interface --- client/src/assets/img/pin-ghost.svg | 1 + client/src/assets/img/pin.svg | 2 +- client/src/assets/styles/main.css | 21 ++++++++++++++++ client/src/components/map/Map.tsx | 32 +++++++++++++++++++++---- client/src/interfaces/step.interface.ts | 4 ++-- client/src/pages/map/MapPage.tsx | 25 +++++++++++-------- 6 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 client/src/assets/img/pin-ghost.svg diff --git a/client/src/assets/img/pin-ghost.svg b/client/src/assets/img/pin-ghost.svg new file mode 100644 index 0000000..0458f8d --- /dev/null +++ b/client/src/assets/img/pin-ghost.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/client/src/assets/img/pin.svg b/client/src/assets/img/pin.svg index 7c0583e..cf772bb 100644 --- a/client/src/assets/img/pin.svg +++ b/client/src/assets/img/pin.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/client/src/assets/styles/main.css b/client/src/assets/styles/main.css index b95ef2b..79af2d6 100644 --- a/client/src/assets/styles/main.css +++ b/client/src/assets/styles/main.css @@ -74,6 +74,27 @@ height: 100% !important; } +main .leaflet-popup-content p { + margin: 4px 0 !important; + color: #fafafa !important; +} + +main .leaflet-popup-tip { + background-color: #656565 !important; +} + +main .leaflet-popup-content-wrapper { + background-color: #656565 !important; +} + +main .leaflet-container a.leaflet-popup-close-button { + color: #fafafa !important; +} + +main .leaflet-popup { + border-radius: 8px !important; +} + .badge-display { transition: .21s ease-out; transform: rotate(0deg); diff --git a/client/src/components/map/Map.tsx b/client/src/components/map/Map.tsx index 52d8bc5..30f0659 100644 --- a/client/src/components/map/Map.tsx +++ b/client/src/components/map/Map.tsx @@ -4,14 +4,18 @@ import { Polyline, Popup, TileLayer, + useMap, } from "react-leaflet"; -import { Icon } from "leaflet"; +import { Icon, LatLng } from "leaflet"; import { Step } from "../../interfaces/step.interface"; +import { useEffect } from "react"; const Map = ({ + currentStep, steps, polylinePath, }: { + currentStep: Step | undefined; steps: Step[]; polylinePath: [number, number][]; }) => { @@ -22,14 +26,32 @@ const Map = ({ iconSize: [40, 40], }); + const customIconGhost = new Icon({ + iconUrl: "/src/assets/img/pin-ghost.svg", + iconSize: [40, 40], + }); + + const geolocalisation = currentStep ? new LatLng(currentStep.geolocalisation.latitude, currentStep.geolocalisation.longitude) : new LatLng(43.282, 5.405); + + const MapRecenter= ({ lat, lng, zoomLevel }: { lat: number; lng: number; zoomLevel: number }) => { + const map = useMap(); + + useEffect(() => { + map.flyTo([lat, lng], zoomLevel ); + }, [lat, lng]); + return null; + }; + return (
+ {steps && @@ -39,11 +61,11 @@ const Map = ({ marker.geolocalisation.latitude, marker.geolocalisation.longitude, ]} - icon={customIcon} + icon={!currentStep ? customIconGhost : (currentStep.etape_numero < marker.etape_numero ? customIconGhost : customIcon)} key={index} > -

Étape n°{marker.etape}

+ Étape n°{marker.etape}

{marker.date}

{marker.ville}

diff --git a/client/src/interfaces/step.interface.ts b/client/src/interfaces/step.interface.ts index 8cd773a..0c17cc4 100644 --- a/client/src/interfaces/step.interface.ts +++ b/client/src/interfaces/step.interface.ts @@ -16,5 +16,5 @@ export interface Step { y: number; }; population: number; - code_postal: "04100"; -} + code_postal: string; +} \ No newline at end of file diff --git a/client/src/pages/map/MapPage.tsx b/client/src/pages/map/MapPage.tsx index 0376ff2..b02a68d 100644 --- a/client/src/pages/map/MapPage.tsx +++ b/client/src/pages/map/MapPage.tsx @@ -28,30 +28,35 @@ const MapPage = () => { }); }; - const handleCurrentStep = useCallback(() => { + const handleCurrentStep = () => { APIHandler(`/etape/actuelle`, true).then((res) => { setCurrentFlameLocation(res.data); handleNextStep(res.data.etape_numero); }); - }, []); + } useEffect(() => { handleSteps(); handleCurrentStep(); - }, [handleCurrentStep]); + }, []); + + if(currentFlameLocation) { + steps.forEach((step) => { + if(currentFlameLocation && step.etape_numero > currentFlameLocation.etape_numero) return; + polylinePath.push([ + step.geolocalisation.latitude, + step.geolocalisation.longitude, + ]); + }); + } - steps.forEach((step) => { - polylinePath.push([ - step.geolocalisation.latitude, - step.geolocalisation.longitude, - ]); - }); + console.log(currentFlameLocation); return (

Parcours de la flamme

- +

Où est la flamme