mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(annotations): a double-click follows a pin and zooms to an area or line again
A mark's ring, marker, areas and lines were entities, which the default renderer's double-click followed (ring and marker) or zoomed to (the rest) until the mark was removed. As draw-port items they took no part in it.
This commit is contained in:
1 parent
94ea9cd01d
commit
322e4a91d3
2 files changed
+75
No files matched your search
@@ -6,9 +6,12 @@ import {
|
|||||||
drawOf,
|
drawOf,
|
||||||
findCamera,
|
findCamera,
|
||||||
findFrame,
|
findFrame,
|
||||||
|
findInput,
|
||||||
frameOf,
|
frameOf,
|
||||||
} from '../render/rendererOf.js';
|
} from '../render/rendererOf.js';
|
||||||
import { heightsOf } from '../queries/heights.js';
|
import { heightsOf } from '../queries/heights.js';
|
||||||
|
import { drawnItemTarget, followOnDoubleClick } from '../data/stockFollow.js';
|
||||||
|
import { inputFor } from '../input/dispatcher.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* World-space annotation renderer (Direction A).
|
* World-space annotation renderer (Direction A).
|
||||||
@@ -99,6 +102,8 @@ export function createWorldAnnotationRenderer(viewer) {
|
|||||||
const groundQueue = [];
|
const groundQueue = [];
|
||||||
let offGroundFrame = null;
|
let offGroundFrame = null;
|
||||||
let destroyed = false;
|
let destroyed = false;
|
||||||
|
/** The follow a double-click on a mark started (see the end). */
|
||||||
|
let stockFollow = null;
|
||||||
// Marks with a target ring, and the radius they are drawn at.
|
// Marks with a target ring, and the radius they are drawn at.
|
||||||
const ringed = new Set();
|
const ringed = new Set();
|
||||||
let offRingFrame = null;
|
let offRingFrame = null;
|
||||||
@@ -470,6 +475,9 @@ export function createWorldAnnotationRenderer(viewer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function remove(anno) {
|
function remove(anno) {
|
||||||
|
// Its entities went, and with them a follow of one.
|
||||||
|
const prefix = anno?._draw?.prefix;
|
||||||
|
if (prefix) stockFollow?.retain((key) => !key.startsWith(`${prefix}:`));
|
||||||
pendingGround.get(anno)?.finish('cancelled');
|
pendingGround.get(anno)?.finish('cancelled');
|
||||||
hideOsmCredit(viewer, anno);
|
hideOsmCredit(viewer, anno);
|
||||||
osmAnnotations.delete(anno);
|
osmAnnotations.delete(anno);
|
||||||
@@ -512,6 +520,8 @@ export function createWorldAnnotationRenderer(viewer) {
|
|||||||
|
|
||||||
function destroy() {
|
function destroy() {
|
||||||
destroyed = true;
|
destroyed = true;
|
||||||
|
stockFollow?.destroy();
|
||||||
|
stockFollow = null;
|
||||||
for (const task of [...pendingGround.values()]) task.finish('cancelled');
|
for (const task of [...pendingGround.values()]) task.finish('cancelled');
|
||||||
for (const anno of osmAnnotations) hideOsmCredit(viewer, anno);
|
for (const anno of osmAnnotations) hideOsmCredit(viewer, anno);
|
||||||
osmAnnotations.clear();
|
osmAnnotations.clear();
|
||||||
@@ -525,6 +535,41 @@ export function createWorldAnnotationRenderer(viewer) {
|
|||||||
drawn.clear();
|
drawn.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What a double-click on a hit follows or zooms to, as the default
|
||||||
|
* renderer did for a mark's entities: a pin's ring or marker is followed,
|
||||||
|
* an area, building or line zoomed to.
|
||||||
|
*/
|
||||||
|
function followTargetFor(hit) {
|
||||||
|
if (hit.surface) return null;
|
||||||
|
for (const anno of drawn) {
|
||||||
|
const sets = anno._draw;
|
||||||
|
const was = anno._drawn;
|
||||||
|
if (!sets || !was || anno.hidden) continue;
|
||||||
|
const kind = ['shapes', 'lines', 'points'].find(
|
||||||
|
(name) => sets[name]?.id === hit.set,
|
||||||
|
);
|
||||||
|
if (!kind) continue;
|
||||||
|
const item = was.items[kind]
|
||||||
|
.map((make) => make(was.alpha))
|
||||||
|
.find((candidate) => candidate.id === hit.id);
|
||||||
|
return drawnItemTarget(hit.set, item);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A double-click on a mark, as the default renderer's own followed its
|
||||||
|
// entities (a scene that takes no input has none).
|
||||||
|
stockFollow = findInput(viewer)
|
||||||
|
? followOnDoubleClick({
|
||||||
|
viewer,
|
||||||
|
inputFor,
|
||||||
|
name: 'annotations',
|
||||||
|
enabled: () => !destroyed,
|
||||||
|
targetFor: followTargetFor,
|
||||||
|
})
|
||||||
|
: null;
|
||||||
|
|
||||||
return { add, remove, sync, destroy };
|
return { add, remove, sync, destroy };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -446,3 +446,33 @@ test('a mark removed and added again draws afresh; two renderers on one viewer k
|
|||||||
assert.equal(route._draw, null, 'a destroyed renderer draws nothing more');
|
assert.equal(route._draw, null, 'a destroyed renderer draws nothing more');
|
||||||
assert.equal([...draw.sets.values()].filter((r) => !r.disposed).length, 0);
|
assert.equal([...draw.sets.values()].filter((r) => !r.disposed).length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a double-click follows a pin and zooms to an area, as their entities were; a removed pin ends it', async (t) => {
|
||||||
|
const { createStubRenderer } = await import('../render/stub/index.js');
|
||||||
|
const renderer = createStubRenderer();
|
||||||
|
const v = { isDestroyed: () => false };
|
||||||
|
const unbind = bindRenderer(v, renderer);
|
||||||
|
const r = createWorldAnnotationRenderer(v);
|
||||||
|
t.after(() => {
|
||||||
|
r.destroy();
|
||||||
|
unbind();
|
||||||
|
renderer.destroy();
|
||||||
|
});
|
||||||
|
const [, area, pin] = marks();
|
||||||
|
r.add(area);
|
||||||
|
r.add(pin);
|
||||||
|
const setOf = (anno, kind) => anno._draw[kind].id;
|
||||||
|
let hit = null;
|
||||||
|
renderer.testing.scriptPicks(() => (hit ? [hit] : []));
|
||||||
|
hit = { set: setOf(pin, 'points'), id: 'marker', surface: false };
|
||||||
|
renderer.testing.pointer('dblclick', 10, 10);
|
||||||
|
assert.ok(renderer.camera.followed, 'the pin is followed');
|
||||||
|
hit = { set: setOf(area, 'shapes'), id: 'fill:0', surface: false };
|
||||||
|
renderer.testing.pointer('dblclick', 10, 10);
|
||||||
|
assert.equal(renderer.camera.followed, null, 'the area is zoomed to');
|
||||||
|
hit = { set: setOf(pin, 'shapes'), id: 'ring', surface: false };
|
||||||
|
renderer.testing.pointer('dblclick', 10, 10);
|
||||||
|
assert.ok(renderer.camera.followed, 'its ring follows it too');
|
||||||
|
r.remove(pin);
|
||||||
|
assert.equal(renderer.camera.followed, null, 'removed: no longer followed');
|
||||||
|
});
|
||||||
Reference in new issue
Block a user