mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
Street Level: a landed link, a replaced photo and a retired lookup keep their state
- A link's photo step compares with the navigation token its own restore flight owned, so a navigation after the flight landed (while the layers still load) keeps the camera. - A request that switches the source keeps the open photo up until it is replaced (holdViewer), so EXPAND stays across sources. - A lookup given up while it looked leaves the open photo and the panel as they were, also when it found nothing or failed. - A failed replacement shows its error inside the expanded viewer. - A replacing lookup stops a playing Mapillary sequence before the found photo opens. - The action refuses coordinates outside the globe, keeps a name given with coordinates as its label, and fly: false keeps the camera only for coordinates (its test-only entity and query branches are gone). - Numbered entities carry their label; a view's street-level point is a pair. - Mapillary's nearest search always asks for 50 m and 100 images. - Tests: the lifecycle reproductions, PLAY on replacement, out-of-range coordinates, half a point, and the named label; three layer tests share enabledLayer; the second payload digest is gone. - Docs: the tool count, the panel freshness rule, armed: false, the photo replacement, the browser-gate comment and a shorter changelog fragment.
This commit is contained in:
1 parent
9c73939425
commit
f3996da0af
26 files changed
+470
-327
No files matched your search
@@ -6,7 +6,6 @@ import {
|
||||
import { createSequenceCones, thinImages } from '../../sequenceCones.js';
|
||||
import { coverageZoomForHeight } from '../../tileMath.js';
|
||||
import { passesImageryFilter } from '../../filter.js';
|
||||
import { NEAREST_RADIUS_M } from '../../policy.js';
|
||||
import { metresBetween } from '../../view.js';
|
||||
import { decodeCoverageTile } from './decode.js';
|
||||
import { createMapillaryViewer } from './viewer.js';
|
||||
@@ -20,7 +19,6 @@ import {
|
||||
MAPILLARY_NAME,
|
||||
MAPILLARY_PROVIDER_ID,
|
||||
MAPILLARY_SOURCE_METHODS,
|
||||
NEAREST_LIMIT,
|
||||
PICK_PREFIX,
|
||||
RATE_LIMITED_MESSAGE,
|
||||
} from './policy.js';
|
||||
@@ -206,10 +204,7 @@ export function createMapillaryProvider({ source, photoViewer = null }) {
|
||||
* cone). The core aborts `signal` once a newer request overtakes it.
|
||||
*/
|
||||
async nearestImage({ lat, lon }, { signal } = {}) {
|
||||
const images = await source.nearestImages(
|
||||
{ lat, lon, radius: NEAREST_RADIUS_M, limit: NEAREST_LIMIT },
|
||||
{ signal },
|
||||
);
|
||||
const images = await source.nearestImages({ lat, lon }, { signal });
|
||||
// The API returns the images in the radius in no particular order.
|
||||
const metres = (record) => {
|
||||
const [lon2, lat2] = (record.computed_geometry || record.geometry)
|
||||
|
||||
@@ -200,11 +200,7 @@ test('nearestImage opens the closest image that passes the filter, not the first
|
||||
);
|
||||
assert.equal(await flat.nearestImage({ lat: 1, lon: 2 }, { signal }), 'near');
|
||||
assert.equal(requests[0].options.signal, signal, 'the core can abort it');
|
||||
assert.equal(requests[0].query.radius, 50);
|
||||
// The API cuts at the limit before any order: a small one would sort and
|
||||
// filter a handful of arbitrary photos (a 360° filter could find none).
|
||||
assert.equal(requests[0].query.limit, 100, "the API's most");
|
||||
assert.deepEqual([requests[0].query.lat, requests[0].query.lon], [1, 2]);
|
||||
assert.deepEqual(requests[0].query, { lat: 1, lon: 2 });
|
||||
const any = createMapillaryProvider({ source }).create(fakeContext());
|
||||
assert.equal(await any.nearestImage({ lat: 1, lon: 2 }), 'near-pano');
|
||||
const tooOld = createMapillaryProvider({ source }).create(
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import '../../../../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { registerHooks } from 'node:module';
|
||||
import { createStreetLevelLayer } from '../../index.js';
|
||||
import { fakeStreetLevelProvider, fakeCesiumViewer } from '../../../../testSupport/streetLevelFakes.mjs';
|
||||
import { createMapillaryViewer } from './viewer.js';
|
||||
import { showStreetLevel } from '../../../../voice/gevActions.js';
|
||||
|
||||
// Library boundary fixture: moveTo changes the image without stopping PLAY,
|
||||
// matching installed MapillaryJS Viewer.moveTo / Navigator.moveTo$.
|
||||
const fakeLibrary = `export class Viewer {
|
||||
constructor() { globalThis.__replacePlayViewer = this; this.playing = false; this.id = null; this.stops = 0; }
|
||||
on() {} remove() {} resize() {} setRenderMode() {}
|
||||
getComponent() { return { play: () => {this.playing = true;}, stop: () => {this.playing = false; this.stops++;} }; }
|
||||
async moveTo(id) { this.id = id; return { id, sequenceId: 'fixture-sequence', cameraType: 'perspective' }; }
|
||||
async getPosition() { return { lng: 2, lat: 48 }; }
|
||||
async getPointOfView() { return { bearing: 0 }; }
|
||||
}
|
||||
export class GraphDataProvider {}
|
||||
export const RenderMode = { Fill: 1, Letterbox: 0 };`;
|
||||
const hooks = registerHooks({
|
||||
resolve(specifier, context, next) {
|
||||
if (specifier === 'mapillary-js') return { url: 'data:text/javascript,' + encodeURIComponent(fakeLibrary), shortCircuit: true };
|
||||
if (specifier.endsWith('mapillary.css')) return { url: 'data:text/javascript,export default {}', shortCircuit: true };
|
||||
return next(specifier, context);
|
||||
},
|
||||
});
|
||||
globalThis.fetch = async () => { throw new Error('Unexpected network use in offline test'); };
|
||||
test('a photo the action asks for stops sequence PLAY', async t => {
|
||||
const provider = fakeStreetLevelProvider({ nearestImage: async () => 'B' });
|
||||
const create = provider.create;
|
||||
provider.create = context => ({ ...create(context), viewer: createMapillaryViewer({ source: { token: '' } }) });
|
||||
const viewer = fakeCesiumViewer(); viewer.canvas = viewer.scene.canvas;
|
||||
const layer = createStreetLevelLayer({ providers: [provider] });
|
||||
layer.init(viewer); layer.enable(viewer);
|
||||
layer.attachViewerHost(document.body.appendChild(document.createElement('div')));
|
||||
t.after(() => { layer.destroy(); hooks.deregister(); delete globalThis.__replacePlayViewer; document.body.replaceChildren(); });
|
||||
await Promise.resolve();
|
||||
await layer.openImage('mapillary', 'A', { frame: false });
|
||||
const libraryViewer = globalThis.__replacePlayViewer;
|
||||
libraryViewer.getComponent('sequence').play();
|
||||
assert.equal(libraryViewer.playing, true);
|
||||
const manager = {
|
||||
layers: new Map([['street-level', { module: layer }]]), isEnabled: () => true,
|
||||
getLayerParams: () => layer.getParams(), setLayerParams: (_id, params) => layer.setParams(params),
|
||||
};
|
||||
const result = await showStreetLevel({ provider: 'mapillary', latitude: 48, longitude: 2 }, {
|
||||
viewer, dataManager: manager, styleManager: { _navigationGeneration: 1 },
|
||||
runGevAction: async () => ({ ok: true, latitude: 48, longitude: 2, label: 'fixture destination' }),
|
||||
});
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(libraryViewer.id, 'B');
|
||||
assert.equal(layer.getUIState().street.open, true);
|
||||
assert.equal(libraryViewer.playing, false, 'requested image must stay selected rather than continue sequence PLAY');
|
||||
});
|
||||
@@ -196,18 +196,15 @@ export function createMapillarySource({
|
||||
return Array.isArray(payload?.data) ? payload.data : [];
|
||||
},
|
||||
|
||||
/** Images within `radius` metres of a point, in no particular order. */
|
||||
async nearestImages(
|
||||
{ lat, lon, radius = NEAREST_RADIUS_M, limit = NEAREST_LIMIT },
|
||||
{ signal } = {},
|
||||
) {
|
||||
/** Images within `NEAREST_RADIUS_M` of a point, in no particular order. */
|
||||
async nearestImages({ lat, lon }, { signal } = {}) {
|
||||
const payload = await graph(
|
||||
'images',
|
||||
{
|
||||
lat: String(lat),
|
||||
lng: String(lon),
|
||||
radius: String(Math.min(50, Math.max(1, radius))),
|
||||
limit: String(Math.min(100, Math.max(1, limit))),
|
||||
radius: String(NEAREST_RADIUS_M),
|
||||
limit: String(NEAREST_LIMIT),
|
||||
fields: NEAREST_IMAGE_FIELDS,
|
||||
},
|
||||
{ signal, timeoutMs: NEAREST_TIMEOUT_MS },
|
||||
|
||||
@@ -126,24 +126,21 @@ test('a rejected key and a rate limit are told apart from other tile errors', as
|
||||
);
|
||||
});
|
||||
|
||||
test('nearestImages asks the graph API around a point, its radius and limit clamped', async () => {
|
||||
test('nearestImages asks the graph API around a point, within 50 m, for at most 100 images', async () => {
|
||||
const { calls, fetchImpl } = fakeFetch(() =>
|
||||
jsonResponse({ data: [{ id: '1', geometry: { coordinates: [1, 2] } }] }),
|
||||
);
|
||||
const source = createMapillarySource({ token: 'MLY|1|abc', fetchImpl });
|
||||
const images = await source.nearestImages({
|
||||
lat: 38.5,
|
||||
lon: -121.5,
|
||||
radius: 500,
|
||||
limit: 500,
|
||||
});
|
||||
const images = await source.nearestImages({ lat: 38.5, lon: -121.5 });
|
||||
assert.equal(images.length, 1);
|
||||
const url = new URL(calls[0].url);
|
||||
assert.equal(url.pathname, '/images');
|
||||
assert.equal(url.searchParams.get('lat'), '38.5');
|
||||
assert.equal(url.searchParams.get('lng'), '-121.5');
|
||||
assert.equal(url.searchParams.get('radius'), '50', 'the API maximum');
|
||||
assert.equal(url.searchParams.get('limit'), '100');
|
||||
assert.equal(url.searchParams.get('radius'), '50');
|
||||
// The API cuts at the limit before any order: a small one would sort and
|
||||
// filter a handful of arbitrary photos (a 360° filter could find none).
|
||||
assert.equal(url.searchParams.get('limit'), '100', "the API's most");
|
||||
assert.match(url.searchParams.get('fields'), /computed_geometry/);
|
||||
assert.match(url.searchParams.get('fields'), /is_pano/);
|
||||
});
|
||||
|
||||
@@ -174,6 +174,15 @@ export function createMapillaryViewer({ source, render } = {}) {
|
||||
current = null;
|
||||
}
|
||||
|
||||
/** A playing sequence keeps stepping through (and downloading) images. */
|
||||
function stopPlayback() {
|
||||
try {
|
||||
viewer?.getComponent('sequence')?.stop();
|
||||
} catch {
|
||||
/* sequence component not available */
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
async mount(host) {
|
||||
if (!host) throw new Error('Street Level viewer has no host element');
|
||||
@@ -195,15 +204,12 @@ export function createMapillaryViewer({ source, render } = {}) {
|
||||
close() {
|
||||
pendingOpen = null;
|
||||
current = null;
|
||||
// A playing sequence would keep stepping through (and downloading)
|
||||
// images in the hidden viewer.
|
||||
try {
|
||||
viewer?.getComponent('sequence')?.stop();
|
||||
} catch {
|
||||
/* sequence component not available */
|
||||
}
|
||||
// Hidden, the viewer must not keep playing.
|
||||
stopPlayback();
|
||||
},
|
||||
|
||||
stopPlayback,
|
||||
|
||||
unmount() {
|
||||
pendingOpen = null;
|
||||
// A build still waiting for the library gives up when it arrives.
|
||||
|
||||
Reference in new issue
Block a user