From 77b6683e0af6440d4ef5a086241da5d034dafe35 Mon Sep 17 00:00:00 2001 From: Michael Zilske Date: Wed, 17 Jul 2024 16:26:26 +0200 Subject: [PATCH] Revert "use nominatim on Enter/Tab" This reverts commit 5146e7f7f62835fbf20ea9c0160f8937b77c3c53. Revert "clean up" This reverts commit b988eeb7c06d1b320de65b646ea119addf2814bb. --- src/sidebar/search/AddressInput.tsx | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/sidebar/search/AddressInput.tsx b/src/sidebar/search/AddressInput.tsx index 241eea81..230acd11 100644 --- a/src/sidebar/search/AddressInput.tsx +++ b/src/sidebar/search/AddressInput.tsx @@ -25,7 +25,7 @@ export interface AddressInputProps { point: QueryPoint points: QueryPoint[] onCancel: () => void - onAddressSelected: (queryText: string, coord: Coordinate | undefined) => void + onAddressSelected: (queryText: string, coord: Coordinate | undefined, bbox: Bbox | undefined) => void onChange: (value: string) => void clearDragDrop: () => void moveStartIndex: number @@ -113,24 +113,15 @@ export default function AddressInput(props: AddressInputProps) { break case 'Enter': case 'Tab': - // try to parse input as coordinate. Otherwise query nominatim + // try to parse input as coordinate. Otherwise use autocomplete results const coordinate = textToCoordinate(text) if (coordinate) { - props.onAddressSelected(text, coordinate) + props.onAddressSelected(text, coordinate, getBBoxFromCoord(coordinate)) } else if (autocompleteItems.length > 0) { // by default use the first result, otherwise the highlighted one - getApi().geocode(text, 'nominatim').then(result => { - if (result && result.hits.length > 0) { - const hit: GeocodingHit = result.hits[0] - const res = nominatimHitToItem(hit) - props.onAddressSelected(res.mainText + ', ' + res.secondText, hit.point) - } else { - const index = highlightedResult >= 0 ? highlightedResult : 0 - const item = autocompleteItems[index] - if (item instanceof GeocodingItem) - props.onAddressSelected(item.toText(), item.point) - } - }) + const index = highlightedResult >= 0 ? highlightedResult : 0 + const item = autocompleteItems[index] + if (item instanceof GeocodingItem) props.onAddressSelected(item.toText(), item.point, item.bbox) } inputElement.blur() // onBlur is deactivated for mobile so force: @@ -224,7 +215,7 @@ export default function AddressInput(props: AddressInputProps) { setHasFocus(false) if (item instanceof GeocodingItem) { hideSuggestions() - props.onAddressSelected(item.toText(), item.point) + props.onAddressSelected(item.toText(), item.point, item.bbox) } else if (item instanceof SelectCurrentLocationItem) { hideSuggestions() onCurrentLocationSelected(props.onAddressSelected)