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