|
1 | 1 | import { useCallback, useMemo, useRef, useState } from 'react'; |
2 | 2 |
|
| 3 | +import type { Position } from 'geojson'; |
3 | 4 | import { useTranslation } from 'react-i18next'; |
4 | 5 | import type { MapLayerMouseEvent, MapRef } from 'react-map-gl/maplibre'; |
5 | 6 |
|
| 7 | +import { matchOpRefAndOp } from 'applications/operationalStudies/utils'; |
6 | 8 | import type { PathProperties } from 'common/api/osrdEditoastApi'; |
7 | 9 | import BaseMap from 'common/Map/BaseMap'; |
8 | 10 | import MapButtons from 'common/Map/Buttons/MapButtons'; |
@@ -168,10 +170,32 @@ const ItineraryModalMap = ({ |
168 | 170 | const pathStepLocation = step.location; |
169 | 171 | if (!pathStepLocation || !pathStepMetadata || pathStepMetadata?.isInvalid) return null; |
170 | 172 |
|
171 | | - const allCoordinates = computePathStepCoordinates(pathStepMetadata); |
| 173 | + let coordinates: Position | undefined; |
| 174 | + if (pathProperties?.operational_points) { |
| 175 | + // If there is a pathfinding, we use it to get the simulated coordinates |
| 176 | + if (pathStepMetadata.type == 'trackOffset') { |
| 177 | + coordinates = pathStepMetadata.coordinates; |
| 178 | + } else { |
| 179 | + const matchedOp = pathProperties.operational_points.find((op) => |
| 180 | + matchOpRefAndOp(pathStepLocation, op) |
| 181 | + ); |
| 182 | + const secondaryCodeMetadata = pathStepMetadata.locationsBySecondaryCode.get( |
| 183 | + matchedOp?.extensions?.sncf?.ch || '' |
| 184 | + ); |
| 185 | + const trackMetadata = secondaryCodeMetadata?.find( |
| 186 | + (metadata) => metadata.trackId === matchedOp?.part.track |
| 187 | + ); |
| 188 | + coordinates = trackMetadata?.coordinates; |
| 189 | + } |
| 190 | + } else { |
| 191 | + // If not, we use the input informations to compute them |
| 192 | + const allCoordinates = computePathStepCoordinates(pathStepMetadata); |
| 193 | + |
| 194 | + coordinates = |
| 195 | + allCoordinates.length === 1 ? allCoordinates[0] : getBarycenter(allCoordinates); |
| 196 | + } |
172 | 197 |
|
173 | | - const coordinates = |
174 | | - allCoordinates.length === 1 ? allCoordinates[0] : getBarycenter(allCoordinates); |
| 198 | + if (!coordinates) return null; |
175 | 199 |
|
176 | 200 | let name = ''; |
177 | 201 | if (pathStepMetadata.type === 'trackOffset') { |
|
0 commit comments