mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
The globe viewer's own double-click tracked a picked entity with a position or zoomed to one without. Layers moving onto the draw port had it re-created one by one (data/stockFollow.js); following is a click in GEV, so the viewer's handler is removed where the viewer is made and every re-creation goes: earthquakes, cyclones, air quality, news, perimeters, drone airspace, ghost maps, places, radio, cables, CCTV, ALPR, launches, bikeshare, Local ADS-B, installations, directions, trails, data packs, annotations, the library's view and local GeoJSON. The Cockpit's own double-click and the draw tool's finishing double-click stay.
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import { toRadians } from '../../geo/vector.js';
|
|
import { cameraOf } from '../../render/rendererOf.js';
|
|
|
|
export function createInteraction({ state, parts, inputFor }) {
|
|
function beginInteraction(viewer) {
|
|
if (state._clickSubscription) return;
|
|
state._clickSubscription = inputFor(viewer).onClick((event) => {
|
|
if (!state._enabled) return;
|
|
const record = resolvePickRecord(event.drawHit);
|
|
if (!record?.reference) return;
|
|
flyToReference(viewer, record.reference);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* What a click's draw hit names: a cable, landing point or reference of
|
|
* this layer's current items, as `{ label, kind, featureId, reference }`,
|
|
* or null.
|
|
*/
|
|
function resolvePickRecord(hit) {
|
|
return parts.rendering.pickInfo(hit);
|
|
}
|
|
|
|
function flyToReference(viewer, reference) {
|
|
if (!viewer || !reference) return;
|
|
const camera = cameraOf(viewer);
|
|
camera.cancelFlight();
|
|
camera.flyTo(
|
|
{ lon: reference.lon, lat: reference.lat, height: 6500 },
|
|
{
|
|
orientation: {
|
|
heading: camera.pose().heading || 0,
|
|
pitch: toRadians(-52),
|
|
roll: 0,
|
|
},
|
|
durationS: 1.35,
|
|
easing: 'cubicInOut',
|
|
},
|
|
);
|
|
}
|
|
return {
|
|
beginInteraction,
|
|
resolvePickRecord,
|
|
flyToReference,
|
|
};
|
|
}
|