Skip to content

Commit 96183be

Browse files
committed
front: use a new type MarkerInformation in ItineraryMarkers
Signed-off-by: Clara Ni <[email protected]>
1 parent 160ef24 commit 96183be

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/ItineraryMarkers.tsx

+20-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useCallback, useMemo } from 'react';
22

33
import type { Position } from '@turf/helpers';
44
import cx from 'classnames';
5+
import { compact } from 'lodash';
56
import type { Map } from 'maplibre-gl';
67
import { Marker } from 'react-map-gl/maplibre';
78
import { useSelector } from 'react-redux';
@@ -13,17 +14,27 @@ import stdcmOrigin from 'assets/pictures/mapMarkers/start.svg';
1314
import originSVG from 'assets/pictures/origin.svg';
1415
import viaSVG from 'assets/pictures/via.svg';
1516
import { useOsrdConfSelectors } from 'common/osrdContext';
16-
import type { PathStep } from 'reducers/osrdconf/types';
1717
import { getNearestTrack } from 'utils/mapHelper';
1818

19+
export type MarkerInformation = {
20+
name?: string;
21+
coordinates?: number[] | Position;
22+
metadata?: {
23+
lineCode: number;
24+
lineName: string;
25+
trackName: string;
26+
trackNumber: number;
27+
};
28+
};
29+
1930
enum MARKER_TYPE {
2031
ORIGIN = 'origin',
2132
VIA = 'via',
2233
DESTINATION = 'destination',
2334
}
2435

25-
type MarkerInformation = {
26-
marker: PathStep;
36+
type MarkerProps = {
37+
marker: MarkerInformation;
2738
coordinates: number[] | Position;
2839
imageSource: string;
2940
} & (
@@ -38,15 +49,15 @@ type MarkerInformation = {
3849

3950
type ItineraryMarkersProps = {
4051
map: Map;
41-
simulationPathSteps?: PathStep[];
52+
simulationPathSteps?: MarkerInformation[];
4253
showStdcmAssets: boolean;
4354
};
4455

4556
const formatPointWithNoName = (
4657
lineCode: number,
4758
lineName: string,
4859
trackName: string,
49-
markerType: MarkerInformation['type']
60+
markerType: MarkerProps['type']
5061
) => (
5162
<>
5263
<div className="main-line">
@@ -57,7 +68,7 @@ const formatPointWithNoName = (
5768
</>
5869
);
5970

60-
const extractMarkerInformation = (pathSteps: (PathStep | null)[], showStdcmAssets: boolean) =>
71+
const extractMarkerInformation = (pathSteps: MarkerInformation[], showStdcmAssets: boolean) =>
6172
pathSteps.reduce((acc, cur, index) => {
6273
if (cur && cur.coordinates) {
6374
if (index === 0) {
@@ -85,19 +96,19 @@ const extractMarkerInformation = (pathSteps: (PathStep | null)[], showStdcmAsset
8596
}
8697
}
8798
return acc;
88-
}, [] as MarkerInformation[]);
99+
}, [] as MarkerProps[]);
89100

90101
const ItineraryMarkers = ({ map, simulationPathSteps, showStdcmAssets }: ItineraryMarkersProps) => {
91102
const { getPathSteps } = useOsrdConfSelectors();
92103
const pathSteps = useSelector(getPathSteps);
93104

94105
const markersInformation = useMemo(
95-
() => extractMarkerInformation(simulationPathSteps || pathSteps, showStdcmAssets),
106+
() => extractMarkerInformation(simulationPathSteps || compact(pathSteps), showStdcmAssets),
96107
[simulationPathSteps, pathSteps, showStdcmAssets]
97108
);
98109

99110
const getMarkerDisplayInformation = useCallback(
100-
(markerInfo: MarkerInformation) => {
111+
(markerInfo: MarkerProps) => {
101112
const {
102113
marker: { coordinates: markerCoordinates, metadata: markerMetadata },
103114
type: markerType,

front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ import RenderPopup from 'modules/trainschedule/components/ManageTrainSchedule/Ma
4747
import { updateViewport } from 'reducers/map';
4848
import type { Viewport } from 'reducers/map';
4949
import { getMap, getTerrain3DExaggeration } from 'reducers/map/selectors';
50-
import type { PathStep } from 'reducers/osrdconf/types';
5150
import { useAppDispatch } from 'store';
5251
import { getMapMouseEventNearestFeature } from 'utils/mapHelper';
5352

5453
import ItineraryLayer from './ManageTrainScheduleMap/ItineraryLayer';
55-
import ItineraryMarkers from './ManageTrainScheduleMap/ItineraryMarkers';
54+
import ItineraryMarkers, {
55+
type MarkerInformation,
56+
} from './ManageTrainScheduleMap/ItineraryMarkers';
5657

5758
type MapProps = {
5859
pathProperties?: ManageTrainSchedulePathProperties;
@@ -63,7 +64,7 @@ type MapProps = {
6364
hideItinerary?: boolean;
6465
preventPointSelection?: boolean;
6566
mapId?: string;
66-
simulationPathSteps?: PathStep[];
67+
simulationPathSteps?: MarkerInformation[];
6768
showStdcmAssets?: boolean;
6869
isFeasible?: boolean;
6970
};

0 commit comments

Comments
 (0)