mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
fix(directions): a double-click follows an A or B marker and zooms to the route again
The markers and the route were entities, which the default renderer's double-click followed (a marker) or zoomed to (the route). As draw-port items they took no part in it. Directions now joins the stock double-click as launches and imported pins do.
This commit is contained in:
1 parent
4c7deb11dc
commit
63a6595eaf
2 files changed
+111
No files matched your search
@@ -2,6 +2,8 @@ import test from 'node:test';
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import * as Cesium from 'cesium';
|
import * as Cesium from 'cesium';
|
||||||
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
|
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
|
||||||
|
import { bindRenderer } from '../render/rendererOf.js';
|
||||||
|
import { createStubRenderer } from '../render/stub/index.js';
|
||||||
import {
|
import {
|
||||||
DEFAULT_DIRECTIONS_MODE,
|
DEFAULT_DIRECTIONS_MODE,
|
||||||
DIRECTIONS_MODES,
|
DIRECTIONS_MODES,
|
||||||
@@ -1025,3 +1027,69 @@ test('a placed endpoint draws its letter through the overlay, not as entity text
|
|||||||
directionsLayer.destroy(viewer);
|
directionsLayer.destroy(viewer);
|
||||||
assert.ok(cleared.includes(DIRECTIONS_MARKER_OVERLAY_SOURCE_ID));
|
assert.ok(cleared.includes(DIRECTIONS_MARKER_OVERLAY_SOURCE_ID));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a double-click follows an A or B marker and zooms to the route, as their entities did', async (t) => {
|
||||||
|
directionsLayer = createApplicationDirectionsLayer({
|
||||||
|
source: {
|
||||||
|
getRoute: async () => ({
|
||||||
|
ok: true,
|
||||||
|
distanceM: route.distanceM,
|
||||||
|
durationS: route.durationS,
|
||||||
|
geometry: route.geometry,
|
||||||
|
steps: route.steps,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
directionsLayer._setOverlayHostForTest({
|
||||||
|
setEntries() {},
|
||||||
|
setVisible() {},
|
||||||
|
clearSource() {},
|
||||||
|
});
|
||||||
|
resetPointerOwnership();
|
||||||
|
const renderer = createStubRenderer();
|
||||||
|
const viewer = { isDestroyed: () => false };
|
||||||
|
const unbind = bindRenderer(viewer, renderer);
|
||||||
|
t.after(() => {
|
||||||
|
directionsLayer.destroy(viewer);
|
||||||
|
directionsLayer._setOverlayHostForTest(null);
|
||||||
|
unbind();
|
||||||
|
renderer.destroy();
|
||||||
|
resetPointerOwnership();
|
||||||
|
});
|
||||||
|
directionsLayer.init(viewer);
|
||||||
|
directionsLayer.enable(viewer);
|
||||||
|
directionsLayer.placeEndpoint('a', A);
|
||||||
|
directionsLayer.placeEndpoint('b', B);
|
||||||
|
const started = Date.now();
|
||||||
|
while (
|
||||||
|
directionsLayer.getStats().status !== 'ready' &&
|
||||||
|
Date.now() - started < 5000
|
||||||
|
)
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||||
|
const setOf = (suffix) =>
|
||||||
|
renderer.testing.sets().find((id) => id.endsWith(suffix));
|
||||||
|
let hit = null;
|
||||||
|
renderer.testing.scriptPicks(() => (hit ? [hit] : []));
|
||||||
|
const markersId = setOf(':markers');
|
||||||
|
const routeId = setOf(':route');
|
||||||
|
assert.ok(markersId && routeId, 'the sets are drawn');
|
||||||
|
|
||||||
|
hit = { set: markersId, id: 'directions:marker:B', surface: false };
|
||||||
|
renderer.testing.pointer('dblclick', 10, 10);
|
||||||
|
const followed = renderer.camera.followed;
|
||||||
|
assert.ok(followed, 'B is followed');
|
||||||
|
assert.equal(followed.key, 'directions:marker:B');
|
||||||
|
const p = followed.position(0);
|
||||||
|
const at = Cesium.Cartographic.fromCartesian(
|
||||||
|
new Cesium.Cartesian3(p.x, p.y, p.z),
|
||||||
|
);
|
||||||
|
assert.ok(Math.abs(Cesium.Math.toDegrees(at.latitude) - B.lat) < 1e-9);
|
||||||
|
|
||||||
|
hit = { set: routeId, id: 'directions:route', surface: false };
|
||||||
|
renderer.testing.pointer('dblclick', 10, 10);
|
||||||
|
assert.equal(renderer.camera.followed, null, 'the route is zoomed to');
|
||||||
|
renderer.testing.tick();
|
||||||
|
const pose = renderer.camera.pose();
|
||||||
|
assert.ok(Math.abs(pose.lat - (A.lat + B.lat) / 2) < 0.2, String(pose.lat));
|
||||||
|
assert.ok(Math.abs(pose.lon - (A.lon + B.lon) / 2) < 0.2, String(pose.lon));
|
||||||
|
});
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
import { roadLabel } from '../../data/routeSteps.js';
|
import { roadLabel } from '../../data/routeSteps.js';
|
||||||
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
||||||
|
import { sphereFromPoints } from '../../geo/sphere.js';
|
||||||
|
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||||
import { hexColor } from '../../render/color.js';
|
import { hexColor } from '../../render/color.js';
|
||||||
import { drawOf } from '../../render/rendererOf.js';
|
import { drawOf } from '../../render/rendererOf.js';
|
||||||
import {
|
import {
|
||||||
@@ -1637,6 +1639,31 @@ export function createDirectionsLayer({ services, source }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** What a double-click on a marker or the route follows or zooms to. */
|
||||||
|
function followTargetFor(hit) {
|
||||||
|
if (!_sets) return null;
|
||||||
|
if (hit.set === _sets.markers.id) {
|
||||||
|
const point =
|
||||||
|
hit.id === 'directions:marker:A'
|
||||||
|
? _a
|
||||||
|
: hit.id === 'directions:marker:B'
|
||||||
|
? _b
|
||||||
|
: null;
|
||||||
|
if (!point) return null;
|
||||||
|
return {
|
||||||
|
key: hit.id,
|
||||||
|
position: () => fromDegrees(point.lon, point.lat, 0),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (hit.set === _sets.route.id && _route?.geometry?.length)
|
||||||
|
return {
|
||||||
|
zoomTo: sphereFromPoints(
|
||||||
|
_route.geometry.map(([lon, lat]) => fromDegrees(lon, lat, 0)),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function _installClickHandler(viewer) {
|
function _installClickHandler(viewer) {
|
||||||
if (_clickSubscription) return;
|
if (_clickSubscription) return;
|
||||||
const input = inputFor(viewer);
|
const input = inputFor(viewer);
|
||||||
@@ -1670,9 +1697,25 @@ export function createDirectionsLayer({ services, source }) {
|
|||||||
}
|
}
|
||||||
if (_selectedStep !== null) _clearStepSelection();
|
if (_selectedStep !== null) _clearStepSelection();
|
||||||
});
|
});
|
||||||
|
// A double-click follows an A or B marker and zooms to the route, as the
|
||||||
|
// default renderer's double-click did with their entities.
|
||||||
|
let follow = null;
|
||||||
|
try {
|
||||||
|
follow = followOnDoubleClick({
|
||||||
|
viewer,
|
||||||
|
inputFor: () => input,
|
||||||
|
name: 'directions',
|
||||||
|
enabled: () => _enabled,
|
||||||
|
targetFor: followTargetFor,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// A renderer that takes no input has no double-click to follow on.
|
||||||
|
follow = null;
|
||||||
|
}
|
||||||
_clickSubscription = () => {
|
_clickSubscription = () => {
|
||||||
offPlace();
|
offPlace();
|
||||||
offSelect();
|
offSelect();
|
||||||
|
follow?.destroy();
|
||||||
};
|
};
|
||||||
if (typeof document !== 'undefined')
|
if (typeof document !== 'undefined')
|
||||||
document.addEventListener('keydown', _onKeyDown);
|
document.addEventListener('keydown', _onKeyDown);
|
||||||
|
|||||||
Reference in new issue
Block a user