forked from MapComplete/MapComplete
Search: use 'searchbar' where applicable, refactoring
This commit is contained in:
parent
bcd53405c8
commit
9b8c300e77
28 changed files with 403 additions and 582 deletions
|
@ -1,11 +1,11 @@
|
|||
import GeocodingProvider, { SearchResult } from "./GeocodingProvider"
|
||||
import GeocodingProvider, { GeocodeResult } from "./GeocodingProvider"
|
||||
import { Utils } from "../../Utils"
|
||||
import { ImmutableStore, Store } from "../UIEventSource"
|
||||
|
||||
/**
|
||||
* A simple search-class which interprets possible locations
|
||||
*/
|
||||
export default class CoordinateSearch implements GeocodingProvider {
|
||||
export default class CoordinateSearch implements GeocodingProvider<GeocodeResult> {
|
||||
private static readonly latLonRegexes: ReadonlyArray<RegExp> = [
|
||||
/^(-?[0-9]+\.[0-9]+)[ ,;/\\]+(-?[0-9]+\.[0-9]+)/,
|
||||
/lat[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?[ ,;&]+lon[:=]? *['"]?(-?[0-9]+\.[0-9]+)['"]?/,
|
||||
|
@ -59,9 +59,9 @@ export default class CoordinateSearch implements GeocodingProvider {
|
|||
* results.length // => 1
|
||||
* results[0] // => {lat: -57.5802905, lon: -12.7202538, display_name: "lon: -12.7202538, lat: -57.5802905", "category": "coordinate", "source": "coordinate:latlon"}
|
||||
*/
|
||||
private directSearch(query: string): SearchResult[] {
|
||||
private directSearch(query: string): GeocodeResult[] {
|
||||
|
||||
const matches = Utils.NoNull(CoordinateSearch.latLonRegexes.map(r => query.match(r))).map(m => <SearchResult>{
|
||||
const matches = Utils.NoNull(CoordinateSearch.latLonRegexes.map(r => query.match(r))).map(m => <GeocodeResult>{
|
||||
lat: Number(m[1]),
|
||||
lon: Number(m[2]),
|
||||
display_name: "lon: " + m[2] + ", lat: " + m[1],
|
||||
|
@ -71,7 +71,7 @@ export default class CoordinateSearch implements GeocodingProvider {
|
|||
|
||||
|
||||
const matchesLonLat = Utils.NoNull(CoordinateSearch.lonLatRegexes.map(r => query.match(r)))
|
||||
.map(m => <SearchResult>{
|
||||
.map(m => <GeocodeResult>{
|
||||
lat: Number(m[2]),
|
||||
lon: Number(m[1]),
|
||||
display_name: "lon: " + m[1] + ", lat: " + m[2],
|
||||
|
@ -81,11 +81,11 @@ export default class CoordinateSearch implements GeocodingProvider {
|
|||
return matches.concat(matchesLonLat)
|
||||
}
|
||||
|
||||
suggest(query: string): Store<SearchResult[]> {
|
||||
suggest(query: string): Store<GeocodeResult[]> {
|
||||
return new ImmutableStore(this.directSearch(query))
|
||||
}
|
||||
|
||||
async search (query: string): Promise<SearchResult[]> {
|
||||
async search (query: string): Promise<GeocodeResult[]> {
|
||||
return this.directSearch(query)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue