forked from MapComplete/MapComplete
UX: more work on a search function
This commit is contained in:
parent
3cd04df60b
commit
00ad21d5ef
30 changed files with 636 additions and 138 deletions
|
|
@ -9,13 +9,35 @@ export default class CombinedSearcher implements GeocodingProvider {
|
|||
this._providersWithSuggest = providers.filter(pr => pr.suggest !== undefined)
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the geocode-results from various sources.
|
||||
* If the same osm-id is mentioned multiple times, only the first result will be kept
|
||||
* @param geocoded
|
||||
* @private
|
||||
*/
|
||||
private merge(geocoded: GeoCodeResult[][]): GeoCodeResult[]{
|
||||
const results : GeoCodeResult[] = []
|
||||
const seenIds = new Set<string>()
|
||||
for (const geocodedElement of geocoded) {
|
||||
for (const entry of geocodedElement) {
|
||||
const id = entry.osm_type+ entry.osm_id
|
||||
if(seenIds.has(id)){
|
||||
continue
|
||||
}
|
||||
seenIds.add(id)
|
||||
results.push(entry)
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
async search(query: string, options?: GeocodingOptions): Promise<GeoCodeResult[]> {
|
||||
const results = await Promise.all(this._providers.map(pr => pr.search(query, options)))
|
||||
return results.flatMap(x => x)
|
||||
return this.merge(results)
|
||||
}
|
||||
|
||||
async suggest(query: string, options?: GeocodingOptions): Promise<GeoCodeResult[]> {
|
||||
const results = await Promise.all(this._providersWithSuggest.map(pr => pr.suggest(query, options)))
|
||||
return results.flatMap(x => x)
|
||||
return this.merge(results)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue