@@ -55,6 +55,7 @@ import RenderPopup from 'modules/trainschedule/components/ManageTrainSchedule/Ma
55
55
import { updateViewport } from 'reducers/map' ;
56
56
import type { Viewport } from 'reducers/map' ;
57
57
import { getMap , getTerrain3DExaggeration } from 'reducers/map/selectors' ;
58
+ import type { PathStep } from 'reducers/osrdconf/types' ;
58
59
import { useAppDispatch } from 'store' ;
59
60
import { getMapMouseEventNearestFeature } from 'utils/mapHelper' ;
60
61
@@ -64,27 +65,39 @@ import ItineraryMarkersV2 from './ManageTrainScheduleMap/ItineraryMarkersV2';
64
65
type MapProps = {
65
66
pathProperties ?: ManageTrainSchedulePathProperties ;
66
67
setMapCanvas ?: ( mapCanvas : string ) => void ;
68
+ isReadOnly ?: boolean ;
67
69
hideAttribution ?: boolean ;
68
70
hideItinerary ?: boolean ;
69
71
preventPointSelection ?: boolean ;
72
+ mapId ?: string ;
73
+ simulationPathSteps ?: PathStep [ ] ;
70
74
} ;
71
75
72
76
const Map : FC < PropsWithChildren < MapProps > > = ( {
73
77
pathProperties,
74
78
setMapCanvas,
79
+ isReadOnly = false ,
75
80
hideAttribution = false ,
76
81
hideItinerary = false ,
77
82
preventPointSelection = false ,
83
+ mapId = 'map-container' ,
84
+ simulationPathSteps,
78
85
children,
79
86
} ) => {
80
87
const mapBlankStyle = useMapBlankStyle ( ) ;
81
88
82
89
const infraID = useInfraID ( ) ;
83
90
const terrain3DExaggeration = useSelector ( getTerrain3DExaggeration ) ;
84
91
const { viewport, mapSearchMarker, mapStyle, showOSM, layersSettings } = useSelector ( getMap ) ;
92
+ const mapViewport = useMemo (
93
+ ( ) =>
94
+ isReadOnly && pathProperties
95
+ ? computeBBoxViewport ( bbox ( pathProperties ?. geometry ) , viewport )
96
+ : viewport ,
97
+ [ isReadOnly , pathProperties , viewport ]
98
+ ) ;
85
99
86
100
const [ mapIsLoaded , setMapIsLoaded ] = useState ( false ) ;
87
- const [ showLayers , setShowLayers ] = useState ( true ) ;
88
101
89
102
const [ snappedPoint , setSnappedPoint ] = useState < Feature < Point > | undefined > ( ) ;
90
103
const { urlLat = '' , urlLon = '' , urlZoom = '' , urlBearing = '' , urlPitch = '' } = useParams ( ) ;
@@ -119,15 +132,14 @@ const Map: FC<PropsWithChildren<MapProps>> = ({
119
132
120
133
const resetPitchBearing = ( ) => {
121
134
updateViewportChange ( {
122
- ...viewport ,
135
+ ...mapViewport ,
123
136
bearing : 0 ,
124
137
pitch : 0 ,
125
138
} ) ;
126
139
} ;
127
140
128
141
const onFeatureClick = ( e : MapLayerMouseEvent ) => {
129
142
if ( preventPointSelection ) return ;
130
-
131
143
const result = getMapMouseEventNearestFeature ( e , { layersId : [ 'chartis/tracks-geo/main' ] } ) ;
132
144
if (
133
145
result &&
@@ -155,7 +167,6 @@ const Map: FC<PropsWithChildren<MapProps>> = ({
155
167
156
168
const onMoveGetFeature = ( e : MapLayerMouseEvent ) => {
157
169
if ( preventPointSelection ) return ;
158
-
159
170
const result = getMapMouseEventNearestFeature ( e , { layersId : [ 'chartis/tracks-geo/main' ] } ) ;
160
171
if (
161
172
result &&
@@ -193,7 +204,7 @@ const Map: FC<PropsWithChildren<MapProps>> = ({
193
204
useEffect ( ( ) => {
194
205
if ( urlLat ) {
195
206
updateViewportChange ( {
196
- ...viewport ,
207
+ ...mapViewport ,
197
208
latitude : parseFloat ( urlLat ) ,
198
209
longitude : parseFloat ( urlLon ) ,
199
210
zoom : parseFloat ( urlZoom ) ,
@@ -206,60 +217,63 @@ const Map: FC<PropsWithChildren<MapProps>> = ({
206
217
207
218
useEffect ( ( ) => {
208
219
if ( pathProperties ) {
209
- if ( setMapCanvas ) {
210
- setShowLayers ( false ) ;
211
- }
212
- const newViewport = computeBBoxViewport ( bbox ( pathProperties . geometry ) , viewport ) ;
220
+ const newViewport = computeBBoxViewport ( bbox ( pathProperties . geometry ) , mapViewport ) ;
213
221
dispatch ( updateViewport ( newViewport ) ) ;
214
222
}
215
223
} , [ pathProperties ] ) ;
216
224
217
225
const captureMap = async ( ) => {
218
226
if ( ! pathProperties ) return ;
219
227
220
- const itineraryViewport = computeBBoxViewport ( bbox ( pathProperties . geometry ) , viewport ) ;
228
+ const itineraryViewport = computeBBoxViewport ( bbox ( pathProperties . geometry ) , mapViewport ) ;
221
229
222
- if ( setMapCanvas && ! showLayers && isEqual ( viewport , itineraryViewport ) ) {
230
+ if ( setMapCanvas && isEqual ( mapViewport , itineraryViewport ) ) {
223
231
try {
224
- const mapElement = document . getElementById ( 'map-container' ) ;
232
+ const mapElement = document . getElementById ( mapId ) ;
225
233
if ( mapElement ) {
226
234
const canvas = await html2canvas ( mapElement ) ;
227
235
setMapCanvas ( canvas . toDataURL ( ) ) ;
228
236
}
229
237
} catch ( error ) {
230
238
console . error ( 'Error capturing map:' , error ) ;
231
- } finally {
232
- setShowLayers ( true ) ;
233
239
}
234
240
}
235
241
} ;
236
242
237
243
return (
238
244
< >
239
- < MapButtons
240
- map = { mapRef . current ?? undefined }
241
- resetPitchBearing = { resetPitchBearing }
242
- closeFeatureInfoClickPopup = { closeFeatureInfoClickPopup }
243
- bearing = { viewport . bearing }
244
- withMapKeyButton
245
- viewPort = { viewport }
246
- />
245
+ { ! isReadOnly && (
246
+ < MapButtons
247
+ map = { mapRef . current ?? undefined }
248
+ resetPitchBearing = { resetPitchBearing }
249
+ closeFeatureInfoClickPopup = { closeFeatureInfoClickPopup }
250
+ bearing = { mapViewport . bearing }
251
+ withMapKeyButton
252
+ viewPort = { mapViewport }
253
+ />
254
+ ) }
247
255
< ReactMapGL
256
+ dragPan = { false }
257
+ scrollZoom = { false }
248
258
ref = { mapRef }
249
- { ...viewport }
259
+ { ...mapViewport }
250
260
style = { { width : '100%' , height : '100%' } }
251
- cursor = { preventPointSelection ? 'default' : 'pointer' }
261
+ cursor = { isReadOnly || preventPointSelection ? 'default' : 'pointer' }
252
262
mapStyle = { mapBlankStyle }
253
- onMove = { ( e ) => updateViewportChange ( e . viewState ) }
254
- onMouseMove = { onMoveGetFeature }
255
263
attributionControl = { false } // Defined below
256
- onClick = { onFeatureClick }
257
- onResize = { ( e ) => {
258
- updateViewportChange ( {
259
- width : e . target . getContainer ( ) . offsetWidth ,
260
- height : e . target . getContainer ( ) . offsetHeight ,
261
- } ) ;
262
- } }
264
+ { ...( ! isReadOnly && {
265
+ dragPan : true ,
266
+ scrollZoom : true ,
267
+ onMove : ( e ) => updateViewportChange ( e . viewState ) ,
268
+ onMouseMove : onMoveGetFeature ,
269
+ onClick : onFeatureClick ,
270
+ onResize : ( e ) => {
271
+ updateViewportChange ( {
272
+ width : e . target . getContainer ( ) . offsetWidth ,
273
+ height : e . target . getContainer ( ) . offsetHeight ,
274
+ } ) ;
275
+ } ,
276
+ } ) }
263
277
interactiveLayerIds = { interactiveLayerIds }
264
278
touchZoomRotate
265
279
maxPitch = { 85 }
@@ -271,9 +285,11 @@ const Map: FC<PropsWithChildren<MapProps>> = ({
271
285
onLoad = { ( ) => {
272
286
setMapIsLoaded ( true ) ;
273
287
} }
274
- onIdle = { ( ) => captureMap ( ) }
288
+ onIdle = { ( ) => {
289
+ captureMap ( ) ;
290
+ } }
275
291
preserveDrawingBuffer
276
- id = "map-container"
292
+ id = { mapId }
277
293
>
278
294
< VirtualLayers />
279
295
{ ! hideAttribution && (
@@ -325,7 +341,7 @@ const Map: FC<PropsWithChildren<MapProps>> = ({
325
341
layerOrder = { LAYER_GROUPS_ORDER [ LAYERS . ROUTES . GROUP ] }
326
342
infraID = { infraID }
327
343
/>
328
- { showLayers && (
344
+ { ! isReadOnly && (
329
345
< >
330
346
{ layersSettings . operationalpoints && (
331
347
< OperationalPoints
@@ -384,17 +400,22 @@ const Map: FC<PropsWithChildren<MapProps>> = ({
384
400
layerOrder = { LAYER_GROUPS_ORDER [ LAYERS . LINE_SEARCH . GROUP ] }
385
401
infraID = { infraID }
386
402
/>
403
+ < RenderPopup pathProperties = { pathProperties } />
387
404
</ >
388
405
) }
389
- < RenderPopup pathProperties = { pathProperties } />
390
406
{ mapIsLoaded && (
391
407
< >
392
408
< ItineraryLayer
393
409
layerOrder = { LAYER_GROUPS_ORDER [ LAYERS . ITINERARY . GROUP ] }
394
410
geometry = { pathProperties ?. geometry }
395
411
hideItineraryLine = { hideItinerary }
396
412
/>
397
- { mapRef . current && < ItineraryMarkersV2 map = { mapRef . current . getMap ( ) } /> }
413
+ { mapRef . current && (
414
+ < ItineraryMarkersV2
415
+ simulationPathSteps = { simulationPathSteps }
416
+ map = { mapRef . current . getMap ( ) }
417
+ />
418
+ ) }
398
419
</ >
399
420
) }
400
421
{ mapSearchMarker && < SearchMarker data = { mapSearchMarker } colors = { colors [ mapStyle ] } /> }
0 commit comments