Skip to content
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

front: map smooth animation configuration for pathfinding errors #8406

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading