fixes
This commit is contained in:
parent
3fd64785a2
commit
44b4e0d72f
3 changed files with 32 additions and 20 deletions
|
|
@ -895,22 +895,36 @@ export default memo(function Map({
|
|||
|
||||
const handleFlyTo = useCallback(
|
||||
(lat: number, lng: number, zoom: number, options?: MapFlyToOptions) => {
|
||||
setInternalViewState((prev) => {
|
||||
const targetPoint =
|
||||
getViewportRelativeVisibleAreaCenter(dimensions, containerRef.current, options) ??
|
||||
getMapRelativeVisibleAreaCenter(dimensions, options);
|
||||
const center = getMapCenterForTargetScreenPoint(
|
||||
lat,
|
||||
lng,
|
||||
zoom,
|
||||
dimensions.width,
|
||||
dimensions.height,
|
||||
targetPoint.x,
|
||||
targetPoint.y
|
||||
);
|
||||
const targetPoint =
|
||||
getViewportRelativeVisibleAreaCenter(dimensions, containerRef.current, options) ??
|
||||
getMapRelativeVisibleAreaCenter(dimensions, options);
|
||||
const center = getMapCenterForTargetScreenPoint(
|
||||
lat,
|
||||
lng,
|
||||
zoom,
|
||||
dimensions.width,
|
||||
dimensions.height,
|
||||
targetPoint.x,
|
||||
targetPoint.y
|
||||
);
|
||||
|
||||
return { ...prev, ...center, zoom };
|
||||
});
|
||||
// Drive the camera imperatively rather than only through the controlled
|
||||
// `viewState` prop. In controlled mode react-map-gl silently DROPS view
|
||||
// state updates while the map is mid-movement — _updateViewState writes to
|
||||
// the real transform only `if (!map.isMoving())`. So a fly issued right
|
||||
// after a scroll-zoom or pan, while inertia is still settling, was being
|
||||
// ignored, which is why the jump/zoom only landed sometimes. stop() cancels
|
||||
// any in-flight animation/inertia and jumpTo then applies unconditionally;
|
||||
// its move events sync `internalViewState` back through handleMove.
|
||||
const map = mapRef.current;
|
||||
if (map) {
|
||||
map.stop();
|
||||
map.jumpTo({ center: [center.longitude, center.latitude], zoom });
|
||||
} else {
|
||||
// Map not mounted yet (e.g. an initial deep-link selection before load):
|
||||
// seed the controlled state so it applies once react-map-gl initialises.
|
||||
setInternalViewState((prev) => ({ ...prev, ...center, zoom }));
|
||||
}
|
||||
},
|
||||
[dimensions]
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue