mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
fix(recent-imagery): take the short arc when a box is dragged across the dateline
A drag across ±180° was turned into a min/max box about 360° wide and refused as "Box is 38,332 km wide", and validateBox() refused any west > east box. A drag whose corners are more than 180° apart is now the short box (west > east), and the layer handles it end to end: - model: lonSpanDeg() and nonCrossingBoxes(); validateBox, boxSideKm, boxCentre, boxFromPin and coverageFor read a west > east box as the short arc. - catalog: CMR reads a west > east bounding_box as the short box, so the box is sent as it is. - rendering: the slot drapes one imagery layer per side of ±180°. - Worldview Snapshots rejects a west > east BBOX, so snapshot URLs, EXPORT and get_recent_imagery refuse a dateline box and request nothing; thumbnail and Data-Present probes use the box's wider side.
This commit is contained in:
1 parent
7df581765d
commit
ca14954636
16 files changed
+503
-70
No files matched your search
@@ -23,6 +23,8 @@ export const IMAGERY_BOX_POINTER_OWNER = 'recent-imagery-box';
|
||||
* @param {{ viewer: object, onBox: (box: object) => void, onCancel?: (reason: string, message?: string, box?: object) => void, onActive?: (active: boolean) => void, onEscape?: () => boolean, cesium?: object, pickWorld?: Function, documentRef?: object }} deps
|
||||
* `onEscape` runs before the tool cancels on Escape; returning `true` claims
|
||||
* the key (it is still consumed) and leaves the tool armed.
|
||||
* A drag whose corners are more than 180 degrees of longitude apart is the
|
||||
* short box across the dateline, returned with west > east.
|
||||
* @returns {{ start: () => boolean, cancel: (reason?: string) => void, isActive: () => boolean, destroy: () => Promise<void> } | null}
|
||||
*/
|
||||
export function initImageryBoxTool({
|
||||
@@ -48,13 +50,20 @@ export function initImageryBoxTool({
|
||||
let savedDoubleClick = null;
|
||||
let savedCameraInputs = null;
|
||||
|
||||
const dragBox = () =>
|
||||
anchor && {
|
||||
west: Math.min(anchor.lon, corner.lon),
|
||||
const dragBox = () => {
|
||||
if (!anchor) return null;
|
||||
const lo = Math.min(anchor.lon, corner.lon);
|
||||
const hi = Math.max(anchor.lon, corner.lon);
|
||||
// Corners more than half the globe apart are the short way round, over
|
||||
// the dateline: west is the eastern corner and east the western one.
|
||||
const crosses = hi - lo > 180;
|
||||
return {
|
||||
west: crosses ? hi : lo,
|
||||
south: Math.min(anchor.lat, corner.lat),
|
||||
east: Math.max(anchor.lon, corner.lon),
|
||||
east: crosses ? lo : hi,
|
||||
north: Math.max(anchor.lat, corner.lat),
|
||||
};
|
||||
};
|
||||
|
||||
const dataSource = new cesium.CustomDataSource(
|
||||
'gev-recent-imagery-box-preview',
|
||||
|
||||
@@ -152,3 +152,32 @@ test('destroy mid-drag restores the camera, releases the claim and detaches the
|
||||
assert.equal(f.tool.start(), false);
|
||||
assert.equal(initImageryBoxTool({ viewer: null, onBox() {} }), null);
|
||||
});
|
||||
|
||||
test('a drag across the dateline is the short box, not a box round the world', async () => {
|
||||
const pickWorld = (_viewer, nx, ny) =>
|
||||
ny < 0.05 ? null : { lon: nx < 0.5 ? 179.99 : -179.99, lat: ny };
|
||||
const f = fixture({ pickWorld });
|
||||
f.tool.start();
|
||||
f.fire('LEFT_DOWN', { position: { x: 100, y: 200 } });
|
||||
f.fire('LEFT_UP', { position: { x: 800, y: 250 } });
|
||||
assert.deepEqual(f.cancels, []);
|
||||
assert.equal(f.boxes.length, 1);
|
||||
const { west, east } = f.boxes[0];
|
||||
assert.ok(west > east, `west ${west} is east of east ${east}`);
|
||||
assert.ok(Math.abs(east + 360 - west - 0.02) < 1e-9, 'a 0.02 degree span');
|
||||
await f.tool.destroy();
|
||||
});
|
||||
|
||||
test('a drag whose short arc is still over the size limit is refused as too large', async () => {
|
||||
const pickWorld = (_viewer, nx, ny) => ({
|
||||
lon: nx < 0.5 ? 100 : -100,
|
||||
lat: ny,
|
||||
});
|
||||
const f = fixture({ pickWorld });
|
||||
f.tool.start();
|
||||
f.fire('LEFT_DOWN', { position: { x: 100, y: 200 } });
|
||||
f.fire('LEFT_UP', { position: { x: 800, y: 250 } });
|
||||
assert.equal(f.boxes.length, 0);
|
||||
assert.equal(f.cancels.at(-1)[0], 'too-large');
|
||||
await f.tool.destroy();
|
||||
});
|
||||
@@ -22,6 +22,7 @@ import RecentImageryReadout from './recentImagery/RecentImageryReadout.vue';
|
||||
import {
|
||||
PRODUCTS,
|
||||
hhmm,
|
||||
lonSpanDeg,
|
||||
wvsSnapshotUrl,
|
||||
} from '../layers/recentImagery/model.js';
|
||||
import { displayDay, displayMetres } from '../layers/recentImagery/display.js';
|
||||
@@ -766,13 +767,19 @@ export function createRecentImageryPanel({
|
||||
const candidate = exportTarget(slotId);
|
||||
if (destroyed || !candidate || !snapshot.box || exporting.has(slotId))
|
||||
return false;
|
||||
// Worldview Snapshots rejects a west > east BBOX: say so, request nothing.
|
||||
if (snapshot.box.west > snapshot.box.east) {
|
||||
exportError = t('Select one side of the dateline');
|
||||
preserveScroll(paint);
|
||||
return false;
|
||||
}
|
||||
exporting.add(slotId);
|
||||
exportError = null;
|
||||
preserveScroll(paint);
|
||||
// The snapshot is plate carrée: keep the box's degree aspect, with the
|
||||
// longer side at the size limit.
|
||||
const size = longerSideKm(snapshot.boxSizeKm) > 25 ? 2048 : 1024;
|
||||
const spanLon = Math.abs(snapshot.box.east - snapshot.box.west) || 1;
|
||||
const spanLon = lonSpanDeg(snapshot.box.west, snapshot.box.east) || 1;
|
||||
const spanLat = Math.abs(snapshot.box.north - snapshot.box.south) || 1;
|
||||
const width = Math.max(
|
||||
1,
|
||||
|
||||
@@ -968,6 +968,26 @@ test('opacity drives both images; EXPORT downloads the pin or the preview and EX
|
||||
await settle();
|
||||
assert.equal(await f.readout.exportImage('a'), true);
|
||||
assert.match(f.fetches.at(-1), /WIDTH=1024&HEIGHT=512/);
|
||||
// A dateline box is drawn on the map, but Worldview rejects a crossing BBOX.
|
||||
const before = f.fetches.length;
|
||||
f.layer.setBox({ west: 179, south: 0, east: -179, north: 1 });
|
||||
f.catalog.resolveLast();
|
||||
await settle();
|
||||
assert.notEqual(
|
||||
f.byId('ri-notice-text').textContent,
|
||||
'Select one side of the dateline',
|
||||
'the drawn box is not a warning until an export is tried',
|
||||
);
|
||||
assert.equal(await f.readout.exportImage('a'), false);
|
||||
assert.equal(
|
||||
f.byId('ri-notice-text').textContent,
|
||||
'Select one side of the dateline',
|
||||
);
|
||||
assert.equal(
|
||||
f.fetches.length,
|
||||
before,
|
||||
'export does not request a crossing BBOX',
|
||||
);
|
||||
f.layer.setMode('ab');
|
||||
assert.deepEqual(
|
||||
[
|
||||
|
||||
@@ -14,7 +14,7 @@ const REFUSALS = [
|
||||
'Point the camera at the ground to use the view', // layers/recentImagery/index.js
|
||||
'That point cannot anchor a box', // layers/recentImagery/index.js
|
||||
...[
|
||||
{ west: 170, south: 10, east: -170, north: 20 }, // dateline
|
||||
{ west: 170, south: 10, east: -170, north: 20 }, // too large (dateline arc)
|
||||
{ west: 10, south: 80, east: 20, north: 89 }, // polar
|
||||
{ west: 10, south: 10, east: 10, north: 20 }, // degenerate
|
||||
{ west: 10, south: 10, east: 200, north: 20 }, // longitude range
|
||||
@@ -37,8 +37,14 @@ const SHOWN_EN = new Map([
|
||||
|
||||
test('en: refusals stay English', () => {
|
||||
setLocale('en');
|
||||
for (const text of REFUSALS)
|
||||
assert.equal(localizeNotice(text), SHOWN_EN.get(text) ?? text);
|
||||
for (const text of REFUSALS) {
|
||||
const shown = localizeNotice(text);
|
||||
// Size refusals are rewritten with a non-breaking space before the unit.
|
||||
const expected = / km wide/.test(text)
|
||||
? text.replaceAll(' km', '\u00a0km')
|
||||
: (SHOWN_EN.get(text) ?? text);
|
||||
assert.equal(shown, expected);
|
||||
}
|
||||
assert.ok(REFUSALS.includes('Imagery stops at ±85.05° latitude'));
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user