cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Scene ready event

Open hpinkos opened this issue 8 years ago • 4 comments

This is something frequently requested on the forum. Users would like an event that is fired when the scene is fully loaded.

https://groups.google.com/forum/?hl=en#!topic/cesium-dev/FTHsjxL8rS4

hpinkos avatar Oct 12 '16 14:10 hpinkos

We have a bit of a start for this but its just for 3D Tiles at the moment: https://github.com/AnalyticalGraphicsInc/cesium/pull/4405.

lilleyse avatar Oct 12 '16 15:10 lilleyse

Yes, this would be great!

billwritescode avatar Nov 16 '16 23:11 billwritescode

Agreed this would be very useful!

adunham1962 avatar Nov 17 '16 21:11 adunham1962

FYI, some of our apps use the below logic to detect this. We can probably tweak the code and have it work out of the box in CesiumJS. The main issue is that there is primitive-level way to detect if the primitive is "done" so we have to specifically track and check 3D Tiles tilesets. It would be easier to have a clearly defined Primitive API to make this easy to do.

const viewer = this._viewer;
const tilesets = this._tilesetCollection;
const surface = viewer.scene.globe._surface;

//A rather obtuse check to see if Entity geometry is complete. (CZML/KML/GeoJSON)
const entitiesComplete = viewer.clockViewModel.canAnimate;

let complete =
  entitiesComplete &&
  viewer.scene.globe.tilesLoaded &&
  surface._debug.tilesWaitingForChildren === 0 &&
  RequestScheduler.statistics.numberOfActiveRequests === 0;

//If not, check all of the 3D tilesets.
if (complete) {
  const length = tilesets.length;
  for (let i = 0; i < length; i++) {
    const tileset = tilesets.get(i);
    complete = tileset.tilesLoaded;
    if (!complete) {
      break;
    }
  }
}

mramato avatar Sep 21 '22 01:09 mramato

A related request same in at https://community.cesium.com/t/events-to-track-bulk-polygon-loading-triangulation-complete/25944 specifically for geometry. I provided workaround (below). The same data that drives canAnimate can also support a viewer level property for indicating geometry completeness. (But this only works for the entity API)

await new Promise((resolve) => {
  const removeEvent = viewer.scene.postRender.addEventListener(() => {
    if (viewer.clockViewModel.canAnimate) {
      removeEvent();
      resolve();
    }
  });
});

mramato avatar Aug 07 '23 16:08 mramato