Improve url format definition

This commit is contained in:
Austen Adler 2023-04-27 21:22:31 -04:00
parent d26cf96c45
commit 9be403c7eb
3 changed files with 32 additions and 20 deletions

View File

@ -1,6 +1,21 @@
import init from 'xpin-wasm'; import init from 'xpin-wasm';
import * as xpinWasm from 'xpin-wasm'; import * as xpinWasm from 'xpin-wasm';
export function rustEnumToArray(e) {
let ret = [];
for (let k in e) {
// Add the string coordinate types
if (!isNaN(k * 1)) {
// This is a numeric key, not a string key
// So skip it
continue;
}
ret.push(k);
}
return ret;
}
export const WasmStatus = { export const WasmStatus = {
NotLoaded: -1, NotLoaded: -1,
Loaded: 0, Loaded: 0,

View File

@ -1,5 +1,5 @@
<script> <script>
import { getWasm } from '$lib/common.js'; import { getWasm, rustEnumToArray } from '$lib/common.js';
import { WasmStatus } from '$lib/common.js'; import { WasmStatus } from '$lib/common.js';
import { tick, onMount, onDestroy } from 'svelte'; import { tick, onMount, onDestroy } from 'svelte';
import AddressInput from '$lib/AddressInput.svelte'; import AddressInput from '$lib/AddressInput.svelte';
@ -25,6 +25,17 @@
let initSuccess = false; let initSuccess = false;
let coordinateTypes = []; let coordinateTypes = [];
let urlFormats = [
'google_maps',
'google_maps_satellite',
'geo',
'openstreetmap',
'waze',
'apple_maps',
'osmand',
'bing_maps',
'osmand_direct'
];
let selectedCoordinateType; let selectedCoordinateType;
let leaflet; let leaflet;
import Map from '$lib/Map.svelte'; import Map from '$lib/Map.svelte';
@ -60,15 +71,11 @@
await getWasm() await getWasm()
.then((w) => { .then((w) => {
wasm = w; wasm = w;
for (let k in wasm.call.CoordinateType) {
// Add the string coordinate types
if (!isNaN(k * 1)) {
continue;
}
coordinateTypes.push(k); coordinateTypes = rustEnumToArray(wasm.call.CoordinateType);
}
selectedCoordinateType = coordinateTypes[0]; selectedCoordinateType = coordinateTypes[0];
console.log('My url formats: ', urlFormats, wasm.call.CoordinateUrls);
}) })
.then(async () => { .then(async () => {
leaflet = await import('leaflet'); leaflet = await import('leaflet');
@ -193,7 +200,7 @@
<TabSelector bind:tabInfo /> <TabSelector bind:tabInfo />
{#if tabInfo.selected === 1} {#if tabInfo.selected === 1}
<CoordinateInfo bind:coordinateTypes bind:xpin={addr} /> <CoordinateInfo bind:coordinateTypes bind:urlFormats bind:xpin={addr} />
{/if} {/if}
{:catch message} {:catch message}
<Error {message}>Could not start core module</Error> <Error {message}>Could not start core module</Error>

View File

@ -4,17 +4,7 @@
export let xpin; export let xpin;
export let coordinateTypes; export let coordinateTypes;
export let urlFormats;
let urlFormats = [
'google_maps',
'geo',
'openstreetmap',
'waze',
'apple_maps',
'osmand',
'bing_maps',
'osmand_direct'
];
// const shareClicked = (url) => { // const shareClicked = (url) => {
// if (navigator.share) { // if (navigator.share) {