From 70ac7b95e6a822790c369785721c825e9ad4f215 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Fri, 5 Jun 2026 17:41:55 +0100 Subject: [PATCH] Fix flyto --- frontend/src/components/map/LocationSearch.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/map/LocationSearch.tsx b/frontend/src/components/map/LocationSearch.tsx index 0f2caa4..f3d7177 100644 --- a/frontend/src/components/map/LocationSearch.tsx +++ b/frontend/src/components/map/LocationSearch.tsx @@ -146,6 +146,12 @@ export default function LocationSearch({ if (result.type === 'place') { const zoom = ZOOM_FOR_TYPE[result.place_type] ?? 14; const flyZoom = result.place_type === 'outcode' ? POSTCODE_SEARCH_ZOOM : zoom; + // Move the camera straight away using the coordinates already in the + // search result. The nearest-postcode lookup below only feeds the side + // panel, so gating the fly on it (and on isCurrentLookup) made the jump + // intermittent whenever that request was slow, failed, or was superseded + // by another keystroke/selection. + if (!isMobile) onFlyTo(result.lat, result.lon, flyZoom); try { const params = new URLSearchParams({ lat: String(result.lat), @@ -172,7 +178,6 @@ export default function LocationSearch({ markerLatitude: result.lat, markerLongitude: result.lon, }); - if (!isMobile) onFlyTo(result.lat, result.lon, flyZoom); search.saveRecentSearch(result); search.clear(); if (isMobile) setExpanded(false); @@ -189,6 +194,10 @@ export default function LocationSearch({ } if (result.type === 'address') { + // Fly from the result's own coordinates immediately; the postcode fetch + // below only resolves the geometry for the side panel. See the note in + // the place branch above. + if (!isMobile) onFlyTo(result.lat, result.lon, 17); try { const res = await fetch( `/api/postcode/${encodeURIComponent(result.postcode)}`, @@ -201,7 +210,6 @@ export default function LocationSearch({ } const json: PostcodeLookupResponse = await res.json(); if (!isCurrentLookup(requestId, controller)) return; - if (!isMobile) onFlyTo(result.lat, result.lon, 17); onLocationSearched?.({ postcode: json.postcode, geometry: json.geometry, @@ -228,7 +236,9 @@ export default function LocationSearch({ return; } - // Postcode — fetch geometry + // Postcode — fetch geometry. Unlike place/address results, a postcode + // result carries no coordinates, so the camera move genuinely depends on + // this response and stays gated by isCurrentLookup. try { const res = await fetch( `/api/postcode/${encodeURIComponent(result.label)}`,