Skip to content

Commit

Permalink
front: use a new type MarkerInformation in ItineraryMarkers
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Nov 18, 2024
1 parent 689f983 commit dd76dc2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useMemo } from 'react';

import type { Position } from '@turf/helpers';
import cx from 'classnames';
import { compact } from 'lodash';
import type { Map } from 'maplibre-gl';
import { Marker } from 'react-map-gl/maplibre';
import { useSelector } from 'react-redux';
Expand All @@ -13,17 +14,27 @@ import stdcmOrigin from 'assets/pictures/mapMarkers/start.svg';
import originSVG from 'assets/pictures/origin.svg';
import viaSVG from 'assets/pictures/via.svg';
import { useOsrdConfSelectors } from 'common/osrdContext';
import type { PathStep } from 'reducers/osrdconf/types';
import { getNearestTrack } from 'utils/mapHelper';

export type MarkerInformation = {
name?: string;
coordinates?: number[] | Position;
metadata?: {
lineCode: number;
lineName: string;
trackName: string;
trackNumber: number;
};
};

enum MARKER_TYPE {
ORIGIN = 'origin',
VIA = 'via',
DESTINATION = 'destination',
}

type MarkerInformation = {
marker: PathStep;
type MarkerProps = {
marker: MarkerInformation;
coordinates: number[] | Position;
imageSource: string;
} & (
Expand All @@ -38,15 +49,15 @@ type MarkerInformation = {

type ItineraryMarkersProps = {
map: Map;
simulationPathSteps?: PathStep[];
simulationPathSteps?: MarkerInformation[];
showStdcmAssets: boolean;
};

const formatPointWithNoName = (
lineCode: number,
lineName: string,
trackName: string,
markerType: MarkerInformation['type']
markerType: MarkerProps['type']
) => (
<>
<div className="main-line">
Expand All @@ -57,7 +68,7 @@ const formatPointWithNoName = (
</>
);

const extractMarkerInformation = (pathSteps: (PathStep | null)[], showStdcmAssets: boolean) =>
const extractMarkerInformation = (pathSteps: MarkerInformation[], showStdcmAssets: boolean) =>
pathSteps.reduce((acc, cur, index) => {
if (cur && cur.coordinates) {
if (index === 0) {
Expand Down Expand Up @@ -85,19 +96,19 @@ const extractMarkerInformation = (pathSteps: (PathStep | null)[], showStdcmAsset
}
}
return acc;
}, [] as MarkerInformation[]);
}, [] as MarkerProps[]);

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

const markersInformation = useMemo(
() => extractMarkerInformation(simulationPathSteps || pathSteps, showStdcmAssets),
() => extractMarkerInformation(simulationPathSteps || compact(pathSteps), showStdcmAssets),
[simulationPathSteps, pathSteps, showStdcmAssets]
);

const getMarkerDisplayInformation = useCallback(
(markerInfo: MarkerInformation) => {
(markerInfo: MarkerProps) => {
const {
marker: { coordinates: markerCoordinates, metadata: markerMetadata },
type: markerType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ import RenderPopup from 'modules/trainschedule/components/ManageTrainSchedule/Ma
import { updateViewport } from 'reducers/map';
import type { Viewport } from 'reducers/map';
import { getMap, getTerrain3DExaggeration } from 'reducers/map/selectors';
import type { PathStep } from 'reducers/osrdconf/types';
import { useAppDispatch } from 'store';
import { getMapMouseEventNearestFeature } from 'utils/mapHelper';

import ItineraryLayer from './ManageTrainScheduleMap/ItineraryLayer';
import ItineraryMarkers from './ManageTrainScheduleMap/ItineraryMarkers';
import ItineraryMarkers, {
type MarkerInformation,
} from './ManageTrainScheduleMap/ItineraryMarkers';

type MapProps = {
pathProperties?: ManageTrainSchedulePathProperties;
Expand All @@ -63,7 +64,7 @@ type MapProps = {
hideItinerary?: boolean;
preventPointSelection?: boolean;
mapId?: string;
simulationPathSteps?: PathStep[];
simulationPathSteps?: MarkerInformation[];
showStdcmAssets?: boolean;
isFeasible?: boolean;
};
Expand Down

0 comments on commit dd76dc2

Please sign in to comment.