feat(map): stop flyTo/panTo on champ carte by default

This commit is contained in:
Martin 2024-02-01 17:34:02 +01:00
parent 32dcb411ca
commit 53ae5eeb5b
2 changed files with 14 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import type { FeatureCollection } from 'geojson';
import { useMapLibre } from '../../shared/maplibre/MapLibre'; import { useMapLibre } from '../../shared/maplibre/MapLibre';
import { import {
useFitBounds, useFitBounds,
useFitBoundsNoFly,
useEvent, useEvent,
useMapEvent, useMapEvent,
useFlyTo useFlyTo
@ -117,6 +118,7 @@ function useExternalEvents(
} }
) { ) {
const fitBounds = useFitBounds(); const fitBounds = useFitBounds();
const fitBoundsNoFly = useFitBoundsNoFly();
const flyTo = useFlyTo(); const flyTo = useFlyTo();
const onFeatureFocus = useCallback( const onFeatureFocus = useCallback(
@ -184,10 +186,10 @@ function useExternalEvents(
); );
useEffect(() => { useEffect(() => {
fitBounds(featureCollection.bbox as LngLatBoundsLike); fitBoundsNoFly(featureCollection.bbox as LngLatBoundsLike);
// We only want to zoom on bbox on component mount. // We only want to zoom on bbox on component mount.
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [fitBounds]); }, [fitBoundsNoFly]);
useEvent('map:feature:focus', onFeatureFocus); useEvent('map:feature:focus', onFeatureFocus);
useEvent('map:feature:create', onFeatureCreate); useEvent('map:feature:create', onFeatureCreate);

View file

@ -26,6 +26,16 @@ export function useFitBounds() {
); );
} }
export function useFitBoundsNoFly() {
const map = useMapLibre();
return useCallback(
(bbox: LngLatBoundsLike) => {
map.fitBounds(bbox, { padding: 100, linear: true, duration: 0 });
},
[map]
);
}
export function useFlyTo() { export function useFlyTo() {
const map = useMapLibre(); const map = useMapLibre();
return useCallback( return useCallback(