mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
fix(overlays): let only the topmost painted card act on a click
Card handlers hit-tested only their own source, so a card buried under another layer's card still acted, and a click on a selected quake card over a vessel or fire card made both layers act. Vessels, FIRMS, wildlife, news, ghost maps and shipwrecks now read the unfiltered topmost painted entry: their own card acts only when it is on top, and a click on another layer's card is that layer's, so it neither acts here nor clears a selection. A top news or wildlife card still acts over another layer's scene item, so it never goes dead over a flight trail or a directions route; a registered marker under a foreign card is still its layer's to select.
This commit is contained in:
1 parent
5bc31ce08a
commit
836daf82b3
14 files changed
+310
-43
No files matched your search
@@ -196,8 +196,9 @@ function harness(
|
||||
},
|
||||
setVisible: (id, value) => overlay.visible.set(id, value),
|
||||
clearSource: (id) => overlay.entries.delete(id),
|
||||
hitTest: (_x, _y, { sourceId }) =>
|
||||
cardHit?.sourceId === sourceId ? cardHit : null,
|
||||
// As the host does: unfiltered, the topmost entry.
|
||||
hitTest: (_x, _y, { sourceId } = {}) =>
|
||||
!sourceId || cardHit?.sourceId === sourceId ? cardHit : null,
|
||||
},
|
||||
input: () => ({
|
||||
onClick(fn) {
|
||||
|
||||
@@ -483,17 +483,10 @@ export function createSelection({ state, services, parts }) {
|
||||
if (!state.enabled || services.pointer?.isPointerFree?.() === false)
|
||||
return;
|
||||
const at = click.screenPosition;
|
||||
const hit =
|
||||
overlay?.hitTest?.(at?.x, at?.y, {
|
||||
sourceId: WILDLIFE_SELECTED_SOURCE_ID,
|
||||
}) ||
|
||||
overlay?.hitTest?.(at?.x, at?.y, {
|
||||
sourceId: WILDLIFE_OVERLAY_SOURCE_ID,
|
||||
}) ||
|
||||
overlay?.hitTest?.(at?.x, at?.y, {
|
||||
sourceId: WILDLIFE_LABEL_SOURCE_ID,
|
||||
});
|
||||
if (hit) {
|
||||
// The topmost painted entry decides: our own card or label acts; one
|
||||
// covered by another layer's card does not.
|
||||
const hit = overlay?.hitTest?.(at?.x, at?.y);
|
||||
if (hit && sourceIds.includes(hit.sourceId)) {
|
||||
hit.entry?.activate?.();
|
||||
return;
|
||||
}
|
||||
@@ -516,6 +509,8 @@ export function createSelection({ state, services, parts }) {
|
||||
services.picking?.isOwnedByOtherLayer?.('wildlife-sightings', id)
|
||||
)
|
||||
return;
|
||||
// Another layer's card on top is that layer's click, not empty map.
|
||||
if (hit) return;
|
||||
clearAndRebuild();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ function fixture(sighting = row, extraServices = {}) {
|
||||
const seen = [];
|
||||
const painted = new Set();
|
||||
let hit = null;
|
||||
let coveringHit = null;
|
||||
let projections = 0;
|
||||
let click;
|
||||
const state = {
|
||||
@@ -49,8 +50,12 @@ function fixture(sighting = row, extraServices = {}) {
|
||||
setEntries: (id, value) => entries.set(id, value),
|
||||
clearSource: (id) => entries.delete(id),
|
||||
setVisible() {},
|
||||
hitTest: (_x, _y, { sourceId }) =>
|
||||
hit?.sourceId === sourceId ? hit : null,
|
||||
hitTest: (_x, _y, { sourceId } = {}) =>
|
||||
sourceId
|
||||
? hit?.sourceId === sourceId
|
||||
? hit
|
||||
: null
|
||||
: coveringHit || hit,
|
||||
},
|
||||
now: () => row.observedAt + 60_000,
|
||||
project: (_scene, anchor) => {
|
||||
@@ -94,6 +99,9 @@ function fixture(sighting = row, extraServices = {}) {
|
||||
?.find((entry) => entry.id === entryId);
|
||||
hit = entry ? { sourceId, entryId, entry } : null;
|
||||
},
|
||||
cover(value) {
|
||||
coveringHit = value;
|
||||
},
|
||||
paint(ids) {
|
||||
painted.clear();
|
||||
for (const id of ids) painted.add(id);
|
||||
@@ -179,6 +187,37 @@ test('selected photo and name cards use the selected lane, select on click and n
|
||||
}
|
||||
});
|
||||
|
||||
test('a covered sighting label yields; the top label acts over trails and other scene items', () => {
|
||||
const f = fixture(row, {
|
||||
// Registered owners, as the app has them: an aircraft, and the flight
|
||||
// trails every layer reads as a no-op (src/data/trailRenderer.js).
|
||||
picking: {
|
||||
isOwnedByOtherLayer: (_layer, id) =>
|
||||
id === 'other:aircraft' || String(id).startsWith('gev-trail:'),
|
||||
},
|
||||
});
|
||||
f.selection.install();
|
||||
f.selection.refreshAmbient();
|
||||
f.hit('wildlife-sightings-labels', 'wildlife-sightings-label:inat:123');
|
||||
f.click(null);
|
||||
assert.equal(f.flights.length, 1);
|
||||
f.cover({ sourceId: 'earthquakes', entryId: 'quake:cover' });
|
||||
f.click(null);
|
||||
assert.equal(f.flights.length, 1);
|
||||
assert.equal(f.state.selectedRow, row);
|
||||
f.click();
|
||||
assert.equal(f.flights.length, 2, 'an actual sighting remains selectable');
|
||||
f.cover(null);
|
||||
// The top label acts over a flight trail: never a dead click.
|
||||
f.click('gev-trail:fl-a1b2c3:head');
|
||||
assert.equal(f.flights.length, 3, 'the label acts over a flight trail');
|
||||
// And over another layer's scene item, as on main.
|
||||
f.click('other:aircraft');
|
||||
assert.equal(f.flights.length, 4, 'the top label acts');
|
||||
assert.equal(f.state.selectedRow, row);
|
||||
f.selection.remove();
|
||||
});
|
||||
|
||||
test('nearby duplicate display names yield to painted cards and higher-ranked labels using cached screens', () => {
|
||||
const low = {
|
||||
...row,
|
||||
|
||||
Reference in new issue
Block a user