Fix: fix move dialog

This commit is contained in:
Pieter Vander Vennet 2024-09-12 21:42:35 +02:00
parent ee33624780
commit 084cd86b71
3 changed files with 18 additions and 13 deletions

View file

@ -34,7 +34,12 @@
export let coordinate: { lon: number; lat: number } = undefined
/**
* The center of the map at all times
* Max distance that one is allowed to move, to prevent to stray too much
*/
export let maxDistanceInMeters = 50
/**
* The resulting location; either the map center or the snapped coordinate
* If undefined at the beginning, 'coordinate' will be used
*/
export let value: UIEventSource<{ lon: number; lat: number }>
@ -57,11 +62,6 @@
export let snappedTo: UIEventSource<WayId | undefined>
let preciseLocation: UIEventSource<{ lon: number; lat: number }> = new UIEventSource<{
lon: number
lat: number
}>(undefined)
const map: UIEventSource<MlMap> = new UIEventSource<MlMap>(undefined)
export let mapProperties: Partial<MapProperties> & { location } = {
zoom: new UIEventSource<number>(19),
@ -69,10 +69,7 @@
/*If no snapping needed: the value is simply the map location;
* If snapping is needed: the value will be set later on by the snapping feature source
* */
location:
snapToLayers?.length > 0
? new UIEventSource<{ lon: number; lat: number }>(coordinate)
: value,
location: new UIEventSource<{ lon: number; lat: number }>(coordinate),
bounds: new UIEventSource<BBox>(undefined),
allowMoving: new UIEventSource<boolean>(true),
allowZooming: new UIEventSource<boolean>(true),
@ -143,15 +140,16 @@
})
withCorrectedAttributes.features.addCallbackAndRunD((f) => console.log("Snapped point is", f))
}
</script>
<LocationInput
{map}
on:click
{mapProperties}
value={preciseLocation}
value={ snapToLayers?.length > 0 ? new UIEventSource(undefined) : value}
initialCoordinate={coordinate}
maxDistanceInMeters={50}
{maxDistanceInMeters}
>
<slot name="image" slot="image">
<Move_arrows class="h-full max-h-24" />

View file

@ -18,9 +18,15 @@
/**
* A visualisation to pick a location on a map background
*/
/**
* The center of the map. If it contains a value (and initialCoordinate is not given), this will be used as start coordinate
*/
export let value: UIEventSource<{ lon: number; lat: number }>
export let initialCoordinate: { lon: number; lat: number }
export let initialCoordinate: { lon: number; lat: number } = undefined
initialCoordinate = initialCoordinate ?? value.data
/**
* Max distance that one is allowed to stray from the initial coordinate
*/
export let maxDistanceInMeters: number = undefined
export let mapProperties: Partial<MapProperties> & {
readonly location: UIEventSource<{ lon: number; lat: number }>

View file

@ -106,6 +106,7 @@
snapToLayers={$reason.snapTo}
targetLayer={layer}
dontShow={[id]}
maxDistanceInMeters={200}
/>
<div class="absolute bottom-0 left-0">
<OpenBackgroundSelectorButton {state} />