diff --git a/web-frontend/src/lib/common.js b/web-frontend/src/lib/common.js
index 8962149..7e12429 100644
--- a/web-frontend/src/lib/common.js
+++ b/web-frontend/src/lib/common.js
@@ -1,6 +1,21 @@
import init from 'xpin-wasm';
import * as xpinWasm from 'xpin-wasm';
+export const emptyxpin = {
+ address: '',
+ latLon: [0.0, 0.0]
+};
+
+export function getxpin(xpin) {
+ if (!xpin) {
+ return;
+ }
+ return {
+ address: xpin.get_address(),
+ latLon: xpin.get_lat_lon()
+ };
+}
+
export const WasmStatus = {
NotLoaded: -1,
Loaded: 0,
diff --git a/web-frontend/src/routes/app/+page.svelte b/web-frontend/src/routes/app/+page.svelte
index 4466232..9fc11a5 100644
--- a/web-frontend/src/routes/app/+page.svelte
+++ b/web-frontend/src/routes/app/+page.svelte
@@ -4,8 +4,8 @@
import { onMount, onDestroy } from 'svelte';
import AddressInput from '$lib/AddressInput.svelte';
import { browser } from '$app/environment';
- // import tick from 'svelte';
import Error from './Error.svelte';
+ import { emptyxpin, getxpin } from '$lib/common.js';
let leaflet;
import Map from '$lib/Map.svelte';
@@ -13,7 +13,9 @@
let map;
let latlng = { lat: '', lng: '' };
- let addr = '';
+ let addr = emptyxpin;
+ let addrInputValue = '';
+
let wasm = {
status: WasmStatus.NotLoaded,
error: undefined,
@@ -25,11 +27,17 @@
try {
latlng = e.latlng;
- addr = wasm.call.address_from_lat_lon(latlng.lat, latlng.lng);
- popup.setLatLng(e.latlng).setContent(`${addr}`).openOn(map);
+ addr = getxpin(wasm.call.EncodedAddress.from_lat_lon(latlng.lat, latlng.lng));
+ console.log(latlng, addr);
+ popup.setLatLng({
+ lat:addr.latLon[0],
+ lng:addr.latLon[1]
+ }).setContent(`${addr.address}`).openOn(map);
+ // popup.setLatLng(e.latlng).setContent(`${addr.address}`).openOn(map);
} catch (err) {
console.error(err);
- addr = '';
+ // addr = emptyxpin;
+ addrInputValue = '';
popup.setLatLng(e.latlng).setContent(`You clicked at ${e.latlng}`).openOn(map);
}
};
@@ -62,7 +70,7 @@
const input = () => {
try {
if (browser) {
- outputValue = wasm.call.address_to_lat_lon(addr);
+ addr = getxpin(wasm.call.EncodedAddress.from_address(addr));
let latlng = new leaflet.LatLng(outputValue[0], outputValue[1]);
map.panTo(latlng, 20);
leaflet.popup().setLatLng(latlng).setContent(`${outputValue}
hi`).openOn(map);
@@ -91,9 +99,9 @@
{#await init()}
Loading WebAssembly module...
{:then} -Current cursor: {addr} => ({latlng.lat}, {latlng.lng})
+Current cursor: {addr.address} ({addr.latLon}) => ({latlng.lat}, {latlng.lng})
-