From 3abb322ad1d3c8f85ba4535b10438a13d36bbce9 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 14 Mar 2023 23:26:17 -0400 Subject: [PATCH] Fix leaflet --- web-frontend/src/lib/Map.svelte | 2 + web-frontend/src/lib/common.js | 1 + web-frontend/src/routes/app-lite/+page.svelte | 1 + web-frontend/src/routes/app/+page.svelte | 88 ++++++++++--------- web-frontend/src/routes/app/Error.svelte | 29 ++++++ wordlist/03-exclude.csv | 1 + 6 files changed, 82 insertions(+), 40 deletions(-) create mode 100644 web-frontend/src/routes/app-lite/+page.svelte create mode 100644 web-frontend/src/routes/app/Error.svelte diff --git a/web-frontend/src/lib/Map.svelte b/web-frontend/src/lib/Map.svelte index 8094724..fcf6ab0 100644 --- a/web-frontend/src/lib/Map.svelte +++ b/web-frontend/src/lib/Map.svelte @@ -4,6 +4,7 @@ let mapElement; + export let onMapClick = () => {}; export let map; // export const leaflet; @@ -12,6 +13,7 @@ const leaflet = await import('leaflet'); map = leaflet.map(mapElement).setView([51.505, -0.09], 13); + map.on('click', onMapClick); leaflet .tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { diff --git a/web-frontend/src/lib/common.js b/web-frontend/src/lib/common.js index 7f96454..8962149 100644 --- a/web-frontend/src/lib/common.js +++ b/web-frontend/src/lib/common.js @@ -19,6 +19,7 @@ export async function getWasm() { console.error('Error loading wasm module', e); wasmError = e; wasmStatus = WasmStatus.Errored; + throw e; }); return { diff --git a/web-frontend/src/routes/app-lite/+page.svelte b/web-frontend/src/routes/app-lite/+page.svelte new file mode 100644 index 0000000..b0c847b --- /dev/null +++ b/web-frontend/src/routes/app-lite/+page.svelte @@ -0,0 +1 @@ +

App Lite

diff --git a/web-frontend/src/routes/app/+page.svelte b/web-frontend/src/routes/app/+page.svelte index 92d1489..4466232 100644 --- a/web-frontend/src/routes/app/+page.svelte +++ b/web-frontend/src/routes/app/+page.svelte @@ -4,9 +4,10 @@ import { onMount, onDestroy } from 'svelte'; import AddressInput from '$lib/AddressInput.svelte'; import { browser } from '$app/environment'; - let leaflet; - // import leaflet from 'leaflet'; + // import tick from 'svelte'; + import Error from './Error.svelte'; + let leaflet; import Map from '$lib/Map.svelte'; let map; @@ -19,26 +20,36 @@ call: undefined }; - onMount(async () => { - leaflet = await import('leaflet'); - wasm = await getWasm(); + const onMapClick = (e) => { + let popup = leaflet.popup(); - if (browser) { - let popup = leaflet.popup(); - map.on('click', (e) => { - try { - // TODO: Leaflet allows sending coordinates out of the standard range - latlng = e.latlng; - addr = wasm.call.address_from_lat_lon(latlng.lat, latlng.lng); - popup.setLatLng(e.latlng).setContent(`${addr}`).openOn(map); - } catch (err) { - console.error(err); - addr = ''; - popup.setLatLng(e.latlng).setContent(`You clicked at ${e.latlng}`).openOn(map); - } - }); + try { + latlng = e.latlng; + addr = wasm.call.address_from_lat_lon(latlng.lat, latlng.lng); + popup.setLatLng(e.latlng).setContent(`${addr}`).openOn(map); + } catch (err) { + console.error(err); + addr = ''; + popup.setLatLng(e.latlng).setContent(`You clicked at ${e.latlng}`).openOn(map); } - }); + }; + + let init = async () => { + await getWasm() + .then((w) => (wasm = w)) + .then(async () => { + leaflet = await import('leaflet'); + }) + .catch((err) => { + console.log('Erroring'); + console.error(err); + throw err; + }); + }; + + // onMount(async () => { + // leaflet = await import('leaflet'); + // }); onDestroy(async () => { if (map) { @@ -66,28 +77,25 @@

App

+ +

{outputValue}

-{#if wasm.status == WasmStatus.Loaded || wasm.status == WasmStatus.NotLoaded} + +{#await init()} +

Loading WebAssembly module...

+{:then}

Current cursor: {addr} => ({latlng.lat}, {latlng.lng})

- -{:else if wasm.status == WasmStatus.Errored} -
-
- -
-
-

Could not start core module

-

Error: {wasm.error}.

-
-
-{/if} + +{:catch message} + Could not start core module +{/await} diff --git a/web-frontend/src/routes/app/Error.svelte b/web-frontend/src/routes/app/Error.svelte new file mode 100644 index 0000000..e4f1fd5 --- /dev/null +++ b/web-frontend/src/routes/app/Error.svelte @@ -0,0 +1,29 @@ + + +
+
+ +
+
+

+ + {#if message} +

Message: {message}.

+ {/if} + +

+ You can still use xpin, but you have to go to the lite version of the app +

+
+
diff --git a/wordlist/03-exclude.csv b/wordlist/03-exclude.csv index 873389a..703f424 100644 --- a/wordlist/03-exclude.csv +++ b/wordlist/03-exclude.csv @@ -437,6 +437,7 @@ BRAVO BRAY BRAZIL BRAZILIAN +BREAST BREMEN BRENT BRETON