mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
Street Level photo viewer: fresh elements per mount, and one viewer drawn
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]>
This commit is contained in:
1 parent
766364f691
commit
2a0e21774b
17 files changed
+340
-107
No files matched your search
@@ -13,7 +13,11 @@ import {
|
||||
TOO_HIGH_HINT,
|
||||
} from './policy.js';
|
||||
import { validateProviders } from '../../registry.js';
|
||||
import { fakeHost, until } from '../../../../testSupport/kartaViewFakes.mjs';
|
||||
import {
|
||||
drawn,
|
||||
fakeHost,
|
||||
until,
|
||||
} from '../../../../testSupport/kartaViewFakes.mjs';
|
||||
import {
|
||||
bindStreetViewer,
|
||||
coverageViewer,
|
||||
@@ -978,6 +982,7 @@ test('after a GPU reset the photo is drawn again by the viewer, not through the
|
||||
const canvas = () => host.children[0].children[1];
|
||||
const kind = () => host.children[0].dataset.kind;
|
||||
canvas().fire('webglcontextlost');
|
||||
await drawn();
|
||||
assert.equal(kind(), '', 'cleared while it is drawn again');
|
||||
assert.ok(await until(() => kind() === 'pano'), 'drawn again');
|
||||
assert.ok(poses.length >= 2);
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createKartaViewViewer, loadImage, panoSizeFor } from './viewer.js';
|
||||
import { fakeHost, until } from '../../../../testSupport/kartaViewFakes.mjs';
|
||||
import {
|
||||
drawn,
|
||||
fakeHost,
|
||||
until,
|
||||
} from '../../../../testSupport/kartaViewFakes.mjs';
|
||||
|
||||
const PHOTOS = {
|
||||
flat1: {
|
||||
@@ -223,6 +227,7 @@ test('a flat photo shows its 1280 px version, then the sharp one, with a pose fa
|
||||
assert.equal(picture.src, loads[1].url, 'upgraded to the sharp version');
|
||||
assert.equal(viewer.supportsRenderModes(), true);
|
||||
viewer.setRenderMode('fill');
|
||||
await drawn();
|
||||
assert.equal(picture.style.objectFit, 'cover');
|
||||
});
|
||||
|
||||
@@ -357,12 +362,14 @@ test('a newer open wins; close hides the photo; unmount tears down the panorama'
|
||||
assert.equal(renderers.length, 0, 'nor built a WebGL context');
|
||||
await viewer.open('pano1');
|
||||
viewer.close();
|
||||
await drawn();
|
||||
const { picture, canvas, root } = parts(host);
|
||||
assert.equal(canvas.hidden, true);
|
||||
assert.equal(picture.hidden, true);
|
||||
assert.equal(root.dataset.kind, '');
|
||||
await assert.rejects(viewer.open('nope'), /no such photo/);
|
||||
viewer.unmount();
|
||||
await drawn();
|
||||
assert.equal(host.children.length, 0);
|
||||
assert.equal(renderers[0].destroyed, true);
|
||||
await assert.rejects(viewer.open('flat1'), /not mounted/);
|
||||
@@ -463,12 +470,14 @@ test('a lost WebGL context drops the panorama and shows the photo again on a new
|
||||
const lost = parts(host).canvas;
|
||||
lost.fire('webglcontextlost');
|
||||
assert.equal(renderers[0].destroyed, true);
|
||||
await drawn();
|
||||
// A lost canvas only ever gives back its lost context: a new element.
|
||||
assert.notEqual(parts(host).canvas, lost);
|
||||
assert.deepEqual(stepped, ['pano1'], 'reopened through the core');
|
||||
assert.ok(await until(() => renderers.length === 2), 'a new renderer');
|
||||
assert.equal(renderers[1].canvas, parts(host).canvas);
|
||||
assert.equal(poses.at(-1).imageId, 'pano1');
|
||||
await drawn();
|
||||
assert.equal(parts(host).canvas.hidden, false);
|
||||
});
|
||||
|
||||
@@ -931,7 +940,7 @@ test('a docked viewer keeps the 1,280 px photo; expanding it brings the 2,560 px
|
||||
viewer.resize();
|
||||
assert.ok(await until(() => loads.length === 2));
|
||||
assert.match(loads[1].url, /rs:fit:2560:2560/);
|
||||
assert.equal(parts(host).picture.src, loads[1].url);
|
||||
assert.ok(await until(() => parts(host).picture.src === loads[1].url));
|
||||
viewer.resize();
|
||||
for (let i = 0; i < 4; i++) await settle();
|
||||
assert.equal(loads.length, 2, 'once only');
|
||||
|
||||
@@ -14,7 +14,11 @@ import {
|
||||
} from './policy.js';
|
||||
import { validateProviders } from '../../registry.js';
|
||||
import { tileBounds } from '../../tileMath.js';
|
||||
import { fakeHost, until } from '../../../../testSupport/kartaViewFakes.mjs';
|
||||
import {
|
||||
drawn,
|
||||
fakeHost,
|
||||
until,
|
||||
} from '../../../../testSupport/kartaViewFakes.mjs';
|
||||
import {
|
||||
bindStreetViewer,
|
||||
coverageViewer,
|
||||
@@ -994,6 +998,8 @@ test('after a GPU reset the viewer draws the same picture itself, leaving the co
|
||||
const kind = () => host.children[0].dataset.kind;
|
||||
assert.equal(kind(), 'pano');
|
||||
canvas().fire('webglcontextlost');
|
||||
await drawn();
|
||||
assert.equal(kind(), '', 'cleared while it is drawn again');
|
||||
assert.ok(await until(() => kind() === 'pano'), 'drawn again');
|
||||
assert.deepEqual(poses, ['p-0', 'p-0']);
|
||||
assert.deepEqual(actions.opened, [], 'not through the core');
|
||||
|
||||
Reference in new issue
Block a user