Skip to content

Commit 089e966

Browse files
Working search!
1 parent 7db0a35 commit 089e966

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"devDependencies": {
1313
"@rollup/plugin-commonjs": "25.0.7",
1414
"@rollup/plugin-json": "6.1.0",
15-
"@rollup/plugin-wasm": "6.2.2",
1615
"@rollup/plugin-node-resolve": "15.2.3",
1716
"@rollup/plugin-terser": "0.4.4",
1817
"@rollup/plugin-typescript": "11.1.5",
18+
"@rollup/plugin-wasm": "6.2.2",
1919
"@tsconfig/svelte": "5.0.2",
2020
"@types/human-date": "^1.4.0",
2121
"autoprefixer": "10.4.13",

src/components/MapSearch.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
} catch {}
4343
searching = false;
4444
debouncedQuery = query;
45-
}, 500);
45+
}, 0);
4646
4747
$: searching = debouncedQuery !== query;
4848
$: {

src/search/geocode.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ export interface GeocodeResult {
1010
type: string;
1111
}
1212

13+
let initPromise: Promise<typeof import('nz-search')>;
14+
function getSearch() {
15+
if (!initPromise) {
16+
initPromise = (async () => {
17+
const [places, searchApi] = await Promise.all([(await fetch('data/places.json')).arrayBuffer(), import('nz-search')])
18+
await searchApi.default()
19+
searchApi.load_data(new Uint8Array(places))
20+
return searchApi
21+
})()
22+
}
23+
return initPromise
24+
}
25+
1326
const searchOsm = async (query: string): Promise<GeocodeResult[]> => {
1427
// Hackily include the country because the nominatim API is terrible.
1528
query = query + ", NZ";
@@ -23,17 +36,10 @@ const searchOsm = async (query: string): Promise<GeocodeResult[]> => {
2336
}
2437

2538
const searchNzPlaces = async (query: string): Promise<GeocodeResult[]> => {
26-
const api = await import('nz-search').then(async search => {
27-
await search.default();
28-
return search
29-
})
39+
const api = await getSearch()
3040

31-
const results = api.search(query)
41+
const results = api.search(query, 100)
3242
return results
33-
// const url = `${nzPlacesUrl}?query=${encodeURIComponent(query)}`;
34-
// const response = await fetch(url);
35-
// const data = await response.json();
36-
// return data;
3743
}
3844

3945
export default async (query: string, sources=[searchNzPlaces]): Promise<GeocodeResult[]> => {

0 commit comments

Comments
 (0)