Carry the Nepal event images, playback and media across globes

This commit is contained in:
German Khokhlov committed 2026-11-03 03:57:18 +04:00
1 parent 811bcaff85
commit 4e09559337
19 files changed
+426 -84

No files matched your search

+22 -11
View File
@@ -538,9 +538,10 @@ function ensureProviderConnections(documentRef, provider) {
}
}
function anchorOnScreen(viewer, anchor, root) {
if (!viewer?.scene || !anchor || !root) return null;
const camera = viewer.camera;
function anchorOnScreen(viewer, engine, anchor, root) {
if ((!viewer?.scene && !engine) || !anchor || !root) return null;
const camera = viewer?.camera;
if (engine && !engine.projector.horizonVisible(anchor)) return null;
if (camera?.positionWC && camera?.directionWC) {
const delta = Cesium.Cartesian3.subtract(
anchor,
@@ -549,12 +550,12 @@ function anchorOnScreen(viewer, anchor, root) {
);
if (Cesium.Cartesian3.dot(delta, camera.directionWC) <= 0) return null;
}
const pixel = Cesium.SceneTransforms.worldToWindowCoordinates(
const pixel = engine ? engine.projector.worldToWindow(anchor, {}) : Cesium.SceneTransforms.worldToWindowCoordinates(
viewer.scene,
anchor,
);
if (!pixel) return null;
const canvasBounds = viewer.canvas?.getBoundingClientRect?.();
const canvasBounds = (engine?.host.canvas ?? viewer?.canvas)?.getBoundingClientRect?.();
const rootBounds = root.getBoundingClientRect?.();
if (!canvasBounds || !rootBounds) return null;
const x = pixel.x + canvasBounds.left - rootBounds.left;
@@ -637,7 +638,7 @@ function createRoot(documentRef, viewer) {
const root = documentRef.createElement('div');
root.id = 'bhote-koshi-embedded-media-root';
root.setAttribute('aria-live', 'polite');
(viewer?.container || documentRef.body)?.append(root);
(documentRef.getElementById?.('cesiumContainer') || viewer?.container || documentRef.body)?.append(root);
return root;
}
@@ -648,6 +649,7 @@ function createRoot(documentRef, viewer) {
*/
export function createBhoteKoshiEmbeddedMedia({
viewer,
engine = null,
documentRef = globalThis.document,
globalRef = globalThis,
xLoader = loadXWidgets,
@@ -660,7 +662,7 @@ export function createBhoteKoshiEmbeddedMedia({
const pinokioShell = /(?:^|\s)Pinokio\/[^\s]+/i.test(
globalRef.navigator?.userAgent || '',
);
if (pinokioShell || !documentRef?.createElement || !viewer) {
if (pinokioShell || !documentRef?.createElement || (!viewer && !engine)) {
return {
supportsPlayback: false,
warm: () => false,
@@ -671,7 +673,7 @@ export function createBhoteKoshiEmbeddedMedia({
destroy: () => {},
};
}
const root = createRoot(documentRef, viewer);
const root = createRoot(documentRef, engine?.host ?? viewer);
let record = null;
let warmRecord = null;
let generation = 0;
@@ -848,7 +850,7 @@ export function createBhoteKoshiEmbeddedMedia({
const position = () => {
if (!record) return;
const projected = anchorOnScreen(viewer, record.anchor, root);
const projected = anchorOnScreen(viewer, engine, record.anchor, root);
record.card.hidden = !projected;
if (projected) {
placeCard(record.card, record.leader, projected);
@@ -864,8 +866,16 @@ export function createBhoteKoshiEmbeddedMedia({
}
}
};
const removePostRender =
viewer.scene?.postRender?.addEventListener?.(position);
let removePostRender;
function attachScene(nextViewer, nextEngine) {
removePostRender?.();
viewer = nextViewer;
engine = nextEngine;
const frames = engine?.frames.postRender ?? viewer?.scene?.postRender;
removePostRender = frames?.addEventListener?.(position);
position();
}
attachScene(viewer, engine);
function hide({ immediate = false, preserveWarm = false } = {}) {
if (!preserveWarm) clearWarm();
@@ -1223,6 +1233,7 @@ export function createBhoteKoshiEmbeddedMedia({
}
return {
attachScene,
supportsPlayback: true,
warm,
show,