Skip to content

Commit

Permalink
forward zoom param
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Jul 18, 2024
1 parent 609f0cd commit 6e1b099
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/sidebar/search/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default function AddressInput(props: AddressInputProps) {
onChange={e => {
setText(e.target.value)
const coordinate = textToCoordinate(e.target.value)
if (!coordinate) geocoder.request(e.target.value, biasCoord, 'default')
if (!coordinate) geocoder.request(e.target.value, biasCoord, getMap().getView().getZoom())
props.onChange(e.target.value)
}}
onKeyDown={onKeypress}
Expand Down Expand Up @@ -301,24 +301,25 @@ class Geocoder {
this.onSuccess = onSuccess
}

request(query: string, bias: Coordinate | undefined, provider: string) {
this.requestAsync(query, bias, provider).then(() => {})
request(query: string, bias: Coordinate | undefined, zoom = 11) {
this.requestAsync(query, bias, zoom).then(() => {})
}

cancel() {
// invalidates last request if there is one
this.getNextId()
}

async requestAsync(query: string, bias: Coordinate | undefined, provider: string) {
async requestAsync(query: string, bias: Coordinate | undefined, zoom: number) {
const provider = 'default'
const currentId = this.getNextId()
this.timeout.cancel()
if (!query || query.length < 2) return

await this.timeout.wait()
try {
const options: Record<string, string> = bias
? { point: coordinateToText(bias), location_bias_scale: '0.5', zoom: '11' }
? { point: coordinateToText(bias), location_bias_scale: '0.5', zoom: '' + (zoom + 1) }
: {}
const result = await this.api.geocode(query, provider, options)
const hits = Geocoder.filterDuplicates(result.hits)
Expand Down

0 comments on commit 6e1b099

Please sign in to comment.