diff --git a/web/src/lib/components/asset-viewer/detail-panel.svelte b/web/src/lib/components/asset-viewer/detail-panel.svelte index 1962e08256..05575035e0 100644 --- a/web/src/lib/components/asset-viewer/detail-panel.svelte +++ b/web/src/lib/components/asset-viewer/detail-panel.svelte @@ -4,60 +4,23 @@ import ImageOutline from 'svelte-material-icons/ImageOutline.svelte'; import CameraIris from 'svelte-material-icons/CameraIris.svelte'; import MapMarkerOutline from 'svelte-material-icons/MapMarkerOutline.svelte'; - import { createEventDispatcher, onMount } from 'svelte'; - import { browser } from '$app/environment'; + import { createEventDispatcher } from 'svelte'; import { AssetResponseDto, AlbumResponseDto } from '@api'; import { asByteUnitString } from '../../utils/byte-units'; import { locale } from '$lib/stores/preferences.store'; - - type Leaflet = typeof import('leaflet'); - type LeafletMap = import('leaflet').Map; - type LeafletMarker = import('leaflet').Marker; - - // Map Property - let map: LeafletMap; - let leaflet: Leaflet; - let marker: LeafletMarker; + import type { LatLngTuple } from 'leaflet'; export let asset: AssetResponseDto; - $: if (asset.exifInfo?.latitude != null && asset.exifInfo?.longitude != null) { - drawMap(asset.exifInfo.latitude, asset.exifInfo.longitude); - } - export let albums: AlbumResponseDto[] = []; - onMount(async () => { - if (browser) { - if (asset.exifInfo?.latitude != null && asset.exifInfo?.longitude != null) { - await drawMap(asset.exifInfo.latitude, asset.exifInfo.longitude); - } + $: latlng = (() => { + const lat = asset.exifInfo?.latitude; + const lng = asset.exifInfo?.longitude; + + if (lat && lng) { + return [lat, lng] as LatLngTuple; } - }); - - async function drawMap(lat: number, lon: number) { - if (!leaflet) { - leaflet = await import('leaflet'); - } - - if (!map) { - map = leaflet.map('map'); - leaflet - .tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { - attribution: '© OpenStreetMap' - }) - .addTo(map); - } - - if (marker) { - map.removeLayer(marker); - } - - map.setView([lat || 0, lon || 0], 17); - - marker = leaflet.marker([lat || 0, lon || 0]); - marker.bindPopup(`${(lat || 0).toFixed(7)},${(lon || 0).toFixed(7)}`); - map.addLayer(marker); - } + })(); const dispatch = createEventDispatcher(); @@ -186,9 +149,22 @@ -