Remove extra functions and fix undefined map
This commit is contained in:
parent
0658e1075c
commit
62dd7c6bfd
@ -1,7 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { getWasm } from '$lib/common.js';
|
import { getWasm } from '$lib/common.js';
|
||||||
import { WasmStatus } from '$lib/common.js';
|
import { WasmStatus } from '$lib/common.js';
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { tick, onMount, onDestroy } from 'svelte';
|
||||||
import AddressInput from '$lib/AddressInput.svelte';
|
import AddressInput from '$lib/AddressInput.svelte';
|
||||||
import CoordinateInput from '$lib/CoordinateInput.svelte';
|
import CoordinateInput from '$lib/CoordinateInput.svelte';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
@ -73,14 +73,15 @@
|
|||||||
.then(async () => {
|
.then(async () => {
|
||||||
leaflet = await import('leaflet');
|
leaflet = await import('leaflet');
|
||||||
})
|
})
|
||||||
.then(async () => {
|
|
||||||
// Initialize the app
|
|
||||||
// TODO: This leads to a `map is undefined` error
|
|
||||||
updateAddr(wasm.call.EncodedAddress.from_coordinate(coordinateInputValue), true);
|
|
||||||
})
|
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
initSuccess = true;
|
initSuccess = true;
|
||||||
})
|
})
|
||||||
|
// Wait for the map to be created
|
||||||
|
.then(tick)
|
||||||
|
.then(async () => {
|
||||||
|
// Initialize the actual app
|
||||||
|
updateAddr(wasm.call.EncodedAddress.from_coordinate(coordinateInputValue), true);
|
||||||
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('Erroring');
|
console.log('Erroring');
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -100,7 +101,7 @@
|
|||||||
// TODO: Does not work well when the address field is invalid
|
// TODO: Does not work well when the address field is invalid
|
||||||
|
|
||||||
// updateAddr(wasm.call.EncodedAddress.from_coordinate(coordinateInputValue), true);
|
// updateAddr(wasm.call.EncodedAddress.from_coordinate(coordinateInputValue), true);
|
||||||
coordinateInputValue = addr.get_coords_repr_as(coordinateTypes.indexOf(selectedCoordinateType));
|
coordinateInputValue = addr.getCoordsReprAs(coordinateTypes.indexOf(selectedCoordinateType));
|
||||||
};
|
};
|
||||||
|
|
||||||
const coordinateInput = () => {
|
const coordinateInput = () => {
|
||||||
@ -110,7 +111,7 @@
|
|||||||
updateAddr(xpin, true);
|
updateAddr(xpin, true);
|
||||||
|
|
||||||
console.log('xpin:', xpin);
|
console.log('xpin:', xpin);
|
||||||
selectedCoordinateType = coordinateTypes[xpin.srcCoordsType] || selectedCoordinateType;
|
selectedCoordinateType = coordinateTypes[xpin.getCoordsType] || selectedCoordinateType;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Could not parse coordinate input:', e);
|
console.error('Could not parse coordinate input:', e);
|
||||||
}
|
}
|
||||||
@ -133,10 +134,10 @@
|
|||||||
|
|
||||||
// Update coordinate display
|
// Update coordinate display
|
||||||
if (fromTextInput) {
|
if (fromTextInput) {
|
||||||
selectedCoordinateType = coordinateTypes[addr.srcCoordsType] || selectedCoordinateType;
|
selectedCoordinateType = coordinateTypes[addr.getCoordsType] || selectedCoordinateType;
|
||||||
coordinateInputValue = addr.getCoordsRepr() || coordinateInputValue;
|
coordinateInputValue = addr.getCoordsRepr() || coordinateInputValue;
|
||||||
} else {
|
} else {
|
||||||
coordinateInputValue = addr.get_coords_repr_as(
|
coordinateInputValue = addr.getCoordsReprAs(
|
||||||
coordinateTypes.indexOf(selectedCoordinateType)
|
coordinateTypes.indexOf(selectedCoordinateType)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,6 @@ pub struct EncodedAddress {
|
|||||||
pub address: String,
|
pub address: String,
|
||||||
/// The coordinates used to encode this address
|
/// The coordinates used to encode this address
|
||||||
src_coords: Coordinate,
|
src_coords: Coordinate,
|
||||||
#[wasm_bindgen(js_name = srcCoordsType)]
|
|
||||||
pub src_coords_type: CoordinateType,
|
|
||||||
#[wasm_bindgen(js_name = latLon)]
|
#[wasm_bindgen(js_name = latLon)]
|
||||||
pub lat_lon: Box<[f64]>,
|
pub lat_lon: Box<[f64]>,
|
||||||
|
|
||||||
@ -61,15 +59,20 @@ pub struct EncodedAddress {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl EncodedAddress {
|
impl EncodedAddress {
|
||||||
|
#[wasm_bindgen(js_name = getCoordsType)]
|
||||||
|
pub fn get_coords_type(&self) -> CoordinateType {
|
||||||
|
self.src_coords.get_type().into()
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the string representation of the encoded value
|
/// Get the string representation of the encoded value
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen(js_name = getCoordsRepr)]
|
||||||
// TODO: Do not return option
|
// TODO: Do not return option
|
||||||
pub fn get_coords_repr(&self, coordinate_type: CoordinateType) -> String {
|
pub fn get_coords_repr(&self) -> String {
|
||||||
self.src_coords.to_string()
|
self.src_coords.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the string representation of the encoded value as a different type
|
/// Get the string representation of the encoded value as a different type
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen(js_name = getCoordsReprAs)]
|
||||||
// TODO: Do not return option
|
// TODO: Do not return option
|
||||||
pub fn get_coords_repr_as(&self, coordinate_type: CoordinateType) -> Option<String> {
|
pub fn get_coords_repr_as(&self, coordinate_type: CoordinateType) -> Option<String> {
|
||||||
self.src_coords
|
self.src_coords
|
||||||
@ -114,9 +117,6 @@ impl EncodedAddress {
|
|||||||
.map_err(|e| e.to_string())?
|
.map_err(|e| e.to_string())?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
// TODO: Remove this
|
|
||||||
ret.src_coords_type = src_coords.get_type().into();
|
|
||||||
|
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,6 @@ impl TryFrom<&'_ Address<'_>> for EncodedAddress {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
address: addr.to_string(),
|
address: addr.to_string(),
|
||||||
lat_lon: Box::new([lat, lon]),
|
lat_lon: Box::new([lat, lon]),
|
||||||
src_coords_type: src_coords.get_type().into(),
|
|
||||||
src_coords,
|
src_coords,
|
||||||
decimal_degrees: format!("{}, {}", lat, lon),
|
decimal_degrees: format!("{}, {}", lat, lon),
|
||||||
all_coordinates: Coordinates::from(&all_coordinates),
|
all_coordinates: Coordinates::from(&all_coordinates),
|
||||||
|
Loading…
Reference in New Issue
Block a user