mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
Installations: a label takes a click only where nothing else is drawn
An interactive overlay entry is a card that takes every click from what is drawn under it, so a base's label kept an aircraft or vessel under it from being selected. The labels are no longer interactive entries. The layer claims a click on a label box through the pick registry's click claim, as CCTV counts do, only where nothing another layer draws is under it; over the map or the layer's own dots and fills the label takes it, and another layer's card painted over the label keeps its click. The label box is read from the box the overlay painted for it (overlayHost.paintRect).
This commit is contained in:
1 parent
7b7eb2318a
commit
dac8738b80
9 files changed
+229
-102
No files matched your search
@@ -1,10 +1,10 @@
|
||||
// src/layers/installations/labelBoxClick.test.mjs — a click on a mapped
|
||||
// installation's label box finds the site only where that label is the one
|
||||
// painted on top: another layer's label over it keeps the click.
|
||||
// installation's label box finds the site, read from the box the overlay
|
||||
// painted for it, unless another layer's card or label that takes clicks is
|
||||
// painted there.
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createControls } from './controls.js';
|
||||
import { LAYER_ID } from './policy.js';
|
||||
|
||||
const RECORD = Object.freeze({
|
||||
id: 'base',
|
||||
@@ -15,27 +15,28 @@ const RECORD = Object.freeze({
|
||||
longitude: 20,
|
||||
});
|
||||
|
||||
/** The installations controls over a fake overlay whose hit rects are given. */
|
||||
function controlsWith(rects) {
|
||||
const inside = (box, { x, y }) =>
|
||||
x >= box.x && x <= box.x + box.w && y >= box.y && y <= box.y + box.h;
|
||||
|
||||
/**
|
||||
* The installations controls over a fake overlay: `cards` are the hit rects
|
||||
* of entries that take clicks (other layers'), `labels` the boxes painted
|
||||
* for this layer's labels, which are not cards.
|
||||
*/
|
||||
function controlsWith({ cards = [], labels = {} }) {
|
||||
const overlayHost = {
|
||||
// As the world overlay does: the last painted rect under the point wins,
|
||||
// filtered to a source when one is asked for.
|
||||
hitTest(x, y, options = {}) {
|
||||
for (let i = rects.length - 1; i >= 0; i--) {
|
||||
const rect = rects[i];
|
||||
if (options.sourceId && rect.sourceId !== options.sourceId) continue;
|
||||
if (
|
||||
x < rect.x ||
|
||||
x > rect.x + rect.w ||
|
||||
y < rect.y ||
|
||||
y > rect.y + rect.h
|
||||
)
|
||||
continue;
|
||||
return { sourceId: rect.sourceId, entryId: rect.entryId };
|
||||
}
|
||||
// As the world overlay does: the last painted card under the point wins.
|
||||
hitTest(x, y) {
|
||||
for (let i = cards.length - 1; i >= 0; i--)
|
||||
if (inside(cards[i], { x, y }))
|
||||
return { sourceId: cards[i].sourceId, entryId: cards[i].entryId };
|
||||
return null;
|
||||
},
|
||||
};
|
||||
const namedMarkers = {
|
||||
labelAt: (position) =>
|
||||
Object.keys(labels).find((id) => inside(labels[id], position)) ?? null,
|
||||
};
|
||||
const controls = createControls({
|
||||
state: {
|
||||
enabled: true,
|
||||
@@ -43,42 +44,40 @@ function controlsWith(rects) {
|
||||
recordById: new Map([[RECORD.id, RECORD]]),
|
||||
},
|
||||
services: {},
|
||||
parts: { rendering: { installationSurfaceHeightM: () => 0 } },
|
||||
parts: {
|
||||
rendering: { installationSurfaceHeightM: () => 0 },
|
||||
namedMarkers,
|
||||
},
|
||||
source: {},
|
||||
overlayHost,
|
||||
});
|
||||
return controls.methods;
|
||||
}
|
||||
|
||||
const OWN = {
|
||||
sourceId: LAYER_ID,
|
||||
entryId: 'base',
|
||||
x: 100,
|
||||
y: 100,
|
||||
w: 80,
|
||||
h: 20,
|
||||
};
|
||||
const BASE_LABEL = { x: 100, y: 100, w: 80, h: 20 };
|
||||
|
||||
test("a click on the site's own label box finds the site", () => {
|
||||
const methods = controlsWith([OWN]);
|
||||
const methods = controlsWith({ labels: { base: BASE_LABEL } });
|
||||
assert.equal(methods.findAt({ x: 120, y: 110 })?.id, 'base');
|
||||
assert.equal(methods.findAt({ x: 10, y: 10 }), null, 'outside every box');
|
||||
assert.equal(methods.findAt(null), null);
|
||||
});
|
||||
|
||||
test("another layer's label painted over the site's keeps the click", () => {
|
||||
const methods = controlsWith([
|
||||
OWN,
|
||||
{ sourceId: 'flights', entryId: 'abc123', x: 110, y: 105, w: 40, h: 12 },
|
||||
]);
|
||||
test("another layer's card painted over the site's label keeps the click", () => {
|
||||
const methods = controlsWith({
|
||||
labels: { base: BASE_LABEL },
|
||||
cards: [
|
||||
{ sourceId: 'flights', entryId: 'abc123', x: 110, y: 105, w: 40, h: 12 },
|
||||
],
|
||||
});
|
||||
assert.equal(
|
||||
methods.findAt({ x: 120, y: 110 }),
|
||||
null,
|
||||
'the flight is on top',
|
||||
'the flight card is on top',
|
||||
);
|
||||
assert.equal(
|
||||
methods.findAt({ x: 170, y: 110 })?.id,
|
||||
'base',
|
||||
'where the site is on top, it is found',
|
||||
'past the card, the site is found',
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user