Skip to content

Commit

Permalink
Revert "use nominatim on Enter/Tab"
Browse files Browse the repository at this point in the history
This reverts commit 5146e7f.

Revert "clean up"

This reverts commit b988eeb.
  • Loading branch information
michaz committed Jul 17, 2024
1 parent 1477065 commit 77b6683
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/sidebar/search/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 77b6683

Please sign in to comment.