mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
feat(web): better coordinate parsing (#19832)
feat: better coordinate parsing
This commit is contained in:
parent
82c3165247
commit
daea57f7d2
3 changed files with 21 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts">
|
||||
import NumberRangeInput from '$lib/components/shared-components/number-range-input.svelte';
|
||||
import { generateId } from '$lib/utils/generate-id';
|
||||
import { convert } from 'geo-coordinates-parser';
|
||||
import { t } from 'svelte-i18n';
|
||||
|
||||
interface Props {
|
||||
|
|
@ -20,22 +21,22 @@
|
|||
};
|
||||
|
||||
const onPaste = (event: ClipboardEvent) => {
|
||||
const coords = event.clipboardData?.getData('text/plain')?.split(',');
|
||||
if (!coords || coords.length !== 2) {
|
||||
const pastedText = event.clipboardData?.getData('text/plain');
|
||||
if (!pastedText) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [latitude, longitude] = coords.map((coord) => Number.parseFloat(coord));
|
||||
if (Number.isNaN(latitude) || latitude < -90 || latitude > 90) {
|
||||
return;
|
||||
try {
|
||||
const parsed = convert(pastedText);
|
||||
if (parsed) {
|
||||
event.preventDefault();
|
||||
lat = parsed.decimalLatitude;
|
||||
lng = parsed.decimalLongitude;
|
||||
onInput();
|
||||
}
|
||||
} catch {
|
||||
// Invalid coordinate format, do nothing (let the default paste behavior occur)
|
||||
}
|
||||
if (Number.isNaN(longitude) || longitude < -180 || longitude > 180) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
[lat, lng] = [latitude, longitude];
|
||||
onInput();
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue