Identify if any tiliesets are visible/rendered in the viewer

Hi,

I am trying to determine programmatically if tilesets are rendered (and visible) in the viewer.

I often load many tilesets into the viewer and set the initial camera view to fly to a boundingSphere that encompasses the entire extent of the tilesets. This generally works well, but when I have a large number of tilesets covering a vast area, the camera sometimes positions so far away that the viewer appears blank because no tiles are rendered.

Is there a way to inspect the tilesets to check if any are visible? I would like to use this to determine if I could then zoom the camera in until I identify that tiles are rendered on the screen. Any advice or suggestions would be appreciated.

Hi @spinksy,

Have you looked at the tileLoad and allTilesLoaded events? These will give you some indication of whether any tiles were loaded.

A somewhat messier trick is to check the length of the tileset._selectedTiles array. Please note that ._selectedTiles is not part of the public API so it is not a stable solution.

Detecting visibility may be tricky for client applications. (Internally, the visibility detection is done all the time - the question is how the relevant information can be obtained by the client).

One … workaround … for determining whether any tile is visible “in the current frame” might be something like

let anyTileIsVisible = false;

viewer.scene.preRender.addEventListener(function () {
    anyTileIsVisible = false;
});
tileset.tileVisible.addEventListener(function (tile) {
    console.log("There is one: "+tile);
    anyTileIsVisible = true;
});
viewer.scene.postRender.addEventListener(function () {
    if (anyTileIsVisible) {
        console.log("Hey, there was a tile visible in this frame!");
    }
});

It looks a bit quirky. Maybe @jjhembd can say whether this might be a viable solution here, or whether it is fundamentally flawed in some way.