mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Fixes from review of the move to StreetLevelPhotoViewer: - Each mount and each panorama canvas now takes a key no viewer reuses, and the view keys its root by the mount. Before, switching KartaView and Panoramax in one tick let Vue patch the old viewer's canvas, whose destroyed renderer had lost its context, into the new one, so 360° photos fell back to their front view. - Of the viewers mounting in the host, the view draws the one mounted last, by mount key (photoViewers.js, which subscribePhotoViewer() now uses), whatever order they present in. A viewer still mounting when a later one is drawn is superseded: it unmounts and its mount fails as closed, rather than staying pending and being drawn once the later one goes. - A panorama's first image is uploaded once the view has drawn its canvas shown (the view hands the canvas back on every draw), so it is never sized into a hidden canvas. - The tests' fake view now draws as Vue does: once per tick with the final value, keeping elements while their keys are unchanged and handing every element back on each draw. StreetLevelPhotoViewer.test.mjs covers the switch in one tick and the overtaken mount with the real view. - The guard test's check that the photo viewer writes no DOM covers inserting, moving, removing and replacing elements, attributes, classes, styles and the hidden, disabled and text properties. Co-authored-by: Manjunath Paparaju <[email protected]>
81 lines
2.8 KiB
Vue
81 lines
2.8 KiB
Vue
<script setup>
|
||
import { storeToRefs } from 'pinia';
|
||
import UiButton from '../../kit/UiButton.vue';
|
||
import { useStreetLevelPhotoStore } from '../../stores/streetLevelPhoto.js';
|
||
|
||
// The Street Level photo viewer of the providers whose photos are plain
|
||
// files (KartaView, Panoramax), in the viewer host the layer mounts it in.
|
||
// The viewer (src/layers/streetLevel/photoViewer.js) keeps every decision:
|
||
// which photo shows and how, its loading, the panorama it draws, the keys,
|
||
// drag and zoom. This view draws what it presents, forwards the events and
|
||
// hands each element back: the canvas it draws on, the frame and picture
|
||
// it measures, the root and buttons it keeps focus with. Each mount and each
|
||
// canvas has its own key, so a viewer never gets another one's elements.
|
||
const { photo } = storeToRefs(useStreetLevelPhotoStore());
|
||
|
||
/** Hand `name`'s element back to the viewer that presented it. */
|
||
const keep = (name) => (element) => {
|
||
if (element) photo.value?.actions.attach(name, element.$el ?? element);
|
||
};
|
||
// One function per element: a new one on each render would hand it back
|
||
// again each time.
|
||
const refs = {
|
||
root: keep('root'),
|
||
picture: keep('picture'),
|
||
canvas: keep('canvas'),
|
||
prev: keep('prev'),
|
||
next: keep('next'),
|
||
};
|
||
</script>
|
||
|
||
<template>
|
||
<Teleport v-if="photo" :to="photo.host"
|
||
><div
|
||
:key="photo.mountKey"
|
||
:ref="refs.root"
|
||
class="sl-photo-viewer"
|
||
:data-provider="photo.providerId"
|
||
tabindex="0"
|
||
role="group"
|
||
:aria-label="photo.label"
|
||
:data-kind="photo.kind"
|
||
@keydown="photo.actions.keydown"
|
||
><img
|
||
:ref="refs.picture"
|
||
class="sl-photo-flat"
|
||
:alt="photo.alt"
|
||
draggable="false"
|
||
:hidden="photo.kind !== 'flat'"
|
||
:src="photo.src ?? undefined"
|
||
:style="{ objectFit: photo.fit }" /><canvas
|
||
:key="photo.canvasKey"
|
||
:ref="refs.canvas"
|
||
class="sl-photo-pano"
|
||
:class="{ 'sl-photo-dragging': photo.dragging }"
|
||
:hidden="photo.kind !== 'pano'"
|
||
@pointerdown="photo.actions.pointerdown"
|
||
@pointermove="photo.actions.pointermove"
|
||
@pointerup="photo.actions.pointerup"
|
||
@pointercancel="photo.actions.pointerup"
|
||
@wheel="photo.actions.wheel"
|
||
@webglcontextlost="photo.actions.contextLost"
|
||
></canvas
|
||
><UiButton
|
||
:ref="refs.prev"
|
||
class="sl-photo-step sl-photo-step-prev"
|
||
:label="photo.prevLabel"
|
||
:disabled="photo.prevDisabled"
|
||
@click="photo.actions.step(-1, $event)"
|
||
>‹</UiButton
|
||
><UiButton
|
||
:ref="refs.next"
|
||
class="sl-photo-step sl-photo-step-next"
|
||
:label="photo.nextLabel"
|
||
:disabled="photo.nextDisabled"
|
||
@click="photo.actions.step(1, $event)"
|
||
>›</UiButton
|
||
></div
|
||
></Teleport
|
||
>
|
||
</template>
|