mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42: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
@@ -278,10 +278,11 @@ export function createShipwrecksLayer({
|
||||
_clickHandler = clicks.onClick((click) => {
|
||||
if (pointer && !pointer.isPointerFree()) return;
|
||||
const at = click.screenPosition;
|
||||
const cardHit = overlayHost.hitTest?.(at?.x, at?.y, {
|
||||
sourceId: SHIPWRECKS_OVERLAY_SOURCE_ID,
|
||||
});
|
||||
if (cardHit && cardHit.entryId === _selectedCardId) {
|
||||
const cardHit = overlayHost.hitTest?.(at?.x, at?.y);
|
||||
if (
|
||||
cardHit?.sourceId === SHIPWRECKS_OVERLAY_SOURCE_ID &&
|
||||
cardHit.entryId === _selectedCardId
|
||||
) {
|
||||
if (_selectedLink) openExternal(_selectedLink);
|
||||
return;
|
||||
}
|
||||
@@ -299,6 +300,10 @@ export function createShipwrecksLayer({
|
||||
}
|
||||
if (pickId && picking.isOwnedByOtherLayer(SHIPWRECKS_LAYER_ID, pickId))
|
||||
return;
|
||||
// A covered card must neither open its source nor clear the selection.
|
||||
// A marker of ours under that card was already selected by the pick
|
||||
// check before this one.
|
||||
if (cardHit) return;
|
||||
if (_selectedId) {
|
||||
clearSelection();
|
||||
render();
|
||||
|
||||
@@ -36,7 +36,7 @@ function deferred() {
|
||||
return { promise, resolve };
|
||||
}
|
||||
|
||||
function harness({ snapshots, now = () => 1 } = {}) {
|
||||
function harness({ snapshots, now = () => 1, cardHit = () => null } = {}) {
|
||||
const cards = [];
|
||||
const handlers = [];
|
||||
const opened = [];
|
||||
@@ -59,7 +59,7 @@ function harness({ snapshots, now = () => 1 } = {}) {
|
||||
overlayHost: {
|
||||
setEntries: (_source, entries) => cards.push(entries),
|
||||
setVisible() {},
|
||||
hitTest: () => null,
|
||||
hitTest: cardHit,
|
||||
},
|
||||
// The globe's clicks: one listener per click handler installed.
|
||||
input: () => ({
|
||||
@@ -393,3 +393,45 @@ test('the page deadline subtracts the newest available source age from the limit
|
||||
);
|
||||
assert.equal(snapshotDeadline({ sources: both }, 0), 7 * DAY, 'defaults');
|
||||
});
|
||||
|
||||
test('a covered selected card yields while genuine wreck markers still select', async () => {
|
||||
let painted = [];
|
||||
const h = harness({
|
||||
snapshots: [
|
||||
snapshot([
|
||||
wreck('a', { url: 'https://example.com/a' }),
|
||||
wreck('b', { url: 'https://example.com/b' }),
|
||||
]),
|
||||
],
|
||||
cardHit: (_x, _y, { sourceId } = {}) =>
|
||||
painted.find((hit) => !sourceId || hit.sourceId === sourceId) ?? null,
|
||||
});
|
||||
try {
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
const click = () => h.handlers[0].click({ screenPosition: { x: 1, y: 1 } });
|
||||
h.pick('a');
|
||||
click();
|
||||
const first = h.lastCard()[0];
|
||||
painted = [
|
||||
{ sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' },
|
||||
{ sourceId: 'shipwrecks', entryId: first.id },
|
||||
];
|
||||
h.pick(null);
|
||||
click();
|
||||
assert.deepEqual(h.opened, []);
|
||||
assert.equal(h.lastCard()[0].id, first.id);
|
||||
h.pick('b');
|
||||
click();
|
||||
assert.equal(h.lastCard()[0].id, 'shipwreck-card:b');
|
||||
painted = [{ sourceId: 'shipwrecks', entryId: 'shipwreck-card:b' }];
|
||||
h.pick(null);
|
||||
click();
|
||||
assert.deepEqual(h.opened, ['https://example.com/b']);
|
||||
painted = [];
|
||||
click();
|
||||
assert.deepEqual(h.lastCard(), [], 'bare map still clears the selection');
|
||||
} finally {
|
||||
h.layer.destroy();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user