diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/ItineraryMarkers.tsx b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/ItineraryMarkers.tsx index 4f14b38c1bd..5226992a068 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/ItineraryMarkers.tsx +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/ItineraryMarkers.tsx @@ -65,6 +65,18 @@ const formatPointWithNoName = ( ); +const MARKER_IMAGES = { + [MARKER_TYPE.ORIGIN]: originSVG, + [MARKER_TYPE.DESTINATION]: destinationSVG, + [MARKER_TYPE.VIA]: viaSVG, +}; + +const STDCM_MARKER_IMAGES = { + [MARKER_TYPE.ORIGIN]: stdcmOrigin, + [MARKER_TYPE.DESTINATION]: stdcmDestination, + [MARKER_TYPE.VIA]: stdcmVia, +}; + const extractMarkerInformation = ( pathSteps: MarkerInformation[], showStdcmAssets: boolean, @@ -72,41 +84,25 @@ const extractMarkerInformation = ( ): MarkerProperties[] => pathSteps .map((pathStep, index): MarkerProperties | null => { + if (!pathStep.coordinates) return null; + const matchingOp = suggestedOP ? suggestedOP.find((op) => matchPathStepAndOp(pathStep, op)) : undefined; - if (pathStep.coordinates) { - if (pathStep.pointType === MARKER_TYPE.ORIGIN) { - return { - coordinates: pathStep.coordinates, - type: MARKER_TYPE.ORIGIN, - imageSource: showStdcmAssets ? stdcmOrigin : originSVG, - op: matchingOp, - pathStep, - }; - } - - if (pathStep.pointType === MARKER_TYPE.DESTINATION) { - return { - coordinates: pathStep.coordinates, - type: MARKER_TYPE.DESTINATION, - imageSource: showStdcmAssets ? stdcmDestination : destinationSVG, - op: matchingOp, - pathStep, - }; - } - - return { - coordinates: pathStep.coordinates, - type: MARKER_TYPE.VIA, - imageSource: showStdcmAssets ? stdcmVia : viaSVG, - index, - op: matchingOp, - pathStep, - }; - } - return null; + const images = showStdcmAssets ? STDCM_MARKER_IMAGES : MARKER_IMAGES; + return { + coordinates: pathStep.coordinates, + imageSource: images[pathStep.pointType], + op: matchingOp, + pathStep, + ...(pathStep.pointType === MARKER_TYPE.VIA + ? { + type: MARKER_TYPE.VIA, + index, + } + : { type: pathStep.pointType }), + }; }) .filter((marker): marker is MarkerProperties => marker !== null);