MapComplete/src/UI/Image/ImagePreview.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
982 B
Svelte
Raw Normal View History

<script lang="ts">
2023-12-19 22:08:00 +01:00
/**
* The image preview allows to drag and zoom in to the image
*/
import panzoom from "panzoom"
import type { ProvidedImage } from "../../Logic/ImageProviders/ImageProvider"
import { UIEventSource } from "../../Logic/UIEventSource"
import Zoomcontrol from "../Zoomcontrol"
import { onDestroy, onMount } from "svelte"
2023-12-19 22:08:00 +01:00
export let image: ProvidedImage
let panzoomInstance = undefined
let panzoomEl: HTMLElement
export let isLoaded: UIEventSource<boolean> = undefined
onDestroy(Zoomcontrol.createLock())
2023-12-19 22:08:00 +01:00
$: {
if (panzoomEl) {
panzoomInstance = panzoom(panzoomEl, {
bounds: true,
boundsPadding: 0.49,
2024-01-16 04:21:46 +01:00
minZoom: 0.1,
2023-12-19 22:08:00 +01:00
maxZoom: 25,
initialZoom: 1.0,
2023-12-19 22:08:00 +01:00
})
} else {
panzoomInstance?.dispose()
}
2023-12-19 22:08:00 +01:00
}
</script>
2023-12-30 15:24:30 +01:00
<img
bind:this={panzoomEl}
2024-01-16 04:21:46 +01:00
class="panzoom-image h-fit max-w-fit"
2023-12-30 15:24:30 +01:00
on:load={() => {
isLoaded?.setData(true)
}}
src={image.url_hd ?? image.url}
/>