Why does background turn black when removing / adding datasources if requestRenderMode is true, can this be prevented?

1. A concise explanation of the problem you’re experiencing.

The background turns black in this case with Explicit Rendering. After removing and adding Datasources again, I would like to redraw the whole thing so that the data is up to date again.

This event actually only happens when the zoom level is very high.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.


3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

My application contains a lot of external data (ImageryLayer, Datasources) that are often removed and inserted. When fetching a new list with any number of layers (ImageryLayer, Datasources), this should be redrawn at the end. Only at the end in order not to render again permanently.

4. The Cesium version you’re using, your operating system and browser.

cesium: 1.65.0
OS: macOs High Sierra v 10.13.6
Google Chrome: Version 80.0.3987.163

thanks for any help :slightly_smiling_face:

Bildschirmfoto 2020-04-17 um 14.58.49 Bildschirmfoto 2020-04-17 um 14.58.56

Each data source you add should have a readyPromise to tell you when it’s successfully been added to the scene. Have you tried listening for that, and only after that returns true, re-rendering the scene?

thanks for this information. I’ve never tried that.
I have now created and added this.

Cesium.when(customDataSource.readyPromise).then(function(model) {
        console.log('1 ready');

I hope it is correct since I did not find anything in the DataSource documentation about ‘readyPromise’?

Unfortunately, it doesn’t work that way either.

I noticed that this problem is only the case in 2D mode.

When you add a data source it returns a promise, this is documented here:


So what you’d need to do is:

var dataSourcePromise = viewer.dataSources.add(customDataSource2);

Although I’m starting to think this may be an issue specific to the custom data source you’re creating. Here’s a simpler example that calls request render each time this billboard changes.

Have you tried recreating your example without using CustomDataSource to determine if that’s what’s causing the issue?

Thank you for the example.

I created a new sandcastle example with this and render if both are ready, but the problem is still the same.

Recreating would mean to use this: viewer.entities.add for each list element?

That still uses a CustomDataSource. While I haven’t confirmed it, I suspect that may be part of the issue here.

Have you tried adding your entities directly to the viewer and avoiding the custom data source just to confirm this? So instead of:

          position: Cesium.Cartesian3.fromDegrees(lon, lat),
          label: {
            fillColor: Cesium.Color.RED,
            font: '16px sans-serif',
            text: value.toString()

You would do:

          position: Cesium.Cartesian3.fromDegrees(lon, lat),
          label: {
            fillColor: Cesium.Color.RED,
            font: '16px sans-serif',
            text: value.toString()

It works perfectly via the viewer.entities.add. In Link, however, I omitted the removal.

If I have to work with many entity packages (create and remove a lot), is dataSource still state of the art?
Or is there another way?

What I’ve done in the past is simply keep my own set of arrays in my application. So you might have:

var labelEntities = [];
var buildingEntities = []; 
// etc

And then when you add an entity you’d do:

var newEntity = viewer.entities.add({ ... })
labelEntities.push(newEntity);//Or add it to whatever the correct collection is

And if you want to add/remove/show/hide you can iterate over any of these arrays and apply these changes. It’s a little more code but I think it’s just as efficient.