mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 18:52:18 +00:00
Stories: GEV scenes as stories on the live globe
A Stories button (top right) opens Explore: a feed of GEV scenes over GEV's own Cesium globe, with a pin per story. Explore opens at country level over the first story and, while idle, flies on from story to story for a minute. A picked story is framed in the middle of the view; a pin plays its story on a second click. The Story page plays the scene through SceneDirector with a timeline, chapters, key moments, sources and background, then Close (or Back) puts the person's camera, clock, layers, style and AUTHORING selection back. Open in GEV hands the scene to the Scenes panel at its current shot. Stories lists the scenes GEV ships with a camera path (while they are in the project), the scenes saved with SAVE TO STORIES in AUTHORING, and the person's other scenes as drafts. The person's own stories live in the project on this device, so they have no Share; a link to a story that is not here opens Explore and says so. Each shipped story's context comes from what GEV knows: what it shows, the place each shot goes, and each layer's data sources as DATA_SOURCES.md lists them; the Nepal story carries the event pack's facts and CC BY-NC sources. Card images are a captured THUMBNAIL or drawn from the keyless Esri World Imagery. AUTHORING has no scene picker: it starts with no scene, NEW SCENE (or CAPTURE SHOT) makes one, and Stories' Open in GEV selects one. Before SAVE TO STORIES it offers topic tags and THUMBNAIL. A scene's stories flag, storyThumb and storyTags are saved with the project and kept through export and import. Only the closed state loads with the page; the screens, styles, story data and controller load on first open. Stories keeps its place in the query (one history entry per screen) and holds the share link's hash writes while open. Keyboard input and voice tools stay with Stories while it is open. Explore's pins move on every drawn frame without asking for frames; the idle tour and tile settling are bounded. All strings are translated in the 13 locales.
This commit is contained in:
1 parent
da81cf743b
commit
5418438339
77 files changed
+14975
-260
No files matched your search
@@ -0,0 +1,173 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
STORY_THUMB_HEIGHT,
|
||||
STORY_THUMB_MAX_LENGTH,
|
||||
STORY_THUMB_WIDTH,
|
||||
captureStoryThumb,
|
||||
centreCrop,
|
||||
encodeStoryThumb,
|
||||
isStoryThumb,
|
||||
} from './storyThumb.js';
|
||||
import { STORY_TAGS, isStoryTagList } from './storyTags.js';
|
||||
|
||||
/** Canvas double recording each draw; toDataURL answers `url(quality)`. */
|
||||
function fakeCanvases(url = () => 'data:image/jpeg;base64,AAAA') {
|
||||
const made = [];
|
||||
const create = () => {
|
||||
const canvas = {
|
||||
width: 0,
|
||||
height: 0,
|
||||
draws: [],
|
||||
qualities: [],
|
||||
getContext: () => ({
|
||||
drawImage: (...args) => canvas.draws.push(args),
|
||||
}),
|
||||
toDataURL: (type, quality) => {
|
||||
canvas.qualities.push([type, quality]);
|
||||
return url(quality);
|
||||
},
|
||||
};
|
||||
made.push(canvas);
|
||||
return canvas;
|
||||
};
|
||||
return { made, create };
|
||||
}
|
||||
|
||||
test('centreCrop keeps the centred 16:9 part of a wider or taller source', () => {
|
||||
assert.deepEqual(centreCrop(1920, 1080), {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
});
|
||||
assert.deepEqual(centreCrop(2000, 1000), {
|
||||
x: 111,
|
||||
y: 0,
|
||||
width: 1778,
|
||||
height: 1000,
|
||||
});
|
||||
assert.deepEqual(centreCrop(800, 1000), {
|
||||
x: 0,
|
||||
y: 275,
|
||||
width: 800,
|
||||
height: 450,
|
||||
});
|
||||
});
|
||||
|
||||
test('encodeStoryThumb halves a large view down to 320x180 JPEG at 0.82', () => {
|
||||
const { made, create } = fakeCanvases();
|
||||
const source = { width: 2000, height: 1000 };
|
||||
const url = encodeStoryThumb(source, create);
|
||||
assert.equal(url, 'data:image/jpeg;base64,AAAA');
|
||||
// 1778 wide halves to 889, then 445, then the final 320x180.
|
||||
assert.deepEqual(
|
||||
made.map(({ width, height }) => [width, height]),
|
||||
[
|
||||
[889, 500],
|
||||
[445, 250],
|
||||
[STORY_THUMB_WIDTH, STORY_THUMB_HEIGHT],
|
||||
],
|
||||
);
|
||||
assert.deepEqual(
|
||||
made[0].draws[0].slice(1),
|
||||
[111, 0, 1778, 1000, 0, 0, 889, 500],
|
||||
);
|
||||
assert.deepEqual(made.at(-1).qualities, [['image/jpeg', 0.82]]);
|
||||
});
|
||||
|
||||
test('encodeStoryThumb lowers the quality until the image fits, then gives up', () => {
|
||||
const big = 'data:image/jpeg;base64,' + 'A'.repeat(STORY_THUMB_MAX_LENGTH);
|
||||
const fits = fakeCanvases((quality) =>
|
||||
quality > 0.6 ? big : 'data:image/jpeg;base64,AAAA',
|
||||
);
|
||||
assert.equal(
|
||||
encodeStoryThumb({ width: 320, height: 180 }, fits.create),
|
||||
'data:image/jpeg;base64,AAAA',
|
||||
);
|
||||
assert.deepEqual(
|
||||
fits.made.at(-1).qualities.map(([, quality]) => quality),
|
||||
[0.82, 0.7, 0.55],
|
||||
);
|
||||
const never = fakeCanvases(() => big);
|
||||
assert.throws(
|
||||
() => encodeStoryThumb({ width: 320, height: 180 }, never.create),
|
||||
/too large/,
|
||||
);
|
||||
assert.throws(
|
||||
() => encodeStoryThumb({ width: 0, height: 0 }, never.create),
|
||||
/Nothing to capture/,
|
||||
);
|
||||
});
|
||||
|
||||
/** A Cesium scene double: postRender listeners run on requestRender. */
|
||||
function fakeViewer({ draws = true } = {}) {
|
||||
const listeners = new Set();
|
||||
const scene = {
|
||||
canvas: { width: 640, height: 360 },
|
||||
renders: 0,
|
||||
postRender: {
|
||||
addEventListener(listener) {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
},
|
||||
},
|
||||
requestRender() {
|
||||
scene.renders++;
|
||||
if (draws) for (const listener of [...listeners]) listener();
|
||||
},
|
||||
listeners,
|
||||
};
|
||||
return { scene };
|
||||
}
|
||||
|
||||
test('captureStoryThumb reads the canvas inside the postRender it requested', async () => {
|
||||
const viewer = fakeViewer();
|
||||
const { create } = fakeCanvases();
|
||||
const url = await captureStoryThumb(viewer, { createCanvas: create });
|
||||
assert.equal(url, 'data:image/jpeg;base64,AAAA');
|
||||
assert.equal(viewer.scene.renders, 1);
|
||||
assert.equal(viewer.scene.listeners.size, 0, 'the listener is removed');
|
||||
});
|
||||
|
||||
test('captureStoryThumb gives up when no frame is drawn or there is no globe', async () => {
|
||||
const viewer = fakeViewer({ draws: false });
|
||||
await assert.rejects(
|
||||
captureStoryThumb(viewer, {
|
||||
createCanvas: fakeCanvases().create,
|
||||
timeoutMs: 1,
|
||||
}),
|
||||
/No frame was drawn/,
|
||||
);
|
||||
assert.equal(viewer.scene.listeners.size, 0);
|
||||
await assert.rejects(
|
||||
captureStoryThumb({}, { createCanvas: fakeCanvases().create }),
|
||||
/Globe not ready/,
|
||||
);
|
||||
});
|
||||
|
||||
test('isStoryThumb accepts only bounded base64 JPEG or PNG data URLs', () => {
|
||||
assert.equal(isStoryThumb('data:image/jpeg;base64,AAAA'), true);
|
||||
assert.equal(isStoryThumb('data:image/png;base64,AAA='), true);
|
||||
for (const value of [
|
||||
'',
|
||||
null,
|
||||
42,
|
||||
'data:image/gif;base64,AAAA',
|
||||
'data:image/jpeg,AAAA',
|
||||
'https://example.com/a.jpg',
|
||||
'data:image/jpeg;base64,AA"A',
|
||||
'data:image/jpeg;base64,' + 'A'.repeat(STORY_THUMB_MAX_LENGTH),
|
||||
])
|
||||
assert.equal(isStoryThumb(value), false, String(value).slice(0, 40));
|
||||
});
|
||||
|
||||
test('isStoryTagList accepts up to five different known tags', () => {
|
||||
assert.equal(STORY_TAGS.length, 10);
|
||||
assert.equal(isStoryTagList([]), true);
|
||||
assert.equal(isStoryTagList(STORY_TAGS.slice(0, 5)), true);
|
||||
assert.equal(isStoryTagList(STORY_TAGS.slice(0, 6)), false);
|
||||
assert.equal(isStoryTagList(['Floods', 'Floods']), false);
|
||||
assert.equal(isStoryTagList(['floods']), false);
|
||||
assert.equal(isStoryTagList('Floods'), false);
|
||||
});
|
||||
Reference in new issue
Block a user