Waiting for scene to be fully rendered when loading datasources

Hi everyone!
when loading kml datasource, I want to display a loading image untill it can be visualized in the viewer or scene.
I tried to handle:

  • viewer.dataSources.dataSourceAdded event but it is fired very early, that is to say, the loading image disappears before the datasource can be visualized
  • the issue is the same with viewer.dataSources.add(datasource).then(function(){clearLoader();})

Please anyone can help

Add your loading image to your DOM and use the Promise returned by the viewer.dataSources.add method.

We use the “When” library for our promises and you can read about it here:


Hi Mike

I have already done this way:




but the callback is called very early before the scene fully rendered the datasource

I haven’t forgotten. I’m still looking for an event that would trigger at the correct time. I’ll ask the some of the devs if they have any idea. In the mean time hopefully someone in the general community can help.

scene.globe._surface._tileLoadQueue.length == 0 might do it

This code snippet should do what you want. dataSourcesLoaded will become false whenever a data source is being prepared (this includes both loading the data and then creating the geometry). When dataSourcesLoaded is true, you can be sure that all primitives and geometry are being shown in the viewer.

var dataSourcesLoaded = true;
var originalFunction = viewer.dataSourceDisplay.update;

viewer.dataSourceDisplay.update = function(time) {
dataSourcesLoaded = originalFunction.apply(viewer.dataSourceDisplay, [time]);
return dataSourcesLoaded;


Hope that helps.

Hi Mike.thanks I used your principle to adapt my code and it works.


Great to hear… It’s always best when we can figure out solutions that are not using the ‘_’ properties. One never knows when those may change.