-
Notifications
You must be signed in to change notification settings - Fork 84
front: add bbox fetching and viewport adjustment #18052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { useCallback, useEffect, useMemo, useRef, useState, type PropsWithChildren } from 'react'; | ||
|
|
||
| import { skipToken } from '@reduxjs/toolkit/query'; | ||
| import type { Feature, Position } from 'geojson'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import type { MapLayerMouseEvent, MapRef } from 'react-map-gl/maplibre'; | ||
|
|
@@ -16,6 +17,7 @@ import MapButtons from 'common/Map/Buttons/MapButtons'; | |
| import PathStepMarker, { PATH_STEP_MARKER_STATE } from 'common/Map/components/PathStepMarker'; | ||
| import { SnappedMarker } from 'common/Map/Layers'; | ||
| import { MapContextProvider } from 'common/Map/useMapContext'; | ||
| import { computeBBoxViewport } from 'common/Map/WarpedMap/core/helpers'; | ||
| import { useInfraID } from 'common/osrdContext'; | ||
| import { LAYER_GROUPS_ORDER, LAYERS } from 'config/layerOrder'; | ||
| import Itinerary from 'modules/simulationResult/components/SimulationResultsMap/RenderItinerary'; | ||
|
|
@@ -103,6 +105,25 @@ const ItineraryModalMap = ({ | |
| const lastRealStepIndex = pathSteps ? pathSteps.length - (lastStepHasLocation ? 1 : 2) : -1; | ||
|
|
||
| const isNewPlacement = isMapSelectionMode; | ||
| const locatedStepsCount = useMemo( | ||
| () => pathSteps?.filter((step) => step.location !== null).length ?? 0, | ||
| [pathSteps] | ||
| ); | ||
|
|
||
| const { data: infraBbox } = osrdEditoastApi.endpoints.getInfraByInfraIdBbox.useQuery( | ||
| infraID ? { infraId: infraID } : skipToken | ||
| ); | ||
|
|
||
| useMemo(() => { | ||
| if (infraBbox === undefined) return; | ||
| if (locatedStepsCount >= 2) return; | ||
| const { min_lat, min_lon, max_lat, max_lon } = infraBbox!; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nit: I think you can get rid of this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not nit because otherwise, if |
||
|
|
||
| const newViewport = computeBBoxViewport([min_lon, min_lat, max_lon, max_lat], viewport, { | ||
| padding: 64, | ||
| }); | ||
| updateViewport(newViewport); | ||
| }, [infraBbox, locatedStepsCount]); | ||
|
|
||
| useEffect(() => { | ||
| if (!isMapSelectionMode) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useMemo()is supposed to return a value. Here, no value is returned.setViewport()does not integrate well with React here, unfortunately. Ideally the return value ofuseMemo()would be used as the initial viewport.As-is, this patch results in a glitch: the map is first displayed with an arbitrary default viewport, then it's updated later on with the infra's bbox. Ideally the map would not show up until we have the infra's bbox.