From b2700b9ef9e34cebc90d669fd53bde91401cae52 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Wed, 11 Feb 2026 16:33:02 +0100 Subject: Use provided colours in map Closes #131 --- src/frontend/app/components/stop/StopMapModal.tsx | 91 +++-------------------- 1 file changed, 12 insertions(+), 79 deletions(-) (limited to 'src/frontend/app/components/stop/StopMapModal.tsx') diff --git a/src/frontend/app/components/stop/StopMapModal.tsx b/src/frontend/app/components/stop/StopMapModal.tsx index 688ec2e..30ac63f 100644 --- a/src/frontend/app/components/stop/StopMapModal.tsx +++ b/src/frontend/app/components/stop/StopMapModal.tsx @@ -8,9 +8,7 @@ import React, { } from "react"; import { Layer, Marker, Source, type MapRef } from "react-map-gl/maplibre"; import { Sheet } from "react-modal-sheet"; -import { useApp } from "~/AppContext"; import { AppMap } from "~/components/shared/AppMap"; -import { getLineColour } from "~/data/LineColors"; import type { Stop } from "~/data/StopDataProvider"; import "./StopMapModal.css"; @@ -23,18 +21,15 @@ export interface Position { export interface ConsolidatedCirculationForMap { id: string; - line: string; - route: string; currentPosition?: Position; stopShapeIndex?: number; - isPreviousTrip?: boolean; - previousTripShapeId?: string | null; - schedule?: { - shapeId?: string | null; - }; + colour: string; + textColour: string; shape?: any; } +// TODO: Replace `circulations`+`selectedCirculationId` with a single `selectedCirculation` prop + interface StopMapModalProps { stop: Stop; circulations: ConsolidatedCirculationForMap[]; @@ -50,12 +45,10 @@ export const StopMapModal: React.FC = ({ onClose, selectedCirculationId, }) => { - const { theme } = useApp(); const mapRef = useRef(null); const hasFitBounds = useRef(false); const userInteracted = useRef(false); const [shapeData, setShapeData] = useState(null); - const [previousShapeData, setPreviousShapeData] = useState(null); // Filter circulations that have GPS coordinates const busesWithPosition = useMemo( @@ -163,7 +156,7 @@ export const StopMapModal: React.FC = ({ } } else { // Current trip: Start from Bus (if not previous), End at User Stop - if (!previousShapeData && currentPos) { + if (currentPos) { const busIdx = findClosestStopIndex(stops, { lat: currentPos.latitude, lon: currentPos.longitude, @@ -234,7 +227,6 @@ export const StopMapModal: React.FC = ({ } }; - addShapePoints(previousShapeData, true); addShapePoints(shapeData, false); if (points.length === 0) { @@ -292,7 +284,7 @@ export const StopMapModal: React.FC = ({ } as any); } } catch {} - }, [stop, selectedBus, shapeData, previousShapeData]); + }, [stop, selectedBus, shapeData]); // Resize map and fit bounds when modal opens useEffect(() => { @@ -324,7 +316,6 @@ export const StopMapModal: React.FC = ({ hasFitBounds.current = false; userInteracted.current = false; setShapeData(null); - setPreviousShapeData(null); } }, [isOpen]); @@ -332,19 +323,16 @@ export const StopMapModal: React.FC = ({ useEffect(() => { if (!isOpen || !selectedBus) { setShapeData(null); - setPreviousShapeData(null); return; } if (selectedBus.shape) { setShapeData(selectedBus.shape); - setPreviousShapeData(null); handleCenter(); return; } setShapeData(null); - setPreviousShapeData(null); }, [isOpen, selectedBus]); if (!selectedBus && busesWithPosition.length === 0) { @@ -392,58 +380,6 @@ export const StopMapModal: React.FC = ({ handleCenter(); }} > - {/* Previous Shape Layer */} - {previousShapeData && selectedBus && ( - - {/* 1. Black border */} - - {/* 2. White background */} - - {/* 3. Colored dashes */} - - - )} - {/* Shape Layer */} {shapeData && selectedBus && ( @@ -451,8 +387,8 @@ export const StopMapModal: React.FC = ({ id="route-shape-border" type="line" paint={{ - "line-color": "#000000", - "line-width": 5, + "line-color": selectedBus.textColour, + "line-width": 7, "line-opacity": 0.6, }} layout={{ @@ -464,10 +400,8 @@ export const StopMapModal: React.FC = ({ id="route-shape-inner" type="line" paint={{ - "line-color": getLineColour(selectedBus.line) - .background, - "line-width": 3, - "line-opacity": 0.7, + "line-color": selectedBus.colour, + "line-width": 5, }} layout={{ "line-cap": "round", @@ -484,8 +418,7 @@ export const StopMapModal: React.FC = ({ "circle-color": "#FFFFFF", "circle-radius": 4, "circle-stroke-width": 2, - "circle-stroke-color": getLineColour(selectedBus.line) - .background, + "circle-stroke-color": selectedBus.colour, }} /> @@ -557,7 +490,7 @@ export const StopMapModal: React.FC = ({ >