Skip to content

Commit a94afe2

Browse files
committed
check if map is loaded
1 parent e96488b commit a94afe2

File tree

2 files changed

+13
-8
lines changed
  • front/src/applications/osrd/views

2 files changed

+13
-8
lines changed

front/src/applications/osrd/views/OSRDConfig/Map.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ import osmBlankStyle from 'common/Map/Layers/osmBlankStyle';
4949

5050
import 'common/Map/Map.scss';
5151

52-
interface MapProps {
53-
setMapLoaded: (boolean) => void;
54-
}
55-
56-
function Map({ setMapLoaded }: MapProps) {
52+
function Map() {
5753
const { viewport, mapSearchMarker, mapStyle, mapTrackSources, showOSM, layersSettings } =
5854
useSelector((state: RootState) => state.map);
5955
const [idHover, setIdHover] = useState();

front/src/applications/osrd/views/OSRDSimulation/Map.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ function checkIfEcoAndAddPrefix(allowancesSettings, id, baseKey) {
6969
return baseKey;
7070
}
7171

72-
function Map(props) {
72+
interface MapProps {
73+
setExtViewport: (any) => void;
74+
}
75+
function Map(props: MapProps) {
7376
const { setExtViewport } = props;
77+
const [mapLoaded, setMapLoaded] = useState(false);
7478
const { viewport, mapSearchMarker, mapStyle, mapTrackSources, showOSM, layersSettings } =
7579
useSelector((state: RootState) => state.map);
7680
const { isPlaying, selectedTrain, positionValues, timePosition, allowancesSettings } =
@@ -229,7 +233,7 @@ function Map(props) {
229233
};
230234

231235
const onFeatureHover = (e) => {
232-
if (!isPlaying && e && geojsonPath?.geometry?.coordinates) {
236+
if (mapLoaded && !isPlaying && e && geojsonPath?.geometry?.coordinates) {
233237
const line = lineString(geojsonPath.geometry.coordinates);
234238
const cursorPoint = point(e.lngLat);
235239
const key = getRegimeKey(simulation.trains[selectedTrain].id);
@@ -271,7 +275,7 @@ function Map(props) {
271275

272276
function defineInteractiveLayers() {
273277
const interactiveLayersLocal: string[] = [];
274-
if (geojsonPath) {
278+
if (mapLoaded && geojsonPath) {
275279
interactiveLayersLocal.push('geojsonPath');
276280
interactiveLayersLocal.push('main-train-path');
277281
otherTrainsHoverPosition.forEach((train) => {
@@ -315,6 +319,10 @@ function Map(props) {
315319
}
316320
}, [timePosition]);
317321

322+
const handleLoadFinished = () => {
323+
setMapLoaded(true);
324+
};
325+
318326
return (
319327
<>
320328
<MapButtons resetPitchBearing={resetPitchBearing} />
@@ -333,6 +341,7 @@ function Map(props) {
333341
interactiveLayerIds={interactiveLayerIds}
334342
touchRotate
335343
asyncRender
344+
onLoad={handleLoadFinished}
336345
>
337346
<AttributionControl
338347
className="attribution-control"

0 commit comments

Comments
 (0)