mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
feat(web): remember last chosen map location when editing (#16366)
Uses a global store to remember the last location chosen by a user when editing asset locations. This fixes an annoyance when adding location data to multiple assets in a row and having to zoom in the same area everytime.
This commit is contained in:
parent
4b55888d16
commit
8b69114924
@ -2,6 +2,7 @@
|
|||||||
import ConfirmDialog from './dialog/confirm-dialog.svelte';
|
import ConfirmDialog from './dialog/confirm-dialog.svelte';
|
||||||
import { timeDebounceOnSearch } from '$lib/constants';
|
import { timeDebounceOnSearch } from '$lib/constants';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
|
import { lastChosenLocation } from '$lib/stores/asset-editor.store';
|
||||||
|
|
||||||
import { clickOutside } from '$lib/actions/click-outside';
|
import { clickOutside } from '$lib/actions/click-outside';
|
||||||
import LoadingSpinner from './loading-spinner.svelte';
|
import LoadingSpinner from './loading-spinner.svelte';
|
||||||
@ -13,6 +14,7 @@
|
|||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
import CoordinatesInput from '$lib/components/shared-components/coordinates-input.svelte';
|
import CoordinatesInput from '$lib/components/shared-components/coordinates-input.svelte';
|
||||||
import Map from '$lib/components/shared-components/map/map.svelte';
|
import Map from '$lib/components/shared-components/map/map.svelte';
|
||||||
|
import { get } from 'svelte/store';
|
||||||
|
|
||||||
interface Point {
|
interface Point {
|
||||||
lng: number;
|
lng: number;
|
||||||
@ -36,9 +38,15 @@
|
|||||||
let hideSuggestion = $state(false);
|
let hideSuggestion = $state(false);
|
||||||
let mapElement = $state<ReturnType<typeof Map>>();
|
let mapElement = $state<ReturnType<typeof Map>>();
|
||||||
|
|
||||||
let lat = $derived(asset?.exifInfo?.latitude ?? undefined);
|
let previousLocation = get(lastChosenLocation);
|
||||||
let lng = $derived(asset?.exifInfo?.longitude ?? undefined);
|
|
||||||
let zoom = $derived(lat !== undefined && lng !== undefined ? 12.5 : 1);
|
let assetLat = $derived(asset?.exifInfo?.latitude ?? undefined);
|
||||||
|
let assetLng = $derived(asset?.exifInfo?.longitude ?? undefined);
|
||||||
|
|
||||||
|
let mapLat = $derived(assetLat ?? previousLocation?.lat ?? undefined);
|
||||||
|
let mapLng = $derived(assetLng ?? previousLocation?.lng ?? undefined);
|
||||||
|
|
||||||
|
let zoom = $derived(mapLat !== undefined && mapLng !== undefined ? 12.5 : 1);
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (places) {
|
if (places) {
|
||||||
@ -53,6 +61,7 @@
|
|||||||
|
|
||||||
const handleConfirm = () => {
|
const handleConfirm = () => {
|
||||||
if (point) {
|
if (point) {
|
||||||
|
lastChosenLocation.set(point);
|
||||||
onConfirm(point);
|
onConfirm(point);
|
||||||
} else {
|
} else {
|
||||||
onCancel();
|
onCancel();
|
||||||
@ -160,12 +169,12 @@
|
|||||||
{:then { default: Map }}
|
{:then { default: Map }}
|
||||||
<Map
|
<Map
|
||||||
bind:this={mapElement}
|
bind:this={mapElement}
|
||||||
mapMarkers={lat !== undefined && lng !== undefined && asset
|
mapMarkers={assetLat !== undefined && assetLng !== undefined && asset
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
lat,
|
lat: assetLat,
|
||||||
lon: lng,
|
lon: assetLng,
|
||||||
city: asset.exifInfo?.city ?? null,
|
city: asset.exifInfo?.city ?? null,
|
||||||
state: asset.exifInfo?.state ?? null,
|
state: asset.exifInfo?.state ?? null,
|
||||||
country: asset.exifInfo?.country ?? null,
|
country: asset.exifInfo?.country ?? null,
|
||||||
@ -173,7 +182,7 @@
|
|||||||
]
|
]
|
||||||
: []}
|
: []}
|
||||||
{zoom}
|
{zoom}
|
||||||
center={lat && lng ? { lat, lng } : undefined}
|
center={mapLat && mapLng ? { lat: mapLat, lng: mapLng } : undefined}
|
||||||
simplified={true}
|
simplified={true}
|
||||||
clickable={true}
|
clickable={true}
|
||||||
onClickPoint={(selected) => (point = selected)}
|
onClickPoint={(selected) => (point = selected)}
|
||||||
@ -183,8 +192,8 @@
|
|||||||
|
|
||||||
<div class="grid sm:grid-cols-2 gap-4 text-sm text-left mt-4">
|
<div class="grid sm:grid-cols-2 gap-4 text-sm text-left mt-4">
|
||||||
<CoordinatesInput
|
<CoordinatesInput
|
||||||
lat={point ? point.lat : lat}
|
lat={point ? point.lat : assetLat}
|
||||||
lng={point ? point.lng : lng}
|
lng={point ? point.lng : assetLng}
|
||||||
onUpdate={(lat, lng) => {
|
onUpdate={(lat, lng) => {
|
||||||
point = { lat, lng };
|
point = { lat, lng };
|
||||||
mapElement?.addClipMapMarker(lng, lat);
|
mapElement?.addClipMapMarker(lng, lat);
|
||||||
|
@ -17,6 +17,7 @@ export const normaizedRorateDegrees = derived(rotateDegrees, (v) => {
|
|||||||
export const changedOriention = derived(normaizedRorateDegrees, () => get(normaizedRorateDegrees) % 180 > 0);
|
export const changedOriention = derived(normaizedRorateDegrees, () => get(normaizedRorateDegrees) % 180 > 0);
|
||||||
//-----other
|
//-----other
|
||||||
export const showCancelConfirmDialog = writable<boolean | CallableFunction>(false);
|
export const showCancelConfirmDialog = writable<boolean | CallableFunction>(false);
|
||||||
|
export const lastChosenLocation = writable<{ lng: number; lat: number } | null>(null);
|
||||||
|
|
||||||
export const editTypes = [
|
export const editTypes = [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user