From acc29a704f0f73cac29f8d750de122f29b886e36 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sun, 19 Mar 2023 13:03:19 -0400 Subject: [PATCH] Map location and improvements --- justfile | 2 +- web-frontend/src/lib/Map.svelte | 20 ++++++++++++- web-frontend/src/lib/common.js | 3 +- web-frontend/src/routes/app/+page.svelte | 38 ++++++++++++------------ xpin-wasm/src/lib.rs | 7 +++++ 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/justfile b/justfile index 834ecbe..408db79 100644 --- a/justfile +++ b/justfile @@ -12,7 +12,7 @@ rust-build: docs-build output-clean cargo build -p web --release --target x86_64-unknown-linux-musl earthly +rust-image -wasm-build: output-clean +wasm-build: wasm-pack build --target web xpin-wasm # wasm2js xpin-wasm/pkg/xpin_wasm_bg.wasm -o xpin-wasm/pkg/xpin_wasm_bg.wasm.js # sed -i 's/xpin_wasm_bg.wasm/xpin_wasm_bg.wasm.js/' xpin-wasm/pkg/wasm2js.js xpin-wasm/pkg/wasm2js_bg.js diff --git a/web-frontend/src/lib/Map.svelte b/web-frontend/src/lib/Map.svelte index fcf6ab0..3ba2205 100644 --- a/web-frontend/src/lib/Map.svelte +++ b/web-frontend/src/lib/Map.svelte @@ -1,12 +1,23 @@
+
diff --git a/web-frontend/src/lib/common.js b/web-frontend/src/lib/common.js index 7e12429..5e4c0ce 100644 --- a/web-frontend/src/lib/common.js +++ b/web-frontend/src/lib/common.js @@ -12,7 +12,8 @@ export function getxpin(xpin) { } return { address: xpin.get_address(), - latLon: xpin.get_lat_lon() + latLon: xpin.get_lat_lon(), + decimalDegrees: xpin.get_decimal_degrees() }; } diff --git a/web-frontend/src/routes/app/+page.svelte b/web-frontend/src/routes/app/+page.svelte index db51d07..fa6fc08 100644 --- a/web-frontend/src/routes/app/+page.svelte +++ b/web-frontend/src/routes/app/+page.svelte @@ -12,7 +12,7 @@ let map; - let latlng = { lat: '', lng: '' }; + // let latlngInputValue = { lat: '', lng: '' }; let addr = emptyxpin; let addrInputValue = ''; @@ -22,11 +22,9 @@ call: undefined }; - const onMapClick = (e) => { + const updateEditedAddress = (latlng) => { let popup = leaflet.popup(); - try { - latlng = e.latlng; addr = getxpin(wasm.call.EncodedAddress.from_lat_lon(latlng.lat, latlng.lng)); addrInputValue = addr.address; popup @@ -36,15 +34,25 @@ }) .setContent(`${addr.address}`) .openOn(map); - // popup.setLatLng(e.latlng).setContent(`${addr.address}`).openOn(map); + // latlngInputValue = { lat: latlng.lat, lng: latlng.lng }; + // popup.setLatLng(latlng).setContent(`${addr.address}`).openOn(map); } catch (err) { console.error(err); // addr = emptyxpin; addrInputValue = ''; - popup.setLatLng(e.latlng).setContent(`You clicked at ${e.latlng}`).openOn(map); + popup.setLatLng(latlng).setContent(`You clicked at ${latlng}`).openOn(map); } }; + const locationfound = (e) => { + console.log('Updating current location event', e); + updateEditedAddress(e.detail.latlng); + }; + + const onMapClick = (e) => { + updateEditedAddress(e.latlng); + }; + let init = async () => { await getWasm() .then((w) => (wasm = w)) @@ -106,30 +114,22 @@

Loading WebAssembly module...

{:then}

Address: {addr.address}

-

({addr.latLon}) => ({latlng.lat}, {latlng.lng})

+

({addr.latLon}) => ({addr.decimalDegrees})

- + - -
- + {:catch message} Could not start core module {/await} diff --git a/xpin-wasm/src/lib.rs b/xpin-wasm/src/lib.rs index 159c4b6..ef00f0d 100644 --- a/xpin-wasm/src/lib.rs +++ b/xpin-wasm/src/lib.rs @@ -12,6 +12,13 @@ pub struct EncodedAddress { #[wasm_bindgen] impl EncodedAddress { + /// Get the current address as decimal degrees + #[wasm_bindgen] + pub fn get_decimal_degrees(&self) -> String { + format!("{}, {}", self.lat, self.lon) + } + + /// Get an encoded address from a latitude/longitude #[wasm_bindgen] pub fn from_lat_lon(lat: f64, lon: f64) -> Result { xpin::Address::from_lat_lon(lat, lon)