mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
fix(click): the card or label on top takes the click in every layer
Review fixes for #1781: - One rule for cards: the world-overlay host hands its hit test to the pick registry, and every click handler reads the topmost interactive card or label once per click (`clickCard`, `isUnderOtherCard` in src/data/pickRegistry.js), so all handlers agree in any listener order. A layer whose own card or label is on top acts on it whatever is drawn under it; a layer under another layer's card neither acts nor treats the click as empty space (a tracked aircraft stays tracked, a selection stays selected); Context names nothing under a card. A selected news card over a vessel no longer opens the link and selects the vessel. - With one rule, the per-owner arbitration options are no longer read and are removed: `passive`, `expanded` and `declinesClick` pick owners, `rememberClickPickActions`, `isActedOnByOtherLayer`, card backgrounds and `cardKeepsClick`. The dispatcher is unchanged from main. - A drag that ends on a quake disc, label or card does nothing; opening the USGS page or clearing the selection needs a clean click. - A click on the map under another layer's card opens no Street Level ground image. - A CCTV card that is going away is still not the scene under it. - Docs and changelog describe the new rule.
This commit is contained in:
1 parent
7312280817
commit
bb3bf9858b
87 files changed
+1398
-1775
No files matched your search
@@ -199,7 +199,6 @@ export class StyleManager extends ShellFacade {
|
||||
pinia: applicationPinia(),
|
||||
pickWorld: services.pickWorldFromScreen,
|
||||
regionalBrief: services.fetchRegionalBrief,
|
||||
overlayHit: services.hitTestWorldOverlay,
|
||||
});
|
||||
this.mapStackController = mapStackController;
|
||||
this.placeSearch = placeSearch;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
import { fromDegrees } from '../geo/ellipsoid.js';
|
||||
import { inputFor } from '../input/dispatcher.js';
|
||||
import { isUnderOtherCard } from '../data/pickRegistry.js';
|
||||
import { findQuery } from '../render/rendererOf.js';
|
||||
import { clampOrbitalLook, easeLook } from '../cockpitLook.js';
|
||||
import { ORBITAL_EARTH_RADIUS_M } from '../cockpitOrbital.js';
|
||||
@@ -286,7 +287,12 @@ export function routeSceneClick() {
|
||||
// A viewer with no input (headless tools, partial stubs) has no clicks.
|
||||
return () => {};
|
||||
}
|
||||
return input.onClick((event) => this.onOrbitalClick(event?.position));
|
||||
return input.onClick((event) => {
|
||||
// Another layer's card or label painted on top takes the click: the site
|
||||
// under it does not focus, and the click does not end a held focus.
|
||||
if (isUnderOtherCard(event)) return;
|
||||
this.onOrbitalClick(event?.position);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@ import CockpitView from './views/CockpitView.vue';
|
||||
import ContextView from './views/ContextView.vue';
|
||||
import IntelHudView from './views/IntelHudView.vue';
|
||||
import { claimPointer, releasePointer } from '../data/inputOwnership.js';
|
||||
import { setClickCardHitTest } from '../data/pickRegistry.js';
|
||||
import { ORBITAL_FOCUS_EASE_TAU_MS } from '../cockpitOrbitalFocus.js';
|
||||
import { ORBITAL_HOP_MS } from '../cockpitOrbitalSatellites.js';
|
||||
|
||||
@@ -635,6 +636,23 @@ test('a click a tool owns is left alone', async (t) => {
|
||||
assert.equal(scene.cockpit.orbital.focus.key, SITES.alpha.id, 'kept while drawing');
|
||||
});
|
||||
|
||||
// The card or label painted on top takes the click: a site under another
|
||||
// layer's card does not focus, and a click there does not end a held focus.
|
||||
test('another layer\'s card over the orbital view keeps the click', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
let top = { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' };
|
||||
setClickCardHitTest(() => top);
|
||||
t.after(() => setClickCardHitTest(null));
|
||||
scene.click(SITES.alpha.at);
|
||||
assert.equal(scene.cockpit.orbital.focus ?? null, null, 'covered: no focus');
|
||||
top = null;
|
||||
scene.click(SITES.alpha.at);
|
||||
assert.equal(scene.cockpit.orbital.focus.key, SITES.alpha.id);
|
||||
top = { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' };
|
||||
scene.click(EMPTY_GROUND);
|
||||
assert.equal(scene.cockpit.orbital.focus.key, SITES.alpha.id, 'covered: kept');
|
||||
});
|
||||
|
||||
test('a double-click on a site focuses it and keeps the orbital view', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit, viewer, handler } = scene;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { cardKeepsClick, resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { clickCard } from '../data/pickRegistry.js';
|
||||
import { followedOf, onFollowChanged } from '../data/followed.js';
|
||||
import { fromDegreesInto } from '../geo/ellipsoid.js';
|
||||
import { inputFor } from '../input/dispatcher.js';
|
||||
@@ -45,8 +46,6 @@ const FOLLOWABLE = new Set(['flights', 'military', 'satellites']);
|
||||
* to the point under the camera without it.
|
||||
* @param {(lat: number, lon: number) => Promise<object>} [options.regionalBrief]
|
||||
* The app's regional brief service, for the weather and news Context shows.
|
||||
* @param {(x: number, y: number) => object|null} [options.overlayHit]
|
||||
* The overlay card under a screen point, if any (a vessel's, a fire's).
|
||||
* @returns {() => void} disconnects
|
||||
*/
|
||||
export function installEntityContext({
|
||||
@@ -55,7 +54,6 @@ export function installEntityContext({
|
||||
pinia,
|
||||
pickWorld,
|
||||
regionalBrief,
|
||||
overlayHit,
|
||||
}) {
|
||||
const store = useEntityCardStore(pinia);
|
||||
const omnibar = useOmnibarStore(pinia);
|
||||
@@ -311,16 +309,14 @@ export function installEntityContext({
|
||||
// Cockpit has its own picks, and Context is hidden while it runs. A
|
||||
// camera drag never selects, even if it ends over something.
|
||||
if (inCockpit() || !isTrackingSelectionGesture(event.gesture)) return;
|
||||
// A card or label painted on top is its layer's click, read once per
|
||||
// click so every layer agrees: Context names nothing under it and keeps
|
||||
// its own card as it is.
|
||||
if (clickCard(event)) return;
|
||||
const identity = resolvePickedContext(event.hit, {
|
||||
dataManager: getDataManager(),
|
||||
});
|
||||
if (identity) {
|
||||
// A card or label painted over an item its layer does not act on here
|
||||
// (a quake card beside a fire, or over a route) is the card's click.
|
||||
const underCard = Boolean(
|
||||
overlayHit?.(event.screenPosition?.x, event.screenPosition?.y),
|
||||
);
|
||||
if (cardKeepsClick(event, underCard)) return;
|
||||
// These layers start following on their own click; following again
|
||||
// from here would fight them (the flights layer reads a second track
|
||||
// of the same plane as a click on empty map and lets go).
|
||||
@@ -330,14 +326,8 @@ export function installEntityContext({
|
||||
// A click on open ground, sea or sky lets go of what was selected. A
|
||||
// click on something else Context cannot describe (a label, a trail)
|
||||
// leaves the card as it is.
|
||||
// Only a clean click lets go, as the layers' own clicks do; a card
|
||||
// painted on the overlay (a vessel's, a fire's) is not open map.
|
||||
if (
|
||||
event.surface &&
|
||||
isTrackingClickGesture(event.gesture) &&
|
||||
!overlayHit?.(event.screenPosition?.x, event.screenPosition?.y)
|
||||
)
|
||||
store.clear();
|
||||
// Only a clean click lets go, as the layers' own clicks do.
|
||||
if (event.surface && isTrackingClickGesture(event.gesture)) store.clear();
|
||||
});
|
||||
|
||||
// Layers that select through the context store (GeoJSON sites, fires,
|
||||
|
||||
@@ -6,14 +6,14 @@ import { useEntityCardStore } from './stores/entityCard.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import {
|
||||
registerPickOwner,
|
||||
setClickCardHitTest,
|
||||
unregisterPickOwner,
|
||||
} from '../data/pickRegistry.js';
|
||||
|
||||
// A coarse tap that misses everything exactly finds a fire within the shared
|
||||
// touch window. On open map Context names it; under a quake card or label the
|
||||
// card takes the tap, since the fire layer acts only on exact hits; an exact
|
||||
// hit on the fire is the fire's, under a card or not.
|
||||
test('Context leaves a near-missed exact-only item to a card painted over it', (t) => {
|
||||
// The card or label painted on top takes the click: Context names nothing
|
||||
// under it, exact or nearby, an acting owner's item or a passive one, and
|
||||
// keeps its own card. On open map it names what the click found.
|
||||
test('Context names nothing under a card painted on top, and keeps its card', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
@@ -21,17 +21,31 @@ test('Context leaves a near-missed exact-only item to a card painted over it', (
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = { set: 'test-fires:1', id: 'fire:1' };
|
||||
const plane = { set: 'test-planes:1', id: 'plane:1' };
|
||||
const route = { set: 'test-route:1', id: 'route:line' };
|
||||
registerPickOwner('test-fires', (id) => id === fire.id);
|
||||
t.after(() => unregisterPickOwner('test-fires'));
|
||||
let exact = false;
|
||||
registerPickOwner('test-planes', (id) => id === plane.id);
|
||||
registerPickOwner('test-route', (id) => id.startsWith('route:'));
|
||||
let cardOnTop = false;
|
||||
// The card on top at a click, as the host answers the pick registry.
|
||||
setClickCardHitTest(() =>
|
||||
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
|
||||
);
|
||||
t.after(() => {
|
||||
setClickCardHitTest(null);
|
||||
unregisterPickOwner('test-fires');
|
||||
unregisterPickOwner('test-planes');
|
||||
unregisterPickOwner('test-route');
|
||||
});
|
||||
let exact = null;
|
||||
let near = null;
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick: () => (exact ? { id: fire } : null),
|
||||
drillPick: () => [{ id: fire }],
|
||||
pick: () => (exact ? { id: exact } : null),
|
||||
drillPick: () => (near ? [{ id: near }] : []),
|
||||
},
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
let cardOnTop = false;
|
||||
const pinia = createPinia();
|
||||
const disconnect = installEntityContext({
|
||||
viewer,
|
||||
@@ -41,8 +55,6 @@ test('Context leaves a near-missed exact-only item to a card painted over it', (
|
||||
getAll: () => [],
|
||||
}),
|
||||
pinia,
|
||||
overlayHit: () =>
|
||||
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
|
||||
});
|
||||
t.after(() => {
|
||||
disconnect();
|
||||
@@ -50,52 +62,24 @@ test('Context leaves a near-missed exact-only item to a card painted over it', (
|
||||
});
|
||||
const store = useEntityCardStore(pinia);
|
||||
const named = [];
|
||||
let clears = 0;
|
||||
store.select = (identity) => named.push(identity.id);
|
||||
const tap = () => {
|
||||
store.clear = () => clears++;
|
||||
const tap = (hitExact, hitNear) => {
|
||||
exact = hitExact;
|
||||
near = hitNear;
|
||||
named.length = 0;
|
||||
input.click();
|
||||
return [...named];
|
||||
};
|
||||
assert.deepEqual(tap(), ['fire:1'], 'open map: Context names the fire');
|
||||
assert.deepEqual(tap(null, fire), ['fire:1'], 'open map: a near fire');
|
||||
assert.deepEqual(tap(route, null), ['route:line'], 'open map: a route');
|
||||
cardOnTop = true;
|
||||
assert.deepEqual(tap(), [], 'under a card: the card keeps the tap');
|
||||
exact = true;
|
||||
assert.deepEqual(tap(), ['fire:1'], 'an exact hit is the fire’s');
|
||||
});
|
||||
|
||||
// Every card layer acts over a passive owner's pick (a directions route), so
|
||||
// Context leaves an exact route hit under a card to that card, and names it on
|
||||
// open map as before.
|
||||
test('Context leaves an exact passive route under a card to the card', (t) => {
|
||||
const route = { set: 'test-route:1', id: 'route:line' };
|
||||
registerPickOwner('test-route', (id) => id.startsWith('route:'), {
|
||||
passive: true,
|
||||
});
|
||||
t.after(() => unregisterPickOwner('test-route'));
|
||||
const viewer = { scene: { pick: () => ({ id: route }) } };
|
||||
const input = fakeInput(viewer);
|
||||
let cardOnTop = false;
|
||||
const pinia = createPinia();
|
||||
const disconnect = installEntityContext({
|
||||
viewer,
|
||||
getDataManager: () => ({
|
||||
isEnabled: () => true,
|
||||
layers: new Map(),
|
||||
getAll: () => [],
|
||||
}),
|
||||
pinia,
|
||||
overlayHit: () =>
|
||||
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
|
||||
});
|
||||
t.after(() => {
|
||||
disconnect();
|
||||
input.destroy();
|
||||
});
|
||||
const named = [];
|
||||
useEntityCardStore(pinia).select = (identity) => named.push(identity.id);
|
||||
input.click();
|
||||
assert.deepEqual(named, ['route:line'], 'open map: Context names the route');
|
||||
cardOnTop = true;
|
||||
input.click();
|
||||
assert.deepEqual(named, ['route:line'], 'under a card: the card keeps it');
|
||||
assert.deepEqual(tap(null, fire), [], 'under a card: a near fire');
|
||||
assert.deepEqual(tap(fire, fire), [], 'under a card: an exact fire');
|
||||
assert.deepEqual(tap(plane, plane), [], 'under a card: an aircraft');
|
||||
assert.deepEqual(tap(route, null), [], 'under a card: a route');
|
||||
const cleared = clears;
|
||||
tap(null, null);
|
||||
assert.equal(clears, cleared, 'a card over open map is not open map');
|
||||
});
|
||||
@@ -140,6 +140,8 @@ function fixture(
|
||||
},
|
||||
}),
|
||||
focus: { requestWorldFocus: (value) => flights.push(value) },
|
||||
// The card on top at a click, as the registry answers from the host.
|
||||
picking: { clickCard: () => hit },
|
||||
},
|
||||
parts: {
|
||||
rendering: { refreshSelection() {}, requestRender() {} },
|
||||
|
||||
Reference in new issue
Block a user