Skip to content

Commit

Permalink
Change EntityDescription timeout to an interval (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning authored May 31, 2023
1 parent e5cdc93 commit bdf8108
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/EntityDescription/EntityDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,39 @@ const EntityDescription: FC<EntityDescriptionProps> = ({
const parent = frame?.contentDocument?.querySelector(".cesium-infoBox-description");
if (!frame || !parent) return;

let timeout: number | undefined;
let interval: number | undefined;

if (selected) {
// auto resize
if (resizeInfoBox) {
const height = parent.getBoundingClientRect().height;
frame.style.height = height + "px";

timeout = window.setTimeout(() => {
interval = window.setInterval(() => {
// wait for infobox to become visible.
const node = viewer.infoBox.container
.querySelector(
".cesium-infoBox.cesium-infoBox-bodyless.cesium-infoBox-visible");

if (!node) return;

// clear the interval, the following code only happens once.
clearInterval(interval)
interval = undefined

// append the description content to infoBox.
parent.appendChild(c);

// remove cesium-infoBox-bodyless class
viewer.infoBox.container
.querySelector(".cesium-infoBox.cesium-infoBox-bodyless")
?.classList.remove("cesium-infoBox-bodyless");
node.classList.remove("cesium-infoBox-bodyless");
frame.style.height = parent.getBoundingClientRect().height + "px";
}, 10);
}
} else if (c.parentElement === parent) {
parent.removeChild(c);
}

return timeout ? () => clearTimeout(timeout) : undefined;
return interval ? () => clearTimeout(interval) : undefined;
}, [c, container, resizeInfoBox, selected, viewer]);

return c ? createPortal(!container || selected ? children : null, c) : null;
Expand Down

0 comments on commit bdf8108

Please sign in to comment.