mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
fix(street-level): links keep the recipient's preferences; aim under the screen centre
Review fixes for gekh's #1113 round: - a link runs show_street_level with origin 'programmatic', so its source switch and layer are not saved as the recipient's preferences; - with no place named, the action looks under the screen centre (aim 'screen-centre', armed false), keeps the sky refusal and leaves a link's armed point alone; - an armed OPEN aimed at the sky opens nothing instead of the far link point; - an imagery-stage failure is spoken as an error, missing imagery as missing (street.nearestOutcome); the card says "the view centre" in the interface language; - every photo the action opens reveals its panel, and revealPanel scrolls the panel into view in the phone sheet; - embed: EXPAND survives embed's own clean view, the lifted photo hides in cockpit, recording and scene playback, and a failed photo step closes the earlier photo before the view flies; - links pasted into an open tab run their street-level step after the restore settles; a superseded start link does not; - Mapillary's nearest search gives up after 12 s, body included.
This commit is contained in:
1 parent
3f55077c2c
commit
451f3e41cf
22 files changed
+716
-64
No files matched your search
@@ -668,7 +668,10 @@ export function createStreetLevelLayer({
|
||||
* providers that can (a geocoded landmark is rarely within 50 m of a
|
||||
* street); clicks keep the default. A caller's `signal` retires the
|
||||
* lookup: nothing opens after it fires. Providers without
|
||||
* `nearestImage` are skipped.
|
||||
* `nearestImage` are skipped. `armed: false` (a request of its own, such
|
||||
* as the assistant's) neither uses nor drops a link's armed point. Why
|
||||
* nothing opened is left in `street.nearestOutcome`: 'empty' (no imagery
|
||||
* in reach), 'sky' (the screen centre is not ground), or null (an error).
|
||||
*/
|
||||
async openNearest(
|
||||
point,
|
||||
@@ -678,18 +681,25 @@ export function createStreetLevelLayer({
|
||||
aim = 'view',
|
||||
radiusM = null,
|
||||
signal: callerSignal = null,
|
||||
armed: useArmed = true,
|
||||
} = {},
|
||||
) {
|
||||
if (callerSignal?.aborted) return false;
|
||||
state.street.nearestOutcome = null;
|
||||
// An OPEN press after a link armed a lookup opens what the link asked;
|
||||
// any other lookup is a new request and drops the armed one.
|
||||
const armed = state.street.armed;
|
||||
state.street.armed = null;
|
||||
const armed = useArmed ? state.street.armed : null;
|
||||
if (useArmed) state.street.armed = null;
|
||||
if (!point && aim === 'screen-centre' && armed) {
|
||||
// The button promises the centre of the view: the link's spot only
|
||||
// while the view still shows it.
|
||||
// while the view still shows it, or when the view cannot be picked.
|
||||
// Sky refuses below, as any OPEN press does.
|
||||
const centre = armed.point ? screenCentreGround() : null;
|
||||
if (!centre || metresBetween(centre, armed.point) <= ARMED_REACH_M) {
|
||||
if (!armed.point) radiusM ??= armed.radiusM;
|
||||
else if (
|
||||
centre === undefined ||
|
||||
(centre && metresBetween(centre, armed.point) <= ARMED_REACH_M)
|
||||
) {
|
||||
point = armed.point;
|
||||
radiusM ??= armed.radiusM;
|
||||
}
|
||||
@@ -704,6 +714,7 @@ export function createStreetLevelLayer({
|
||||
abortNearest();
|
||||
state.street.loading = false;
|
||||
state.street.error = AIM_AT_GROUND_MESSAGE;
|
||||
state.street.nearestOutcome = 'sky';
|
||||
notify();
|
||||
return false;
|
||||
}
|
||||
@@ -779,6 +790,8 @@ export function createStreetLevelLayer({
|
||||
);
|
||||
// A provider's own refusal is English data that the panel translates;
|
||||
// the core's refusal is built here, for the panel only, in the language.
|
||||
if (state.enabled && stillOn && !lastError)
|
||||
state.street.nearestOutcome = 'empty';
|
||||
if (state.enabled && stillOn)
|
||||
state.street.error =
|
||||
lastError?.message ||
|
||||
|
||||
@@ -1942,3 +1942,115 @@ test('the panel says why a lit Street View draws nothing off Google 3D', async (
|
||||
const view = presentStreetLevelPanel(layer.getUIState());
|
||||
assert.match(view.meta, /Google Street View needs the Google 3D map/);
|
||||
});
|
||||
|
||||
test('OPEN aimed at the sky after a link armed opens nothing: never the far link point', async (t) => {
|
||||
const { createStreetLevelLayer: create } = await import('./index.js');
|
||||
const scenePick = await import('../../data/scenePick.js');
|
||||
const lookups = [];
|
||||
const provider = fakeProvider({
|
||||
nearestImage: async (point) => {
|
||||
lookups.push(point);
|
||||
return null;
|
||||
},
|
||||
});
|
||||
const saved = globalThis.document;
|
||||
const drawing = new Proxy({}, { get: () => () => ({ addColorStop() {} }) });
|
||||
globalThis.document = Object.assign(new EventTarget(), {
|
||||
createElement: () => ({ getContext: () => drawing }),
|
||||
});
|
||||
const viewer = fakeViewer();
|
||||
// Every pick misses the ground: the screen centre is sky.
|
||||
Object.assign(viewer.scene, {
|
||||
pickPositionSupported: true,
|
||||
pickPosition: () => undefined,
|
||||
});
|
||||
viewer.globe = { pick: () => undefined };
|
||||
viewer.scene.canvas.clientWidth = 1000;
|
||||
viewer.scene.canvas.clientHeight = 600;
|
||||
const layer = create({ providers: [provider], services: { scenePick } });
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
t.after(() => {
|
||||
layer.destroy();
|
||||
globalThis.document = saved;
|
||||
});
|
||||
layer.armNearest({ lat: 48.8584, lon: 2.2945 }, { radiusM: 250 });
|
||||
assert.equal(
|
||||
await layer.openNearest(undefined, { aim: 'screen-centre' }),
|
||||
false,
|
||||
);
|
||||
assert.deepEqual(lookups, [], 'no paid Paris lookup from another city’s sky');
|
||||
const street = layer.getUIState().street;
|
||||
assert.equal(street.nearestOutcome, 'sky');
|
||||
assert.match(street.error, /Aim the middle of the view/);
|
||||
});
|
||||
|
||||
test('a request of its own (armed: false) neither uses nor drops the link’s armed point', async (t) => {
|
||||
const { createStreetLevelLayer: create } = await import('./index.js');
|
||||
const scenePick = await import('../../data/scenePick.js');
|
||||
const lookups = [];
|
||||
const provider = fakeProvider({
|
||||
nearestImage: async (point, options) => {
|
||||
lookups.push({ point, radiusM: options?.radiusM ?? null });
|
||||
return null;
|
||||
},
|
||||
});
|
||||
const saved = globalThis.document;
|
||||
const drawing = new Proxy({}, { get: () => () => ({ addColorStop() {} }) });
|
||||
globalThis.document = Object.assign(new EventTarget(), {
|
||||
createElement: () => ({ getContext: () => drawing }),
|
||||
});
|
||||
const viewer = fakeViewer();
|
||||
const centre = Cesium.Cartesian3.fromDegrees(-121.4937, 38.5799, 0);
|
||||
Object.assign(viewer.scene, {
|
||||
pickPositionSupported: true,
|
||||
pickPosition: (at) => (at.x === 500 && at.y === 300 ? centre : undefined),
|
||||
});
|
||||
viewer.scene.canvas.clientWidth = 1000;
|
||||
viewer.scene.canvas.clientHeight = 600;
|
||||
const layer = create({ providers: [provider], services: { scenePick } });
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
t.after(() => {
|
||||
layer.destroy();
|
||||
globalThis.document = saved;
|
||||
});
|
||||
// About 120 m away: an OPEN press would take the link's spot.
|
||||
layer.armNearest({ lat: 38.5808, lon: -121.494 }, { radiusM: 250 });
|
||||
await layer.openNearest(undefined, { aim: 'screen-centre', armed: false });
|
||||
const asked = lookups.at(-1);
|
||||
assert.ok(Math.abs(asked.point.lat - 38.5799) < 1e-9, 'the screen centre');
|
||||
assert.equal(asked.radiusM, null, 'its own radius');
|
||||
assert.equal(layer.getUIState().street.nearestOutcome, 'empty');
|
||||
assert.deepEqual(
|
||||
layer.getUIState().street.armed?.point,
|
||||
{ lat: 38.5808, lon: -121.494 },
|
||||
'still armed for the OPEN press',
|
||||
);
|
||||
});
|
||||
|
||||
test('a failing source is not reported as missing imagery', async (t) => {
|
||||
const { createStreetLevelLayer: create } = await import('./index.js');
|
||||
const provider = fakeProvider({
|
||||
nearestImage: async () => {
|
||||
throw new Error('Mapillary graph HTTP 500');
|
||||
},
|
||||
});
|
||||
const saved = globalThis.document;
|
||||
const drawing = new Proxy({}, { get: () => () => ({ addColorStop() {} }) });
|
||||
globalThis.document = Object.assign(new EventTarget(), {
|
||||
createElement: () => ({ getContext: () => drawing }),
|
||||
});
|
||||
const viewer = fakeViewer();
|
||||
const layer = create({ providers: [provider] });
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
t.after(() => {
|
||||
layer.destroy();
|
||||
globalThis.document = saved;
|
||||
});
|
||||
assert.equal(await layer.openNearest({ lat: 1, lon: 2 }), false);
|
||||
const street = layer.getUIState().street;
|
||||
assert.equal(street.nearestOutcome, null);
|
||||
assert.equal(street.error, 'Mapillary graph HTTP 500');
|
||||
});
|
||||
@@ -82,6 +82,12 @@ export const SEQUENCE_IMAGE_FIELDS =
|
||||
* the imagery filter then choose among the spot's photos, not a few of them.
|
||||
*/
|
||||
export const NEAREST_LIMIT = 100;
|
||||
/**
|
||||
* A nearest-image search that has not answered (headers and body) in this
|
||||
* long is given up: a link or a posted view waits on it, and so does every
|
||||
* view queued behind that one.
|
||||
*/
|
||||
export const NEAREST_TIMEOUT_MS = 12_000;
|
||||
/** Fields a nearest-image search needs: where each is, and the filter's. */
|
||||
export const NEAREST_IMAGE_FIELDS =
|
||||
'id,captured_at,geometry,computed_geometry,is_pano';
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
MAPILLARY_GRAPH_HOST,
|
||||
NEAREST_IMAGE_FIELDS,
|
||||
NEAREST_LIMIT,
|
||||
NEAREST_TIMEOUT_MS,
|
||||
SEQUENCE_IMAGE_FIELDS,
|
||||
SEQUENCE_IMAGES_LIMIT,
|
||||
} from './policy.js';
|
||||
@@ -69,7 +70,47 @@ export function createMapillarySource({
|
||||
...endpoints,
|
||||
};
|
||||
|
||||
async function graph(path, params = {}, { signal } = {}) {
|
||||
async function graph(path, params = {}, { signal, timeoutMs = 0 } = {}) {
|
||||
if (!timeoutMs) return graphOnce(path, params, { signal });
|
||||
// The whole answer, body included, within `timeoutMs`; the caller's
|
||||
// abort still wins.
|
||||
if (signal?.aborted) throw signal.reason;
|
||||
const controller = new AbortController();
|
||||
const onAbort = () => controller.abort(signal.reason);
|
||||
signal?.addEventListener('abort', onAbort, { once: true });
|
||||
const timer = setTimeout(
|
||||
() =>
|
||||
controller.abort(
|
||||
new MapillarySourceError('Mapillary did not answer in time', {
|
||||
status: 504,
|
||||
}),
|
||||
),
|
||||
timeoutMs,
|
||||
);
|
||||
try {
|
||||
// A body that never ends is given up too, whatever the fetch does.
|
||||
const gaveUp = new Promise((_, reject) =>
|
||||
controller.signal.addEventListener(
|
||||
'abort',
|
||||
() => reject(controller.signal.reason),
|
||||
{ once: true },
|
||||
),
|
||||
);
|
||||
return await Promise.race([
|
||||
graphOnce(path, params, { signal: controller.signal }),
|
||||
gaveUp,
|
||||
]);
|
||||
} catch (error) {
|
||||
if (signal?.aborted) throw signal.reason;
|
||||
if (controller.signal.aborted) throw controller.signal.reason;
|
||||
throw error;
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
signal?.removeEventListener('abort', onAbort);
|
||||
}
|
||||
}
|
||||
|
||||
async function graphOnce(path, params, { signal }) {
|
||||
if (graphBase) {
|
||||
const search = new URLSearchParams(params);
|
||||
const response = await fetchImpl(`${graphBase}${path}?${search}`, {
|
||||
@@ -165,7 +206,7 @@ export function createMapillarySource({
|
||||
limit: String(Math.min(100, Math.max(1, limit))),
|
||||
fields: NEAREST_IMAGE_FIELDS,
|
||||
},
|
||||
{ signal },
|
||||
{ signal, timeoutMs: NEAREST_TIMEOUT_MS },
|
||||
);
|
||||
return Array.isArray(payload?.data) ? payload.data : [];
|
||||
},
|
||||
|
||||
@@ -179,3 +179,44 @@ test('Graph endpoint errors keep their status', async () => {
|
||||
(error) => error.status === 503 && error.keyRequired === true,
|
||||
);
|
||||
});
|
||||
|
||||
test('a nearest-image search that never answers is given up, body included', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const { NEAREST_TIMEOUT_MS } = await import('./policy.js');
|
||||
// Headers arrive; the body never ends, and the fetch ignores its signal.
|
||||
const { fetchImpl } = fakeFetch(() => ({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: () => new Promise(() => {}),
|
||||
}));
|
||||
const source = createMapillarySource({ token: 'MLY|1|abc', fetchImpl });
|
||||
const pending = source.nearestImages({ lat: 1, lon: 2 });
|
||||
const outcome = pending.then(
|
||||
() => 'answered',
|
||||
(error) => error,
|
||||
);
|
||||
await Promise.resolve();
|
||||
t.mock.timers.tick(NEAREST_TIMEOUT_MS);
|
||||
const error = await outcome;
|
||||
assert.ok(error instanceof MapillarySourceError, String(error));
|
||||
assert.equal(error.status, 504);
|
||||
assert.equal(error.keyRequired, false, 'not a key problem');
|
||||
});
|
||||
|
||||
test('the caller’s abort still ends a nearest-image search before its deadline', async () => {
|
||||
const { fetchImpl } = fakeFetch(
|
||||
(_url, init) =>
|
||||
new Promise((_, reject) =>
|
||||
init.signal.addEventListener('abort', () => reject(init.signal.reason)),
|
||||
),
|
||||
);
|
||||
const source = createMapillarySource({ token: 'MLY|1|abc', fetchImpl });
|
||||
const controller = new AbortController();
|
||||
const pending = source.nearestImages(
|
||||
{ lat: 1, lon: 2 },
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
const reason = new Error('the turn moved on');
|
||||
controller.abort(reason);
|
||||
await assert.rejects(pending, (error) => error === reason);
|
||||
});
|
||||
@@ -19,6 +19,8 @@ export function freshStreet() {
|
||||
capturedAt: null,
|
||||
/** 'day', or 'month' for providers that date images by month (Google). */
|
||||
capturedAtPrecision: 'day',
|
||||
/** Why the last nearest lookup opened nothing: 'empty', 'sky' or null. */
|
||||
nearestOutcome: null,
|
||||
/** A place name for the caption (Google's address), or null. */
|
||||
title: null,
|
||||
/** Whether the open viewer has FIT/FILL render modes. */
|
||||
|
||||
Reference in new issue
Block a user