Installations: a label box takes a click only when nothing else was hit

The fallback to the label box the shared overlay paints for a site now runs
only when the click hit nothing drawn (the map itself), reads the overlay in
CSS pixels, and accepts the site only when its label is the one painted on
top there: an aircraft or vessel, or another layer's label, over a site's
label keeps its own click. Tested against the overlay's hit rects, not a stub.
This commit is contained in:
Denis Groshev committed 2026-11-17 16:28:04 +01:00
1 parent be326fdcf4
commit 9ed6f11c58
3 files changed
+101 -13

No files matched your search

@@ -0,0 +1,84 @@
// 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.
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',
kind: 'installation',
name: 'Base',
class: 'base',
latitude: 10,
longitude: 20,
});
/** The installations controls over a fake overlay whose hit rects are given. */
function controlsWith(rects) {
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 };
}
return null;
},
};
const controls = createControls({
state: {
enabled: true,
records: [RECORD],
recordById: new Map([[RECORD.id, RECORD]]),
},
services: {},
parts: { rendering: { installationSurfaceHeightM: () => 0 } },
source: {},
overlayHost,
});
return controls.methods;
}
const OWN = {
sourceId: LAYER_ID,
entryId: 'base',
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]);
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 },
]);
assert.equal(
methods.findAt({ x: 120, y: 110 }),
null,
'the flight is on top',
);
assert.equal(
methods.findAt({ x: 170, y: 110 })?.id,
'base',
'where the site is on top, it is found',
);
});