fix(touch): give each tap to the layer that acts on it

On a coarse pointer the dispatcher can name a contact near the tap instead
of the exact pick. Only flights, military, vessels, radio and Street Level
act on such a contact, so they now register as expanded pick owners, and a
quake card or label yields only to them. A FIRMS fire or CCTV camera reached
only as a nearby contact no longer swallows a quake card, a quake label or
a vessel's own card tap, and FIRMS and CCTV cards yield to a contact whose
layer does act on it.

Radio and Street Level also pick through their own windows. A station or
Street Level item found only there, not as the touch contact, yields to
another layer's card painted over it, and Street Level takes its own touch
contact beyond its narrower window.

Fire, CCTV and vessel cards now act over a passive owner's pick (a flight
trail, the directions route), as the quake card does. The Context panel
leaves a passive route, or a fire or camera reached only as a nearby
contact, to the card painted over it.
This commit is contained in:
manjunath22466 committed 2026-11-17 13:18:32 +05:30
1 parent 4804097ca1
commit 830c980ca6
26 files changed
+1095 -69

No files matched your search

+23 -2
View File
@@ -24,7 +24,23 @@ export function createSelection({ state, parts }) {
function onClick(event) {
if (!state.viewer || !state.enabled) return;
const hit = event.windowHit(CLICK_PICK_WINDOW_PX, CLICK_PICK_WINDOW_PX);
const route = parts.router.resolve(pickIdOf(hit));
const windowId = pickIdOf(hit);
// A coarse tap's touch contact (event.hit) reaches farther than this
// window; a card or label over it yields to our item there, so it is ours.
const contact = event.hit;
const contactId =
contact && !contact.surface
? pickIdOf({ drawHit: contact.set ? contact : null, id: event.id })
: null;
let route = parts.router.resolve(windowId);
// Found only through our window, not as the contact (which is the exact
// hit whenever there is one): another layer's card or label painted here
// is that layer's click, since its handler never sees this window.
if (route && windowId !== contactId) {
const at = event.screenPosition;
if (state.services.overlayHit?.(at?.x, at?.y)) return;
}
if (!route && contactId) route = parts.router.resolve(contactId);
// Not ours: the ground handler decides whether it is the map itself.
if (!route) {
parts.openAtGround?.({ surface: hit.surface, ground: groundOf(event) });
@@ -71,7 +87,12 @@ export function createSelection({ state, parts }) {
if (state.clickSubscription) return;
state.clickSubscription = inputFor(viewer).onClick(onClick);
document.addEventListener('keydown', onKeyDown);
picking?.registerPickOwner?.(STREET_LEVEL_LAYER_ID, parts.router.ownsPick);
picking?.registerPickOwner?.(STREET_LEVEL_LAYER_ID, parts.router.ownsPick, {
expanded: true,
// The core's position marker is ours but selects nothing: a card over
// it keeps the tap.
passive: (id) => !parts.router.resolve(id)?.instance,
});
}
function uninstall() {
+135
View File
@@ -4,6 +4,7 @@ import * as Cesium from 'cesium';
import { createSelection } from './selection.js';
import { createPickRouter } from './pickRouter.js';
import { fakeInput } from '../../input/testDoubles.mjs';
import * as pickRegistry from '../../data/pickRegistry.js';
/** The selection installed on a stand-in viewer, with what its clicks reach. */
function harness({
@@ -289,3 +290,137 @@ test('a click on a provider line hands it the ground under the click, measured o
h.restore();
}
});
// An image found only through Street Level's own window (not the exact pick)
// under another layer's card or label is that card's click: its layer never
// sees this window.
test('an item found only in our window yields to a card painted over it', () => {
let top = null;
const h = harness({
services: { overlayHit: () => top },
sceneExtras: {
pick: (_position, width = 3) =>
width >= 9 ? { id: 'mly:img:near' } : null,
},
});
try {
h.click();
assert.deepEqual(h.opened, ['near'], 'open map: the window finds it');
top = { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' };
h.click();
assert.deepEqual(h.opened, ['near'], 'under a card: the card keeps it');
assert.equal(h.groundClicks.length, 0);
} finally {
h.restore();
}
});
// A coarse tap's touch contact reaches farther than this window. A quake card
// or label over that contact yields to it, so Street Level takes it here.
test('a coarse touch contact beyond our window is ours to open', (t) => {
const previous = globalThis.matchMedia;
globalThis.matchMedia = () => ({ matches: true });
t.after(() => {
if (previous) globalThis.matchMedia = previous;
else delete globalThis.matchMedia;
});
const h = harness({
services: {
picking: pickRegistry,
overlayHit: () => ({ sourceId: 'earthquake-card', entryId: 'q' }),
},
sceneExtras: {
pick: () => null,
drillPick: () => [{ id: 'mly:img:contact' }],
},
});
try {
h.click();
assert.deepEqual(h.opened, ['contact']);
assert.equal(h.groundClicks.length, 0);
} finally {
h.restore();
}
});
// The exact hit or the touch contact is ours under a card too: a quake card
// or label yields to a Street Level owner's pick, so yielding back would
// leave the click dead. Line parts compare by the sequence they pick as.
test('an exact or contact hit on our line part acts under a card', (t) => {
const part = {
set: 'street-level:mapillary-coverage:1',
id: 'mly:seq:abc#2',
meta: { pick: 'mly:seq:abc' },
};
const card = () => ({ sourceId: 'earthquake-card', entryId: 'q' });
const exact = harness({ services: { overlayHit: card } });
try {
exact.scene.under = part;
exact.click();
assert.deepEqual(exact.sequences.selects, ['abc'], 'mouse, exact part');
} finally {
exact.restore();
}
const previous = globalThis.matchMedia;
globalThis.matchMedia = () => ({ matches: true });
t.after(() => {
if (previous) globalThis.matchMedia = previous;
else delete globalThis.matchMedia;
});
const contact = harness({
services: { picking: pickRegistry, overlayHit: card },
sceneExtras: {
pick: (_position, width = 3) => (width >= 9 ? { id: part } : null),
drillPick: () => [{ id: part }],
},
});
try {
contact.click();
assert.deepEqual(contact.sequences.selects, ['abc'], 'coarse contact');
} finally {
contact.restore();
}
});
// Our window catching another layer's item says nothing about our own touch
// contact beyond it: that contact is still ours under a card.
test('a contact of ours acts even when our window finds another item', (t) => {
const previous = globalThis.matchMedia;
globalThis.matchMedia = () => ({ matches: true });
t.after(() => {
if (previous) globalThis.matchMedia = previous;
else delete globalThis.matchMedia;
});
const h = harness({
services: {
picking: pickRegistry,
overlayHit: () => ({ sourceId: 'earthquake-card', entryId: 'q' }),
},
sceneExtras: {
pick: (_position, width = 3) =>
width >= 9 ? { id: { set: 'flights:1', id: 'flight:9' } } : null,
drillPick: () => [{ id: 'mly:img:contact' }],
},
});
try {
h.click();
assert.deepEqual(h.opened, ['contact']);
} finally {
h.restore();
}
});
// The core's position marker is ours but selects nothing, so it is a passive
// pick: a card painted over it keeps the tap. Our images and lines act.
test('the position marker is a passive pick; our items act', () => {
const h = harness({ services: { picking: pickRegistry } });
try {
const acted = (id) =>
pickRegistry.isActedOnByOtherLayer('test-card', id, { expanded: true });
assert.equal(pickRegistry.findPickOwner('sl:pos'), 'street-level');
assert.equal(acted('sl:pos'), false, 'the marker acts for nobody');
assert.equal(acted('mly:img:abc'), true, 'an image opens');
} finally {
h.restore();
}
});