From 5146e7f7f62835fbf20ea9c0160f8937b77c3c53 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 10 Jul 2024 17:45:03 +0200 Subject: [PATCH] use nominatim on Enter/Tab --- src/sidebar/search/AddressInput.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/sidebar/search/AddressInput.tsx b/src/sidebar/search/AddressInput.tsx index 3acfde4f..02b69c76 100644 --- a/src/sidebar/search/AddressInput.tsx +++ b/src/sidebar/search/AddressInput.tsx @@ -111,15 +111,25 @@ export default function AddressInput(props: AddressInputProps) { break case 'Enter': case 'Tab': - // try to parse input as coordinate. Otherwise use autocomplete results + // try to parse input as coordinate. Otherwise query nominatim const coordinate = textToCoordinate(text) if (coordinate) { props.onAddressSelected(text, coordinate, getBBoxFromCoord(coordinate)) } else if (autocompleteItems.length > 0) { // by default use the first result, otherwise the highlighted one - const index = highlightedResult >= 0 ? highlightedResult : 0 - const item = autocompleteItems[index] - if (item instanceof GeocodingItem) props.onAddressSelected(item.toText(), item.point, item.bbox) + getApi().geocode(text, 'nominatim').then(result => { + if (result && result.hits.length > 0) { + const hit: GeocodingHit = result.hits[0] + const res = nominatimHitToItem(hit) + const bbox = hit.extent ? hit.extent : getBBoxFromCoord(hit.point) + props.onAddressSelected(res.mainText + ', ' + res.secondText, hit.point, bbox) + } else { + 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: