Skip to content

Commit cd7f264

Browse files
committed
fix: don't auto-zoom the map after generating a route from clicked points
The route-fit effect fired any time the route went from empty to non-empty, which included the very first route after dropping the first two points — yanking the view away from wherever the user was already looking. Now only fires for imported routes, where the map genuinely hasn't been positioned for that route yet.
1 parent bc9f118 commit cd7f264

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎components/Map.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,15 @@ const Map: React.FC<MapProps> = ({ bbox, onBBoxChange, route, hoveredPoint, stra
504504
return combineRiddenOverlay(precomputedRidden, fresh);
505505
}, [precomputedRidden, stravaRoads, allRoads]);
506506

507-
// Fit map whenever the route first appears (e.g. after import)
507+
// Fit map whenever an imported route first appears. Only imports — the
508+
// user hasn't positioned the map for that route's location yet, unlike
509+
// clicking points, where they're already looking at where they want to
510+
// route and don't want the view yanked out from under them.
508511
const prevRouteRef = React.useRef<typeof route>(null);
509512
React.useEffect(() => {
510513
const wasEmpty = !prevRouteRef.current || prevRouteRef.current.length === 0;
511514
const hasRoute = route && route.length > 1;
512-
if (wasEmpty && hasRoute && mapRef.current) {
515+
if (wasEmpty && hasRoute && isImportedRoute && mapRef.current) {
513516
const lats = route!.map(p => p[1]);
514517
const lons = route!.map(p => p[0]);
515518
mapRef.current.fitBounds(

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "street-sweep",
3-
"version": "0.6.51",
3+
"version": "0.6.52",
44
"private": true,
55
"scripts": {
66
"dev": "next dev -p 3888",

0 commit comments

Comments
 (0)