mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Vue kit: Street Level's photo viewer is a view with kit buttons
The photo viewer KartaView and Panoramax share (photoViewer.js) no longer builds its root, picture, panorama canvas and ‹ › buttons in script. It presents them through subscribeView(), which the street-level layer gathers in subscribePhotoViewer(); the application shell publishes that to the gev-street-level-photo store, and StreetLevelPhotoViewer, beside the Street Level panel in the layer panels, teleports the viewer into the viewer host with the same classes, data attributes, labels and order. Its ‹ and › are ghost UiButtons. The view forwards keys, pointers, wheel, the step clicks and a lost WebGL context to the viewer and hands each element back: the canvas the panorama is drawn on (a fresh, keyed one after a lost context, which an open now waits for), and the frame, picture, root and buttons the viewer measures and keeps focus with. The viewer keeps every decision: loading, upgrades, size limits, keys, drag, pinch, zoom, Esc on the viewer's box and focus when a step button disables. The street-level layer still needs no Vue; with no view subscribed these photos cannot mount, which docs/VUE-MIGRATION.md records. The provider and viewer tests draw the viewer with a fake view in kartaViewFakes.mjs; StreetLevelPhotoViewer.test.mjs runs the real view on a page, and streetLevelPhotoControls.test.mjs pins the kit controls. The panel page's lost-graphics notice in globePanelRuntime.js stays built in script, as the document now says. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
9423a26487
commit
766364f691
20 files changed
+911
-112
No files matched your search
@@ -703,6 +703,42 @@ export function createStreetLevelLayer({
|
||||
attachViewerHost(element) {
|
||||
parts.viewerHost.attach(element);
|
||||
},
|
||||
/**
|
||||
* Receive every presentation of the photo viewer the providers whose
|
||||
* photos are plain files (KartaView, Panoramax) mount in the viewer
|
||||
* host, starting with the current one; null while none is mounted. A
|
||||
* view draws it (see photoViewer.js); with nobody subscribed, those
|
||||
* providers' photos cannot open.
|
||||
* @param {(view: ?object) => void} listener
|
||||
* @returns {() => void} Unsubscribe.
|
||||
*/
|
||||
subscribePhotoViewer(listener) {
|
||||
// Each mounted viewer's presentation, the latest mount last.
|
||||
const shown = new Map();
|
||||
let ready = false;
|
||||
let last;
|
||||
const publish = () => {
|
||||
const next = [...shown.values()].at(-1) ?? null;
|
||||
if (!ready || next === last) return;
|
||||
last = next;
|
||||
listener(next);
|
||||
};
|
||||
const unsubscribes = [];
|
||||
for (const [id, entry] of state.providers) {
|
||||
const unsubscribe = entry.instance.viewer?.subscribeView?.((view) => {
|
||||
shown.delete(id);
|
||||
if (view) shown.set(id, view);
|
||||
publish();
|
||||
});
|
||||
if (typeof unsubscribe === 'function') unsubscribes.push(unsubscribe);
|
||||
}
|
||||
ready = true;
|
||||
publish();
|
||||
if (last === undefined) listener((last = null));
|
||||
return () => {
|
||||
for (const unsubscribe of unsubscribes.splice(0)) unsubscribe();
|
||||
};
|
||||
},
|
||||
setProviderEnabled,
|
||||
openImage,
|
||||
/**
|
||||
|
||||
@@ -2176,3 +2176,40 @@ test('proceed() is asked after the lookup: false loads nothing and clears the sp
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('subscribePhotoViewer hands on the photo viewer a provider presents, the latest mount’s while two overlap', async (t) => {
|
||||
const presenting = (id, pickPrefix) => {
|
||||
const provider = fakeProvider({ id, pickPrefix });
|
||||
const create = provider.create;
|
||||
const listeners = new Set();
|
||||
provider.present = (view) => {
|
||||
for (const listener of [...listeners]) listener(view);
|
||||
};
|
||||
provider.create = (context) => {
|
||||
const instance = create(context);
|
||||
instance.viewer.subscribeView = (listener) => {
|
||||
listeners.add(listener);
|
||||
listener(null);
|
||||
return () => listeners.delete(listener);
|
||||
};
|
||||
return instance;
|
||||
};
|
||||
return provider;
|
||||
};
|
||||
const a = presenting('mapillary', 'mly:');
|
||||
const b = presenting('other', 'oth:');
|
||||
const { layer } = await enabledLayer(t, [a, b]);
|
||||
const shown = [];
|
||||
const unsubscribe = layer.subscribePhotoViewer((view) => shown.push(view));
|
||||
assert.deepEqual(shown, [null], 'the current one first');
|
||||
const viewA = { host: 'a' };
|
||||
const viewB = { host: 'b' };
|
||||
a.present(viewA);
|
||||
b.present(viewB);
|
||||
a.present(null);
|
||||
b.present(null);
|
||||
assert.deepEqual(shown, [null, viewA, viewB, null]);
|
||||
unsubscribe();
|
||||
a.present(viewA);
|
||||
assert.equal(shown.length, 4, 'unsubscribed');
|
||||
});
|
||||
@@ -213,6 +213,17 @@ export function panoSizeFor(canvasPixels, fovDeg) {
|
||||
* or pinch to zoom), and ‹ › to step along the sequence (also ← →). Poses
|
||||
* follow the view direction.
|
||||
*
|
||||
* The adapter draws nothing itself. It presents the viewer through
|
||||
* `subscribeView()` (the street-level layer's `subscribePhotoViewer()`): a
|
||||
* fresh `{host, providerId, label, alt, kind, src, fit, canvasKey, dragging,
|
||||
* prevLabel, prevDisabled, nextLabel, nextDisabled, actions}` on each change,
|
||||
* or null while unmounted. A view draws it into `host` (the application's is
|
||||
* `StreetLevelPhotoViewer`), forwards its events to `actions` and hands each
|
||||
* element back through `actions.attach(name, element)`: the panorama canvas
|
||||
* to draw on, the frame and picture to measure, the root and buttons to
|
||||
* keep focus. A new `canvasKey` asks for a fresh canvas (a lost WebGL
|
||||
* context). Mounting with no view subscribed fails.
|
||||
*
|
||||
* Photos are normalized by the provider: `{id, sequenceId, lon, lat,
|
||||
* heading, isPano, capturedAt}` plus whatever its `sources` read.
|
||||
*
|
||||
@@ -249,11 +260,18 @@ export function createPhotoViewer({
|
||||
}) {
|
||||
const LOAD_FAILED = `The ${name} photo could not be loaded`;
|
||||
const listeners = new Set();
|
||||
/** The elements the view handed back. */
|
||||
let root = null;
|
||||
let picture = null;
|
||||
let canvas = null;
|
||||
let prevButton = null;
|
||||
let nextButton = null;
|
||||
/** What the view draws; null while unmounted. */
|
||||
let presented = null;
|
||||
const viewListeners = new Set();
|
||||
/** Waiting for the view's root (a mount) or a fresh canvas (an open). */
|
||||
const rootWaiters = new Set();
|
||||
const canvasWaiters = new Set();
|
||||
let renderer = null;
|
||||
/** WebGL failed once: 360° photos show their front view instead. */
|
||||
let rendererFailed = false;
|
||||
@@ -265,8 +283,6 @@ export function createPhotoViewer({
|
||||
let drag = null;
|
||||
let poseFrame = 0;
|
||||
let removeListeners = [];
|
||||
/** The document the viewer was built in (new canvases come from it). */
|
||||
let documentOf = null;
|
||||
/** A context loss's look direction, for the reopen of that photo. */
|
||||
let restoreView = null;
|
||||
/** The panel's viewer box, where Esc is listened for (null: the root). */
|
||||
@@ -354,44 +370,62 @@ export function createPhotoViewer({
|
||||
});
|
||||
}
|
||||
|
||||
/** Present the viewer with `patch` applied (null: nothing to draw). */
|
||||
function present(patch) {
|
||||
if (patch === null) presented = null;
|
||||
else if (presented) presented = { ...presented, ...patch };
|
||||
else return;
|
||||
for (const listener of [...viewListeners]) listener(presented);
|
||||
}
|
||||
|
||||
/** Settle everything waiting on the view (it drew, or it went). */
|
||||
function wake(waiters) {
|
||||
for (const resolve of waiters) resolve();
|
||||
waiters.clear();
|
||||
}
|
||||
|
||||
/** The panorama canvas once the view has drawn it, or the open stopped. */
|
||||
function canvasReady(signal) {
|
||||
if (canvas || !presented || signal?.aborted) return Promise.resolve();
|
||||
return new Promise((resolve) => {
|
||||
canvasWaiters.add(resolve);
|
||||
signal?.addEventListener?.('abort', resolve, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
function syncButtons() {
|
||||
const enabled = Boolean(photo?.sequenceId) && showing !== null;
|
||||
if (prevButton) prevButton.disabled = !enabled;
|
||||
if (nextButton) nextButton.disabled = !enabled;
|
||||
present({ prevDisabled: !enabled, nextDisabled: !enabled });
|
||||
if (enabled) checkEnds(photo);
|
||||
}
|
||||
|
||||
/** Disable ‹ or › at once where the sequence ends (it also warms the neighbours). */
|
||||
function checkEnds(target) {
|
||||
for (const [delta, button] of [
|
||||
[-1, prevButton],
|
||||
[1, nextButton],
|
||||
])
|
||||
for (const delta of [-1, 1])
|
||||
step(target, delta).then(
|
||||
(id) => {
|
||||
if (photo === target && button && !id) disable(button);
|
||||
if (photo === target && presented && !id) disable(delta);
|
||||
},
|
||||
() => {},
|
||||
);
|
||||
}
|
||||
|
||||
/** Disable a step button, keeping keyboard focus in the viewer. */
|
||||
function disable(button) {
|
||||
if (button.ownerDocument?.activeElement === button) root?.focus?.();
|
||||
button.disabled = true;
|
||||
function disable(delta) {
|
||||
const button = delta < 0 ? prevButton : nextButton;
|
||||
if (button && button.ownerDocument?.activeElement === button)
|
||||
root?.focus?.();
|
||||
present(delta < 0 ? { prevDisabled: true } : { nextDisabled: true });
|
||||
}
|
||||
|
||||
function show(kind) {
|
||||
showing = kind;
|
||||
if (picture) picture.hidden = kind !== 'flat';
|
||||
if (canvas) canvas.hidden = kind !== 'pano';
|
||||
if (root) root.dataset.kind = kind || '';
|
||||
present({ kind: kind || '' });
|
||||
syncButtons();
|
||||
}
|
||||
|
||||
function applyRenderMode() {
|
||||
if (picture)
|
||||
picture.style.objectFit = renderMode === 'fill' ? 'cover' : 'contain';
|
||||
present({ fit: renderMode === 'fill' ? 'cover' : 'contain' });
|
||||
}
|
||||
|
||||
function ensureRenderer() {
|
||||
@@ -410,6 +444,9 @@ export function createPhotoViewer({
|
||||
* with it: drop the renderer, and show the photo again on a new one.
|
||||
*/
|
||||
function onContextLost(event) {
|
||||
// Only the canvas on screen: a replaced one has nothing left to lose.
|
||||
const from = event?.currentTarget ?? event?.target;
|
||||
if (from && from !== canvas) return;
|
||||
event.preventDefault?.();
|
||||
const lost = renderer;
|
||||
renderer = null;
|
||||
@@ -421,11 +458,10 @@ export function createPhotoViewer({
|
||||
} catch {
|
||||
/* already gone */
|
||||
}
|
||||
// A lost canvas hands back its lost context: draw on a new element.
|
||||
const fresh = makeCanvas(documentOf);
|
||||
fresh.hidden = canvas.hidden;
|
||||
canvas.replaceWith?.(fresh);
|
||||
canvas = fresh;
|
||||
// A lost canvas hands back its lost context: the view draws a new
|
||||
// element in its place and hands it back.
|
||||
canvas = null;
|
||||
present({ canvasKey: presented.canvasKey + 1 });
|
||||
// Show the photo again through the core, unless a newer one is opening.
|
||||
if (showing === 'pano' && photo && openingId === null) {
|
||||
const again = photo.id;
|
||||
@@ -435,20 +471,6 @@ export function createPhotoViewer({
|
||||
}
|
||||
}
|
||||
|
||||
/** The panorama canvas, wired for drag, pinch, wheel and context loss. */
|
||||
function makeCanvas(doc) {
|
||||
const element = doc.createElement('canvas');
|
||||
element.className = 'sl-photo-pano';
|
||||
element.hidden = true;
|
||||
listen(element, 'pointerdown', onPointerDown);
|
||||
listen(element, 'pointermove', onPointerMove);
|
||||
listen(element, 'pointerup', onPointerUp);
|
||||
listen(element, 'pointercancel', onPointerUp);
|
||||
listen(element, 'wheel', onWheel, { passive: false });
|
||||
listen(element, 'webglcontextlost', onContextLost);
|
||||
return element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step along the sequence from the photo showing, or from the one on its
|
||||
* way after an earlier press, and open it through the core.
|
||||
@@ -469,8 +491,7 @@ export function createPhotoViewer({
|
||||
// Closed, or another photo was opened meanwhile.
|
||||
if ((openingId ?? photo?.id) !== fromId) return;
|
||||
if (!nextId) {
|
||||
const button = delta < 0 ? prevButton : nextButton;
|
||||
if (button && photo?.id === fromId) disable(button);
|
||||
if (presented && photo?.id === fromId) disable(delta);
|
||||
return;
|
||||
}
|
||||
openingId = nextId;
|
||||
@@ -504,7 +525,7 @@ export function createPhotoViewer({
|
||||
y: event.clientY,
|
||||
view: renderer.getView(),
|
||||
};
|
||||
canvas.classList.add('sl-photo-dragging');
|
||||
present({ dragging: true });
|
||||
}
|
||||
|
||||
function onPointerMove(event) {
|
||||
@@ -532,7 +553,7 @@ export function createPhotoViewer({
|
||||
if (pointers.size < 2) pinch = null;
|
||||
if (!drag || event.pointerId !== drag.id) return;
|
||||
drag = null;
|
||||
canvas.classList.remove('sl-photo-dragging');
|
||||
present({ dragging: false });
|
||||
}
|
||||
|
||||
function onWheel(event) {
|
||||
@@ -603,51 +624,65 @@ export function createPhotoViewer({
|
||||
);
|
||||
}
|
||||
|
||||
/** The elements the view hands back, by name. */
|
||||
const ELEMENTS = {
|
||||
root: (element) => (root = element),
|
||||
picture: (element) => (picture = element),
|
||||
canvas: (element) => (canvas = element),
|
||||
prev: (element) => (prevButton = element),
|
||||
next: (element) => (nextButton = element),
|
||||
};
|
||||
|
||||
/** Present the viewer in `host`; its view draws it and hands back its elements. */
|
||||
function build(host) {
|
||||
const doc = host.ownerDocument;
|
||||
documentOf = doc;
|
||||
root = doc.createElement('div');
|
||||
root.className = 'sl-photo-viewer';
|
||||
root.dataset.provider = providerId;
|
||||
root.tabIndex = 0;
|
||||
root.setAttribute('role', 'group');
|
||||
root.setAttribute(
|
||||
'aria-label',
|
||||
t(
|
||||
// Events from a view drawn for an earlier mount are not this one's.
|
||||
const current =
|
||||
(handler) =>
|
||||
(...args) => {
|
||||
if (presented?.actions === actions) handler(...args);
|
||||
};
|
||||
const actions = {
|
||||
attach(name, element) {
|
||||
if (presented?.actions !== actions || !element) return;
|
||||
ELEMENTS[name]?.(element);
|
||||
if (name === 'root') wake(rootWaiters);
|
||||
if (name === 'canvas') wake(canvasWaiters);
|
||||
},
|
||||
keydown: current(onKeyDown),
|
||||
pointerdown: current(onPointerDown),
|
||||
pointermove: current(onPointerMove),
|
||||
pointerup: current(onPointerUp),
|
||||
wheel: current(onWheel),
|
||||
contextLost: current(onContextLost),
|
||||
step: current((delta, event) => {
|
||||
event?.stopPropagation?.();
|
||||
stepBy(delta);
|
||||
}),
|
||||
};
|
||||
presented = {
|
||||
host,
|
||||
providerId,
|
||||
label: t(
|
||||
'{name} photo. ← and → step along the sequence. On a 360° photo, drag or use Shift+← →, ↑ ↓ to look around, and + − to zoom',
|
||||
{ name },
|
||||
),
|
||||
);
|
||||
picture = doc.createElement('img');
|
||||
picture.className = 'sl-photo-flat';
|
||||
picture.alt = t('{name} street-level photo', { name });
|
||||
picture.draggable = false;
|
||||
picture.hidden = true;
|
||||
canvas = makeCanvas(doc);
|
||||
const nav = (label, glyph, delta) => {
|
||||
const button = doc.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = `sl-photo-step sl-photo-step-${delta < 0 ? 'prev' : 'next'}`;
|
||||
button.textContent = glyph;
|
||||
button.title = label;
|
||||
button.setAttribute('aria-label', label);
|
||||
button.disabled = true;
|
||||
listen(button, 'click', (event) => {
|
||||
event.stopPropagation();
|
||||
stepBy(delta);
|
||||
});
|
||||
return button;
|
||||
alt: t('{name} street-level photo', { name }),
|
||||
kind: undefined,
|
||||
src: null,
|
||||
fit: renderMode === 'fill' ? 'cover' : 'contain',
|
||||
canvasKey: 0,
|
||||
dragging: false,
|
||||
prevLabel: t('Previous photo in this sequence (←)'),
|
||||
prevDisabled: true,
|
||||
nextLabel: t('Next photo in this sequence (→)'),
|
||||
nextDisabled: true,
|
||||
actions,
|
||||
};
|
||||
prevButton = nav(t('Previous photo in this sequence (←)'), '‹', -1);
|
||||
nextButton = nav(t('Next photo in this sequence (→)'), '›', 1);
|
||||
root.append(picture, canvas, prevButton, nextButton);
|
||||
host.append(root);
|
||||
listen(root, 'keydown', onKeyDown);
|
||||
present({});
|
||||
// The viewer's box in the panel; without one, the root's own handler
|
||||
// takes Esc (one listener per element and type).
|
||||
escapeTarget = host.closest?.('.sl-viewer-wrap') ?? null;
|
||||
if (escapeTarget) listen(escapeTarget, 'keydown', onEscapeKey);
|
||||
applyRenderMode();
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
@@ -655,13 +690,17 @@ export function createPhotoViewer({
|
||||
pinch = null;
|
||||
for (const remove of removeListeners) remove();
|
||||
removeListeners = [];
|
||||
escapeTarget = null;
|
||||
if (poseFrame) cancelAnimationFrame(poseFrame);
|
||||
poseFrame = 0;
|
||||
drag = null;
|
||||
renderer?.destroy();
|
||||
renderer = null;
|
||||
root?.remove();
|
||||
// The view takes its elements away.
|
||||
present(null);
|
||||
root = picture = canvas = prevButton = nextButton = null;
|
||||
wake(rootWaiters);
|
||||
wake(canvasWaiters);
|
||||
showing = null;
|
||||
photo = null;
|
||||
}
|
||||
@@ -738,7 +777,7 @@ export function createPhotoViewer({
|
||||
try {
|
||||
const image = await loadAs(url, { crossOrigin: false, signal });
|
||||
if (seq !== openSeq || photo !== target || showing !== 'flat') return;
|
||||
picture.src = image.src;
|
||||
present({ src: image.src });
|
||||
sharp.shown = url;
|
||||
requestRender();
|
||||
} catch {
|
||||
@@ -770,7 +809,8 @@ export function createPhotoViewer({
|
||||
/** The sharp panorama this viewer needs now: 2,048 docked, 4,096 expanded. */
|
||||
function panoSizeNow() {
|
||||
const ratio = Math.min(globalThis.devicePixelRatio || 1, 2);
|
||||
const width = (canvas?.clientWidth || 0) * ratio;
|
||||
// The canvas fills the frame; until the view shows it, it measures 0.
|
||||
const width = (canvas?.clientWidth || root?.clientWidth || 0) * ratio;
|
||||
return panoSizeFor(width, renderer?.getView().fov ?? PANO_FOV_DEFAULT_DEG);
|
||||
}
|
||||
|
||||
@@ -827,7 +867,7 @@ export function createPhotoViewer({
|
||||
}
|
||||
if (!image) throw failure || new Error(LOAD_FAILED);
|
||||
if (seq !== openSeq) return false;
|
||||
picture.src = image.src;
|
||||
present({ src: image.src });
|
||||
flatSharp = { shown: null, loading: null };
|
||||
photo = target;
|
||||
show('flat');
|
||||
@@ -837,6 +877,11 @@ export function createPhotoViewer({
|
||||
async function openPhoto(id, seq, keepView, signal) {
|
||||
const target = await getPhoto(id, { signal });
|
||||
if (seq !== openSeq) return;
|
||||
// A canvas lost moments ago: the view is drawing its replacement.
|
||||
if (sources.hasPano(target) && !rendererFailed) {
|
||||
await canvasReady(signal);
|
||||
if (seq !== openSeq) return;
|
||||
}
|
||||
let shown = false;
|
||||
if (sources.hasPano(target) && ensureRenderer()) {
|
||||
try {
|
||||
@@ -857,10 +902,15 @@ export function createPhotoViewer({
|
||||
const adapter = {
|
||||
async mount(host) {
|
||||
if (!host) throw new Error('Street Level viewer has no host element');
|
||||
if (root && root.parentNode === host) return;
|
||||
if (root && presented?.host === host) return;
|
||||
teardown();
|
||||
rendererFailed = false;
|
||||
if (!viewListeners.size)
|
||||
throw new Error('Street Level photo viewer has no view to draw it');
|
||||
// Resolves once the view drew the viewer, or it was unmounted meanwhile.
|
||||
const drawn = new Promise((resolve) => rootWaiters.add(resolve));
|
||||
build(host);
|
||||
if (!root) await drawn;
|
||||
},
|
||||
|
||||
/** Resolves once the photo is on screen and its pose was emitted. */
|
||||
@@ -896,7 +946,7 @@ export function createPhotoViewer({
|
||||
photo = null;
|
||||
flatSharp = { shown: null, loading: null };
|
||||
show(null);
|
||||
if (picture) picture.removeAttribute('src');
|
||||
present({ src: null });
|
||||
renderer?.clear?.();
|
||||
},
|
||||
|
||||
@@ -937,6 +987,18 @@ export function createPhotoViewer({
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
},
|
||||
|
||||
/**
|
||||
* Receive every presentation of the viewer, starting with the current
|
||||
* one (null while unmounted).
|
||||
* @param {(view: ?object) => void} listener
|
||||
* @returns {() => void} Unsubscribe.
|
||||
*/
|
||||
subscribeView(listener) {
|
||||
viewListeners.add(listener);
|
||||
listener(presented);
|
||||
return () => viewListeners.delete(listener);
|
||||
},
|
||||
};
|
||||
return adapter;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ function setup() {
|
||||
pending.get(url).reject(new Error('gone'));
|
||||
pending.delete(url);
|
||||
};
|
||||
return { viewer, loads, images, release, fail, host: fakeHost() };
|
||||
return { viewer, loads, images, release, fail, host: fakeHost(viewer) };
|
||||
}
|
||||
|
||||
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
||||
@@ -146,7 +146,7 @@ test('Esc: the docked viewer offers it to the provider first; expanded, it is th
|
||||
onEscape: () => ++asked > 0,
|
||||
load: async (url) => ({ src: url }),
|
||||
});
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
await viewer.mount(host);
|
||||
const root = host.children[0];
|
||||
const press = () => {
|
||||
@@ -195,7 +195,7 @@ test('a sharp panorama still downloading when another photo opens is aborted', a
|
||||
});
|
||||
t.after(() => delete globalThis.devicePixelRatio);
|
||||
globalThis.devicePixelRatio = 1;
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
await viewer.mount(host);
|
||||
parts(host).canvas.clientWidth = 1800;
|
||||
await viewer.open('a');
|
||||
@@ -235,7 +235,7 @@ test('a lost WebGL context while the first panorama loads releases its bitmap',
|
||||
};
|
||||
},
|
||||
});
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
await viewer.mount(host);
|
||||
const opening = viewer.open('a');
|
||||
assert.ok(await until(() => land !== null), 'the panorama is loading');
|
||||
@@ -262,7 +262,7 @@ test('docked, Esc anywhere in the viewer’s box (toolbar, caption) is offered t
|
||||
onEscape: () => ++asked > 0,
|
||||
load: async (url) => ({ src: url }),
|
||||
});
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
const wrap = fakeHost();
|
||||
host.closest = (selector) => (selector === '.sl-viewer-wrap' ? wrap : null);
|
||||
await viewer.mount(host);
|
||||
@@ -363,7 +363,7 @@ function heldViewer() {
|
||||
pending.get(url).resolve({ src: url });
|
||||
pending.delete(url);
|
||||
};
|
||||
return { viewer, pending, signals, loads, release, host: fakeHost() };
|
||||
return { viewer, pending, signals, loads, release, host: fakeHost(viewer) };
|
||||
}
|
||||
|
||||
test('a new open, a close or an unmount stops the downloads of the open before it', async () => {
|
||||
@@ -439,7 +439,6 @@ test('a resize while another photo opens does not upgrade the photo still shown'
|
||||
});
|
||||
|
||||
test('a panorama is always decoded at a bounded size', async () => {
|
||||
const env = heldViewer();
|
||||
const options = [];
|
||||
const viewer = createPhotoViewer({
|
||||
providerId: 'test',
|
||||
@@ -461,7 +460,7 @@ test('a panorama is always decoded at a bounded size', async () => {
|
||||
destroy() {},
|
||||
}),
|
||||
});
|
||||
await viewer.mount(env.host);
|
||||
await viewer.mount(fakeHost(viewer));
|
||||
await viewer.open('a');
|
||||
// SOURCES' panoFirst names no size: the viewer still bounds it.
|
||||
assert.deepEqual(options[0].resize, [2048, 1024]);
|
||||
@@ -549,7 +548,7 @@ test('a browser without :fullscreen / :popover-open (Safari < 16.4) still opens
|
||||
onEscape: () => ++asked > 0,
|
||||
load: async (url) => ({ src: url }),
|
||||
});
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
await viewer.mount(host);
|
||||
const root = host.children[0];
|
||||
// Safari 16.0–16.3: neither pseudo-class parses, so closest() throws.
|
||||
@@ -571,3 +570,60 @@ test('a browser without :fullscreen / :popover-open (Safari < 16.4) still opens
|
||||
assert.doesNotThrow(() => root.fire('keydown', event), 'Esc does not throw');
|
||||
assert.equal(asked, 1, 'Esc reaches the provider');
|
||||
});
|
||||
|
||||
test('a panorama reopened after a lost context waits for the view’s fresh canvas', async () => {
|
||||
const canvases = [];
|
||||
const reopened = [];
|
||||
const viewer = createPhotoViewer({
|
||||
providerId: 'test',
|
||||
name: 'Test',
|
||||
sources: SOURCES,
|
||||
getPhoto: async (id) => PHOTOS[id],
|
||||
step: async () => null,
|
||||
onStep() {},
|
||||
onReopen: (id) => reopened.push(id),
|
||||
load: async (url) => ({ src: url }),
|
||||
createRenderer: (canvas) => {
|
||||
canvases.push(canvas);
|
||||
return {
|
||||
setImage() {},
|
||||
setView() {},
|
||||
getView: () => ({ yaw: 0, pitch: 0, fov: 80 }),
|
||||
resize() {},
|
||||
clear() {},
|
||||
destroy() {},
|
||||
};
|
||||
},
|
||||
});
|
||||
// A view that draws a replacement canvas a while after it is asked.
|
||||
let shown = null;
|
||||
let late = null;
|
||||
viewer.subscribeView((view) => {
|
||||
if (view && !shown) {
|
||||
for (const name of ['root', 'picture', 'prev', 'next'])
|
||||
view.actions.attach(name, { name, clientWidth: 400 });
|
||||
view.actions.attach('canvas', { name: 'canvas 0', clientWidth: 400 });
|
||||
} else if (view && view.canvasKey !== shown.canvasKey)
|
||||
late = () =>
|
||||
view.actions.attach('canvas', {
|
||||
name: `canvas ${view.canvasKey}`,
|
||||
clientWidth: 400,
|
||||
});
|
||||
shown = view;
|
||||
});
|
||||
await viewer.mount({});
|
||||
await viewer.open('a');
|
||||
assert.equal(shown.kind, 'pano');
|
||||
shown.actions.contextLost({ preventDefault() {} });
|
||||
assert.deepEqual(reopened, ['a']);
|
||||
const opening = viewer.open('a');
|
||||
await tick();
|
||||
assert.equal(canvases.length, 1, 'no renderer without a canvas');
|
||||
late();
|
||||
await opening;
|
||||
assert.deepEqual(
|
||||
canvases.map((canvas) => canvas.name),
|
||||
['canvas 0', 'canvas 1'],
|
||||
);
|
||||
assert.equal(shown.kind, 'pano', 'not the front view');
|
||||
});
|
||||
@@ -190,7 +190,7 @@ test('the nearest photo is the closest within 50 m, and opening it asks nothing
|
||||
});
|
||||
const id = await instance.nearestImage({ lat: 42.3314, lon: -83.0458 });
|
||||
assert.equal(id, 'near');
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(instance.viewer);
|
||||
await instance.viewer.mount(host);
|
||||
await instance.viewer.open(id);
|
||||
assert.deepEqual(source.calls.photo, [], 'the lookup filled the cache');
|
||||
@@ -285,7 +285,7 @@ const press = async (button, opened) => {
|
||||
|
||||
async function mounted(sourceOptions, contextOptions) {
|
||||
const env = setup(sourceOptions, contextOptions);
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(env.instance.viewer);
|
||||
await env.instance.viewer.mount(host);
|
||||
const poses = [];
|
||||
env.instance.viewer.onPose((pose) => poses.push(pose.imageId));
|
||||
@@ -970,7 +970,7 @@ test('after a GPU reset the photo is drawn again by the viewer, not through the
|
||||
context.actions.reportError = (message) => errors.push(message);
|
||||
const instance = definition.create(context);
|
||||
actions.instance = instance;
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(instance.viewer);
|
||||
await instance.viewer.mount(host);
|
||||
const poses = [];
|
||||
instance.viewer.onPose((pose) => poses.push(pose.imageId));
|
||||
@@ -1010,7 +1010,7 @@ test('the marker is KartaView’s own cone, and it points along the drive, not a
|
||||
photos: page.photos.map((record) => ({ ...record, heading: '200' })),
|
||||
};
|
||||
};
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(env.instance.viewer);
|
||||
await env.instance.viewer.mount(host);
|
||||
const bearings = [];
|
||||
env.instance.viewer.onPose((pose) => bearings.push(pose.bearing));
|
||||
@@ -1101,7 +1101,7 @@ test('a sequence page that lands while a lost GPU context recovers still draws i
|
||||
const instance = definition.create(context);
|
||||
actions.instance = instance;
|
||||
const cones = await withCones(t, { instance });
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(instance.viewer);
|
||||
await instance.viewer.mount(host);
|
||||
await instance.viewer.open('p-0');
|
||||
// › to the next panorama; the GPU resets while it loads.
|
||||
|
||||
@@ -148,7 +148,7 @@ function setup({
|
||||
});
|
||||
const poses = [];
|
||||
viewer.onPose((pose) => poses.push(pose));
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
return {
|
||||
viewer,
|
||||
poses,
|
||||
@@ -498,7 +498,7 @@ test('a WebGL failure only lasts until the viewer is mounted again', async () =>
|
||||
return renderer;
|
||||
},
|
||||
});
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
await viewer.mount(host);
|
||||
await viewer.open('pano1');
|
||||
assert.equal(parts(host).picture.hidden, false, 'front view');
|
||||
@@ -589,7 +589,7 @@ function heldSetup({ slowSteps = false } = {}) {
|
||||
});
|
||||
const poses = [];
|
||||
viewer.onPose((pose) => poses.push(pose.imageId));
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
/** Let the load showing `what` (e.g. 'a@1280') finish. */
|
||||
const release = async (what) => {
|
||||
assert.ok(
|
||||
@@ -798,7 +798,7 @@ function heldPanoSetup(held) {
|
||||
});
|
||||
const poses = [];
|
||||
viewer.onPose((pose) => poses.push(pose));
|
||||
return { viewer, renderers, stepped, poses, host: fakeHost(), release };
|
||||
return { viewer, renderers, stepped, poses, host: fakeHost(viewer), release };
|
||||
}
|
||||
|
||||
const pano2Preview = Buffer.from(
|
||||
|
||||
@@ -284,7 +284,7 @@ async function mounted(sourceOptions, contextOptions) {
|
||||
const env = setup(sourceOptions, contextOptions);
|
||||
const poses = [];
|
||||
env.instance.viewer.onPose((pose) => poses.push(pose.imageId));
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(env.instance.viewer);
|
||||
await env.instance.viewer.mount(host);
|
||||
const [, , prev, next] = host.children[0].children;
|
||||
return { ...env, poses, prev, next };
|
||||
@@ -320,7 +320,7 @@ test('one lookup for a picture asked twice at once', async () => {
|
||||
await gate;
|
||||
return getItem(id);
|
||||
};
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(instance.viewer);
|
||||
await instance.viewer.mount(host);
|
||||
const first = instance.viewer.open('s-0');
|
||||
const second = instance.viewer.open('s-0');
|
||||
@@ -985,7 +985,7 @@ test('after a GPU reset the viewer draws the same picture itself, leaving the co
|
||||
const { context, actions } = fakeContext();
|
||||
const instance = definition.create(context);
|
||||
actions.instance = instance;
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(instance.viewer);
|
||||
await instance.viewer.mount(host);
|
||||
const poses = [];
|
||||
instance.viewer.onPose((pose) => poses.push(pose.imageId));
|
||||
|
||||
@@ -59,7 +59,7 @@ function setup() {
|
||||
});
|
||||
const poses = [];
|
||||
viewer.onPose((pose) => poses.push(pose));
|
||||
return { viewer, poses, loads, renderers, stepped, host: fakeHost() };
|
||||
return { viewer, poses, loads, renderers, stepped, host: fakeHost(viewer) };
|
||||
}
|
||||
|
||||
const parts = (host) => {
|
||||
@@ -252,7 +252,7 @@ test('without WebGL a 360° picture shows its whole equirectangular image flat',
|
||||
throw new Error('no WebGL');
|
||||
},
|
||||
});
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
await viewer.mount(host);
|
||||
await viewer.open('pano');
|
||||
const { picture } = parts(host);
|
||||
@@ -272,7 +272,7 @@ test('a picture whose SD fails falls back to the thumbnail; the original only fo
|
||||
return { src: url };
|
||||
},
|
||||
});
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
await viewer.mount(host);
|
||||
await viewer.open('flat');
|
||||
assert.deepEqual(tried, [PHOTOS.flat.urls.sd, PHOTOS.flat.urls.thumb]);
|
||||
@@ -326,7 +326,7 @@ test('an SD panorama refused for its size is not fetched again as a flat photo',
|
||||
destroy() {},
|
||||
}),
|
||||
});
|
||||
const host = fakeHost();
|
||||
const host = fakeHost(viewer);
|
||||
await viewer.mount(host);
|
||||
await viewer.open('pano');
|
||||
const sdLoads = loads.filter((l) => l.url === PHOTOS.pano.urls.sd);
|
||||
|
||||
@@ -63,6 +63,9 @@ export function filtersOf(provider) {
|
||||
* @property {(mode: 'letterbox'|'fill') => void} [setRenderMode]
|
||||
* @property {() => boolean} [supportsRenderModes] False while the image has no frame to fit (a panorama): FIT / FILL hide.
|
||||
* @property {(listener: (pose: StreetPose) => void) => () => void} onPose
|
||||
* @property {(listener: (view: ?object) => void) => () => void} [subscribeView]
|
||||
* An adapter that draws nothing itself presents its viewer here, for the
|
||||
* layer's `subscribePhotoViewer()` (see photoViewer.js).
|
||||
*
|
||||
* @typedef {object} StreetPose
|
||||
* @property {string} providerId
|
||||
|
||||
Reference in new issue
Block a user