Skip to content

Commit

Permalink
front: map smooth animation configuration for pathfinding errors
Browse files Browse the repository at this point in the history
Fix #8404

Signed-off-by: Benoit Simard <contact@bsimard.com>
  • Loading branch information
sim51 committed Oct 22, 2024
1 parent 02e76f0 commit b375a45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { useMemo } from 'react';

import { debounce, sortBy } from 'lodash';
import { useMap } from 'react-map-gl/maplibre';
import { useSelector } from 'react-redux';

import { getMap } from 'reducers/map/selectors';

import IncompatibleConstraintItem from './IncompatibleConstraintsItem';
import type { IncompatibleConstraintEnhanced } from './types';
Expand All @@ -21,6 +24,7 @@ const IncompatibleConstraintsList = ({
onHover,
onSelect,
}: IncompatibleConstraintListProps) => {
const { smoothTravel } = useSelector(getMap);
const map = useMap();
const items = useMemo(() => sortBy(data, ['start', 'end']), [data]);

Expand All @@ -40,7 +44,7 @@ const IncompatibleConstraintsList = ({
onClick={() => onSelect(item.id)}
gotoMap={() => {
if (!isSelected) onSelect(item.id);
map.current?.fitBounds(item.bbox);
map.current?.fitBounds(item.bbox, { animate: smoothTravel });
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@ import bbox from '@turf/bbox';
import type { FeatureCollection, LineString } from '@turf/helpers';
import { useTranslation } from 'react-i18next';
import { useMap } from 'react-map-gl/maplibre';
import { useSelector } from 'react-redux';

import { getMap } from 'reducers/map/selectors';

interface IncompatibleConstraintsMapFocusProps extends HTMLAttributes<unknown> {
geojson?: FeatureCollection<LineString, unknown>;
}

const IncompatibleConstraintsMapFocus = (props: IncompatibleConstraintsMapFocusProps) => {
const map = useMap();
const { smoothTravel } = useSelector(getMap);
const { t } = useTranslation(['operationalStudies/manageTrainSchedule']);
const { geojson, ...attrs } = props;

const mapFocusOnPath = useCallback(() => {
if (geojson) {
map.current?.fitBounds(bbox(geojson) as [number, number, number, number]);
map.current?.fitBounds(bbox(geojson) as [number, number, number, number], {
animate: smoothTravel,
});
}
}, [map, geojson]);
}, [map, geojson, smoothTravel]);

return (
<button
Expand Down

0 comments on commit b375a45

Please sign in to comment.