Reputation: 381
when loading kml datasource, I want to display a loading image until 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 visualizedthe issue is the same with
viewer.dataSources.add(datasource).then(function(){ clearLoader(); } )
Please anyone can help Thanks Regards
Upvotes: 8
Views: 3780
Reputation: 1
Update (i.e. Cesium.viewer.dataSources.add()
):
DataSourceCollection:
add(dataSource) → Promise.
Adds a data source to the collection.
...
Returns: A Promise that resolves once the data source has been added to the collection.
(https://cesium.com/docs/cesiumjs-ref-doc/DataSourceCollection.html#add)
Then use the Promise .then()
as described in the other answer.
Upvotes: 0
Reputation: 12448
Try this instead:
viewer.dataSource.add(datasource); // add empty datasource.
datasource.load(url).then(function () { clearLoader(); });
The .add
function returns immediately, even with an empty data source. But the .load
function returns a promise that will resolve once the data source is loaded.
Upvotes: 3