commit 07b3262e5452555c1b5412596898b1060b414ed4
parent ab7030111658ece201d05744853219aff310ec45
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Sun, 6 Oct 2024 16:17:14 +0000
Add `@radroots/geocoder`, add geocoder database connect to root layout, update location gcs add utils, update types, add sql wasm file to static assets, update dependencies
Diffstat:
8 files changed, 37 insertions(+), 18 deletions(-)
diff --git a/package.json b/package.json
@@ -24,6 +24,7 @@
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/node": "^20.12.7",
+ "@types/sql.js": "^1.4.9",
"autoprefixer": "^10.4.19",
"daisyui": "^4.10.0",
"postcss": "^8.4.38",
@@ -58,6 +59,7 @@
"@radroots/capacitor-sqlite": "workspace:*",
"@radroots/capacitor-wifi": "workspace:*",
"@radroots/client": "workspace:*",
+ "@radroots/geocoder": "workspace:*",
"@radroots/models": "workspace:*",
"@radroots/svelte-lib": "workspace:*",
"@radroots/svelte-maplibre": "workspace:*",
@@ -67,6 +69,7 @@
"loader": "link:@ionic/pwa-elements/loader",
"maplibre-gl": "^4.0.0",
"pmtiles": "^3.0.3",
- "protomaps-themes-base": "^3.1.0"
+ "protomaps-themes-base": "^3.1.0",
+ "sql.js": "^1.11.0"
}
}
\ No newline at end of file
diff --git a/src/app.html b/src/app.html
@@ -10,7 +10,7 @@
<link rel="stylesheet" type="text/css" href="/phosphor-icons/regular.css" />
<link rel="stylesheet" type="text/css" href="/stylesheets/maplibre-gl.css" />
- <script src="/assets/keyva.min.js"></script>
+ <script src="/keyva.min.js"></script>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no viewport-fit=cover" />
diff --git a/src/lib/client.ts b/src/lib/client.ts
@@ -1,5 +1,6 @@
import { PUBLIC_DATABASE_NAME } from "$env/static/public";
import { ClientCapacitor } from "@radroots/client";
+import { Geocoder } from "@radroots/geocoder";
import { location_gcs_table, nostr_profile_relay_table, nostr_profile_table, nostr_relay_table, trade_product_table } from "@radroots/models";
export const lc = new ClientCapacitor({
@@ -20,3 +21,5 @@ export const lc = new ClientCapacitor({
]
}
});
+
+export const geoc = new Geocoder(`/geonames/geonames.db`);
diff --git a/src/lib/utils/location_gcs.ts b/src/lib/utils/location_gcs.ts
@@ -1,4 +1,5 @@
-import { lc } from "$lib/client";
+import { geoc, lc } from "$lib/client";
+import type { LocationGcsFormFields } from "@radroots/models";
import { location_geohash } from "@radroots/utils";
export const location_gcs_add = async (): Promise<boolean> => {
@@ -19,19 +20,27 @@ export const location_gcs_add = async (): Promise<boolean> => {
await lc.dialog.alert(`A location name is required.`);
return false;
}
-
- const { lat, lng } = loc_gcs;
- const geohash = location_geohash(
- lat,
- lng,
- );
+ const opts: LocationGcsFormFields = {
+ lat: loc_gcs.lat.toString(),
+ lng: loc_gcs.lng.toString(),
+ geohash: location_geohash(loc_gcs),
+ label: loc_gcs_label,
+ }
+ const gc_reverse = await geoc.reverse({
+ point: loc_gcs
+ });
+ if (typeof gc_reverse !== `string` && gc_reverse.results.length > 0) {
+ const gc_result = gc_reverse.results[0];
+ opts.gc_id = gc_result.id.toString();
+ opts.gc_name = gc_result.name;
+ opts.gc_admin1_id = gc_result.admin1_id.toString();
+ opts.gc_admin1_name = gc_result.admin1_name;
+ opts.gc_country_id = gc_result.country_id;
+ opts.gc_country_name = gc_result.country_name;
+ };
+ console.log(JSON.stringify(opts, null, 4), `opts`)
const exe_res =
- await lc.db.location_gcs_add({
- lat: lat.toString(),
- lng: lng.toString(),
- geohash,
- label: loc_gcs_label,
- });
+ await lc.db.location_gcs_add(opts);
console.log(`exe_res `, exe_res)
if (
typeof exe_res !== `string` &&
diff --git a/src/routes/(app)/map/choose-location/+page.svelte b/src/routes/(app)/map/choose-location/+page.svelte
@@ -13,12 +13,12 @@
import { MapLibre, Marker } from "@radroots/svelte-maplibre";
import {
location_geohash,
- type GeolocationCoordinates,
+ type GeolocationCoordinatesPoint,
} from "@radroots/utils";
import { onMount } from "svelte";
let loading_layout = true;
- let map_coords: GeolocationCoordinates | undefined = undefined;
+ let map_coords: GeolocationCoordinatesPoint | undefined = undefined;
onMount(async () => {
try {
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
@@ -1,6 +1,6 @@
<script lang="ts">
import { browser } from "$app/environment";
- import { lc } from "$lib/client";
+ import { geoc, lc } from "$lib/client";
import { _conf } from "$lib/conf";
import {
app_nostr_key,
@@ -77,6 +77,10 @@
}
app_sqlite.set(!!db_connected);
+ console.log(`connect geocoder!!`);
+ const geoc_connected = await geoc.connect();
+ console.log(`geoc_connected `, geoc_connected);
+
const active_key_public = await lc.preferences.get(
_conf.kv.nostr_key_active,
);
diff --git a/static/assets/keyva.min.js b/static/keyva.min.js
diff --git a/static/sql-wasm.wasm b/static/sql-wasm.wasm
Binary files differ.