mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Draw the installations layer through the renderer ports
The site dots, outlines and selected footprint fill are now draw-port sets (points, draped lines, clamped shapes) instead of Cesium entities. The selected site's dot is drawn by a set of its own, so selecting a site redraws no other dot. Selection is registered through plain carrier objects in the context store, as the local GeoJSON layer does, and the tracked card reads the site's label and position from the carrier's entity record. A double-click on a site dot now follows it through camera.follow (gated on the stock double-click follow), centred on the surface under the dot when its height is loaded; one on an outline or fill zooms to it. Hiding the layer stops a follow it started. The layer no longer lowers the shared camera change sensitivity: its own camera-port listener carries its threshold. The follow offset fitting moves to src/geo/frames.js and is shared with the local GeoJSON layer. rendering.js leaves the Cesium allow-list (33 -> 32); the layer's entry joins DRAW_FROM_CALLER.
This commit is contained in:
1 parent
a59f9b10b2
commit
1bff078097
21 files changed
+864
-337
No files matched your search
@@ -7,6 +7,7 @@ import { createRendering } from './rendering.js';
|
||||
import { createNamedMarkers, namedPointId } from './namedMarkers.js';
|
||||
import { bindFakeCesiumScene } from '../../testSupport/fakeCesiumScene.mjs';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
|
||||
function harness(t) {
|
||||
const previousWindow = globalThis.window;
|
||||
@@ -37,9 +38,18 @@ function harness(t) {
|
||||
records: [record],
|
||||
recordById: new Map([[record.id, record]]),
|
||||
renderedKeys: new Map(),
|
||||
dataSource: new Cesium.CustomDataSource(),
|
||||
viewer: {
|
||||
camera: { positionWC: Cesium.Cartesian3.fromDegrees(0, 0, 1e6) },
|
||||
// The viewer's stock double-click follow, which the site follow
|
||||
// stands in for.
|
||||
screenSpaceEventHandler: {
|
||||
getInputAction: (type) =>
|
||||
type === Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
|
||||
? () => {}
|
||||
: undefined,
|
||||
setInputAction() {},
|
||||
removeInputAction() {},
|
||||
},
|
||||
scene: {
|
||||
globe: { show: false },
|
||||
canvas: Object.assign(new EventTarget(), {
|
||||
@@ -52,7 +62,7 @@ function harness(t) {
|
||||
},
|
||||
};
|
||||
let picked;
|
||||
const { draw } = bindFakeCesiumScene(state.viewer);
|
||||
const { draw, camera, query } = bindFakeCesiumScene(state.viewer);
|
||||
const input = fakeInput(state.viewer);
|
||||
t.mock.method(
|
||||
Cesium.SceneTransforms,
|
||||
@@ -85,6 +95,7 @@ function harness(t) {
|
||||
},
|
||||
};
|
||||
parts.rendering = createRendering(ctx);
|
||||
parts.rendering.attach(state.viewer);
|
||||
parts.namedMarkers = createNamedMarkers(ctx);
|
||||
const selection = createSelection(ctx);
|
||||
selection.installInteraction(state.viewer);
|
||||
@@ -93,6 +104,7 @@ function harness(t) {
|
||||
state.clickSubscription();
|
||||
parts.namedMarkers.destroy();
|
||||
parts.rendering.clearRendered();
|
||||
parts.rendering.detach();
|
||||
input.destroy();
|
||||
if (previousWindow === undefined) delete globalThis.window;
|
||||
else globalThis.window = previousWindow;
|
||||
@@ -103,10 +115,7 @@ function harness(t) {
|
||||
assert.equal(state.selectedId, selected ? record.id : null);
|
||||
assert.equal(labels[0].selected, selected);
|
||||
assert.equal(labels[0].variant, selected ? 'selected' : 'card');
|
||||
assert.equal(
|
||||
state.dataSource.entities.values.filter((e) => e.polygon).length,
|
||||
selected ? 1 : 0,
|
||||
);
|
||||
assert.equal(state.sets.fills.size(), selected ? 1 : 0);
|
||||
};
|
||||
assert.equal(selection.selectRecord(record.id), true);
|
||||
assertSelected(true);
|
||||
@@ -115,6 +124,9 @@ function harness(t) {
|
||||
selection,
|
||||
assertSelected,
|
||||
draw,
|
||||
camera,
|
||||
query,
|
||||
input,
|
||||
parts,
|
||||
/** Click on what `pick` names, as the scene would pick it. */
|
||||
click(value) {
|
||||
@@ -186,3 +198,142 @@ test('a click on a named marker point selects its site; again releases it', (t)
|
||||
h.click({ id: { set: 'other:1', id: item.id, meta: item.meta } });
|
||||
h.assertSelected(false);
|
||||
});
|
||||
|
||||
test('a click on a site dot or its outline selects the site; another set does not', (t) => {
|
||||
const h = harness(t);
|
||||
h.state.selectedId = null;
|
||||
context.clearSelectedEntityContextForLayer('military-installations');
|
||||
h.state.records[0].namedArea = false;
|
||||
h.state.records[0].outlineLines = [
|
||||
[
|
||||
[0, 0],
|
||||
[0.01, 0],
|
||||
],
|
||||
];
|
||||
h.parts.rendering.renderRecords();
|
||||
const selectedNow = () => h.state.selectedId === 'base';
|
||||
assert.equal(selectedNow(), false);
|
||||
const dots = h.state.sets.dots;
|
||||
const dot = h.draw.set(dots.id).items.get('base');
|
||||
assert.equal(dot.show, true);
|
||||
assert.equal(dot.height, 'clampGround');
|
||||
assert.equal(dot.pixelSize, 9);
|
||||
assert.equal(dot.disableDepthTest, Infinity);
|
||||
// The dot carries the site's shared context record, for point-and-ask.
|
||||
assert.equal(context.getContextStore().entities.get('base').entity, dot.meta);
|
||||
h.click({ id: { set: dots.id, id: 'base', meta: dot.meta } });
|
||||
assert.equal(selectedNow(), true);
|
||||
assert.equal(context.getSelectedEntityContext().id, 'base');
|
||||
// Drawn larger and white by the selected set, hidden in its own.
|
||||
assert.equal(h.draw.set(dots.id).items.get('base').show, false);
|
||||
assert.equal(h.draw.set(dots.id).items.get('base').pixelSize, 9);
|
||||
const selectedSet = h.draw.set(h.state.sets.selected.id);
|
||||
const selected = selectedSet.items.get('base');
|
||||
assert.equal(selected.pixelSize, 13);
|
||||
assert.deepEqual(selected.color, [1, 1, 1, 1]);
|
||||
assert.equal(selected.meta, dot.meta);
|
||||
// A click on the selected dot clears it.
|
||||
h.click({ id: { set: selectedSet.spec.id, id: 'base', meta: dot.meta } });
|
||||
assert.equal(selectedNow(), false);
|
||||
assert.equal(selectedSet.items.size, 0);
|
||||
assert.equal(h.draw.set(dots.id).items.get('base').show, true);
|
||||
const outlines = h.state.sets.outlines;
|
||||
const outline = h.draw.set(outlines.id).items.get('base:outline:0');
|
||||
assert.equal(outline.mode, 'draped');
|
||||
assert.equal(outline.clampTo, 'both');
|
||||
h.click({ id: { set: outlines.id, id: outline.id, meta: outline.meta } });
|
||||
assert.equal(selectedNow(), true);
|
||||
h.click({ id: { set: 'other:1', id: outline.id, meta: outline.meta } });
|
||||
assert.equal(selectedNow(), false);
|
||||
});
|
||||
|
||||
test('a double-click follows a site dot where it is drawn and zooms to its outline', (t) => {
|
||||
const h = harness(t);
|
||||
h.state.records[0].namedArea = false;
|
||||
h.state.records[0].outlineLines = [
|
||||
[
|
||||
[0, 0],
|
||||
[0.01, 0],
|
||||
],
|
||||
];
|
||||
h.parts.rendering.renderRecords({ claimSelection: true });
|
||||
h.state.enabled = true;
|
||||
const follows = [];
|
||||
const flights = [];
|
||||
let followed = null;
|
||||
Object.assign(h.camera, {
|
||||
follow(target) {
|
||||
follows.push(target);
|
||||
followed = target;
|
||||
},
|
||||
flyToBounds(sphere, options) {
|
||||
flights.push({ sphere, options });
|
||||
},
|
||||
controls: { minDistance: 1, maxDistance: 1e9 },
|
||||
});
|
||||
Object.defineProperty(h.camera, 'followed', { get: () => followed });
|
||||
let hit = null;
|
||||
h.query.pick = () => hit;
|
||||
const dots = h.state.sets.dots;
|
||||
const dot = h.draw.set(dots.id).items.get('base');
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(follows.length, 0, 'nothing of the layer under it');
|
||||
hit = { set: dots.id, id: 'base', meta: dot.meta, surface: false };
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
const target = follows.at(-1);
|
||||
assert.equal(target.key, 'installations:base');
|
||||
assert.equal(target.frame, 'enu');
|
||||
// The tracked card reads the site through the target's entity.
|
||||
assert.equal(target.entity, dot.meta);
|
||||
assert.equal(target.labelModel.title, 'Base');
|
||||
const at = target.position(0);
|
||||
assert.ok(Math.abs(at.x - 6378137) < 1e-6 && Math.abs(at.y) < 1e-6);
|
||||
// 100 m from it, north up, pitched down 45 degrees.
|
||||
const range = Math.hypot(
|
||||
target.viewFrom.x,
|
||||
target.viewFrom.y,
|
||||
target.viewFrom.z,
|
||||
);
|
||||
assert.ok(Math.abs(range - 100) < 1e-6);
|
||||
assert.ok(Math.abs(target.viewFrom.x) < 1e-9);
|
||||
assert.ok(Math.abs(target.viewFrom.y + target.viewFrom.z) < 1e-6);
|
||||
// On the surface under the dot once its height is loaded, before the
|
||||
// cached floor has it, and held there.
|
||||
h.query.sampleHeightNow = () => 2400;
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
const raised = follows.at(-1).position(0);
|
||||
assert.ok(Math.abs(raised.x - 6380537) < 1e-6);
|
||||
h.query.sampleHeightNow = () => null;
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.ok(Math.abs(follows.at(-1).position(0).x - 6378137) < 1e-6);
|
||||
const outlines = h.state.sets.outlines;
|
||||
hit = {
|
||||
set: outlines.id,
|
||||
id: 'base:outline:0',
|
||||
meta: { installationId: 'base' },
|
||||
surface: false,
|
||||
};
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(followed, null, 'a zoom stops the follow');
|
||||
assert.equal(flights.length, 1);
|
||||
assert.equal(flights[0].options.durationS, 0);
|
||||
// The follow stops when the layer hides.
|
||||
hit = { set: dots.id, id: 'base', meta: dot.meta, surface: false };
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(followed?.key, 'installations:base');
|
||||
h.parts.rendering.setShown(false);
|
||||
assert.equal(followed, null);
|
||||
// Another layer's item under the cursor neither follows nor zooms.
|
||||
h.parts.rendering.setShown(true);
|
||||
const before = follows.length;
|
||||
hit = { set: 'another:1', id: 'base', meta: dot.meta, surface: false };
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(follows.length, before);
|
||||
assert.equal(flights.length, 1);
|
||||
// With the stock double-click follow turned off, nothing follows.
|
||||
hit = { set: dots.id, id: 'base', meta: dot.meta, surface: false };
|
||||
const release = inputFor(h.state.viewer).suppressStockClicks();
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(follows.length, before);
|
||||
release();
|
||||
});
|
||||
Reference in new issue
Block a user