Skip to content

Commit 7dde05a

Browse files
committed
front: center map on pathSteps if no path is found
Signed-off-by: Clara Ni <clara.ni@outlook.fr>
1 parent 0a76c55 commit 7dde05a

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

front/src/applications/operationalStudies/views/ManageTrainSchedule.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const ManageTrainSchedule = ({ trainIdToEdit }: ManageTrainScheduleProps) => {
122122
<div className="floating-itinerary">
123123
<Itinerary pathProperties={pathProperties} setPathProperties={setPathProperties} />
124124
</div>
125-
<Map pathProperties={pathProperties}>
125+
<Map pathProperties={pathProperties} simulationPathSteps={compact(pathSteps)}>
126126
<IncompatibleConstraints pathProperties={pathProperties} />
127127
</Map>
128128
</div>

front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ const StcdmResults = ({
6767
);
6868
}, [outputs]);
6969

70-
const simulationPathSteps = hasSimulationResults
71-
? outputs.results.simulationPathSteps
72-
: undefined;
70+
const simulationPathSteps = hasSimulationResults ? outputs.results.simulationPathSteps : [];
7371

7472
return (
7573
<>

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import type { Position } from '@turf/helpers';
44
import cx from 'classnames';
55
import type { Map } from 'maplibre-gl';
66
import { Marker } from 'react-map-gl/maplibre';
7-
import { useSelector } from 'react-redux';
87

98
import destinationSVG from 'assets/pictures/destination.svg';
109
import stdcmDestination from 'assets/pictures/mapMarkers/destination.svg';
1110
import stdcmVia from 'assets/pictures/mapMarkers/intermediate-point.svg';
1211
import stdcmOrigin from 'assets/pictures/mapMarkers/start.svg';
1312
import originSVG from 'assets/pictures/origin.svg';
1413
import viaSVG from 'assets/pictures/via.svg';
15-
import { useOsrdConfSelectors } from 'common/osrdContext';
1614
import type { PathStep } from 'reducers/osrdconf/types';
1715
import { getNearestTrack } from 'utils/mapHelper';
1816

@@ -38,7 +36,7 @@ type MarkerInformation = {
3836

3937
type ItineraryMarkersProps = {
4038
map: Map;
41-
simulationPathSteps?: PathStep[];
39+
simulationPathSteps: PathStep[];
4240
showStdcmAssets: boolean;
4341
};
4442

@@ -88,12 +86,9 @@ const extractMarkerInformation = (pathSteps: (PathStep | null)[], showStdcmAsset
8886
}, [] as MarkerInformation[]);
8987

9088
const ItineraryMarkers = ({ map, simulationPathSteps, showStdcmAssets }: ItineraryMarkersProps) => {
91-
const { getPathSteps } = useOsrdConfSelectors();
92-
const pathSteps = useSelector(getPathSteps);
93-
9489
const markersInformation = useMemo(
95-
() => extractMarkerInformation(simulationPathSteps || pathSteps, showStdcmAssets),
96-
[simulationPathSteps, pathSteps, showStdcmAssets]
90+
() => extractMarkerInformation(simulationPathSteps, showStdcmAssets),
91+
[simulationPathSteps, showStdcmAssets]
9792
);
9893

9994
const getMarkerDisplayInformation = useCallback(
@@ -173,7 +168,7 @@ const ItineraryMarkers = ({ map, simulationPathSteps, showStdcmAssets }: Itinera
173168
</Marker>
174169
);
175170
}),
176-
[simulationPathSteps, pathSteps, showStdcmAssets]
171+
[markersInformation, showStdcmAssets]
177172
);
178173
return Markers;
179174
};

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type MapProps = {
6363
hideItinerary?: boolean;
6464
preventPointSelection?: boolean;
6565
mapId?: string;
66-
simulationPathSteps?: PathStep[];
66+
simulationPathSteps: PathStep[];
6767
showStdcmAssets?: boolean;
6868
isFeasible?: boolean;
6969
};
@@ -218,11 +218,15 @@ const Map = ({
218218
}, []);
219219

220220
useEffect(() => {
221-
if (pathGeometry) {
222-
const newViewport = computeBBoxViewport(bbox(pathGeometry), mapViewport);
221+
const points = pathGeometry ?? {
222+
coordinates: simulationPathSteps.map((step) => step.coordinates),
223+
type: 'LineString',
224+
};
225+
if (points.coordinates.length > 2) {
226+
const newViewport = computeBBoxViewport(bbox(points), mapViewport);
223227
dispatch(updateViewport(newViewport));
224228
}
225-
}, [pathGeometry]);
229+
}, [pathGeometry, simulationPathSteps]);
226230

227231
return (
228232
<>

0 commit comments

Comments
 (0)