fix(bikeshare): a double-click follows the selected station again

The selected station's highlight was a point entity, which the default
renderer's double-click followed; deselecting removed it and ended the
follow. As a draw-port point it took no part in it. The station dots were
point primitives before, so they still take none.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:30:38 -08:00
1 parent 9c4c831ba2
commit 0dc3a1fb66
2 files changed
+96 -1

No files matched your search

+24 -1
View File
@@ -1,5 +1,6 @@
import { t } from '../../i18n/index.js';
import { inputFor } from '../../input/dispatcher.js';
import { followOnDoubleClick } from '../../data/stockFollow.js';
import {
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS,
@@ -101,6 +102,8 @@ export function createSelection({
if (record?.position)
layerState._stationSet?.upsert([parts.rendering.stationItem(record)]);
if (layerState._selectedSet?.size()) layerState._selectedSet.clear();
// Removing the highlight entity ended the default renderer's follow of it.
layerState._stockFollow?.stop();
layerState._overlayHost.clearSource(BIKESHARE_SELECTED_OVERLAY_SOURCE_ID);
}
@@ -142,7 +145,7 @@ export function createSelection({
function _installClickHandler(viewer) {
if (layerState._clickSubscription) return;
layerState._clickSubscription = inputFor(viewer).onClick((event) => {
const clickOff = inputFor(viewer).onClick((event) => {
const hit = event.drawHit;
if (hit) {
@@ -162,6 +165,26 @@ export function createSelection({
// Clicked anything else — deselect.
if (layerState._selectedKey) _clearSelection();
});
// A double-click follows the selected station's highlight, as the
// default renderer followed the point entity it was (the station dots
// were point primitives, which it never followed).
layerState._stockFollow = followOnDoubleClick({
viewer,
inputFor,
name: 'bikeshare',
enabled: () => layerState._enabled,
targetFor: (hit) => {
const key = layerState._selectedKey;
const position = layerState._stationRenderMap.get(key)?.position;
if (hit.set !== layerState._selectedSet?.id || !position) return null;
return { key, position: () => ({ ...position }) };
},
});
layerState._clickSubscription = () => {
clickOff?.();
layerState._stockFollow?.destroy();
layerState._stockFollow = null;
};
document.addEventListener('keydown', _onKeyDown);
}
+72
View File
@@ -0,0 +1,72 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createSelection } from './selection.js';
import { bindFakeGroundRenderer } from '../../testSupport/fakeGroundRenderer.mjs';
import { fromDegrees } from '../../geo/ellipsoid.js';
test('a double-click follows the selected station, as its highlight entity was; deselecting ends it', (t) => {
const viewer = {};
const fake = bindFakeGroundRenderer(viewer);
t.after(fake.unbind);
const listeners = {};
fake.renderer.input = {
on(type, fn) {
listeners[type] = fn;
return () => delete listeners[type];
},
behaviours: { dblclickFollow: { enabled: true } },
};
const press = (type) =>
listeners[type]({
button: 0,
modifiers: { shift: false, ctrl: false, alt: false, meta: false },
position: { x: 5, y: 5 },
});
const position = fromDegrees(2, 41, 20);
const state = {
_enabled: true,
_selectedKey: null,
_stationRenderMap: new Map([['bcn:1', { position, stationId: '1' }]]),
_stationSet: fake.renderer.draw.points({ id: 'bikeshare:stations' }),
_selectedSet: fake.renderer.draw.points({ id: 'bikeshare:selected' }),
_overlayHost: { setEntries() {}, clearSource() {} },
_clickSubscription: null,
};
const selection = createSelection({
state,
services: {},
parts: {
rendering: { stationItem: (r) => ({ id: 'bcn:1', pos: r.position }) },
},
source: {},
});
const priorDocument = globalThis.document;
globalThis.document = { addEventListener() {}, removeEventListener() {} };
t.after(() => {
if (priorDocument === undefined) delete globalThis.document;
else globalThis.document = priorDocument;
});
selection._installClickHandler(viewer);
// A station dot itself (a point primitive before) is never followed.
fake.setPick(() => ({ set: 'bikeshare:stations', id: 'bcn:1' }));
press('dblclick');
assert.equal(fake.follows.length, 0);
// Its first click selects it; the double-click lands on the highlight.
press('click');
assert.equal(state._selectedKey, 'bcn:1');
fake.setPick(() => ({ set: 'bikeshare:selected', id: 'selected' }));
press('dblclick');
assert.equal(fake.follows.length, 1);
assert.deepEqual(fake.renderer.camera.followed.position(), { ...position });
selection._clearSelection();
assert.equal(fake.renderer.camera.followed, null, 'the highlight went');
// Disabled: a double-click on it follows nothing.
state._clickSubscription();
selection._selectStation('bcn:1');
press('dblclick');
assert.equal(fake.follows.length, 2, 'only the stop since');
});