Unpredictable visibility of CzmlDataSource

I have a strange issue with toggling the visibility of a CZML data source. I can do an initial load and display of the data via a button press handler without any problems. I store the returned data source and can toggle its visibility off and on using another button handler. However, as soon as I pan or interact with the map, any further toggling of the visibility using the button handlers no longer seems to work.

Breakpoints in the code indicate that the handlers are still working, and I discovered that if I pan or zoom into the map (viewing as a 2D flat plane if that matters), suddenly the data source shows or hides as desired. But this strange behavior only presents if I do some sort of pan/zoom after the initial loading of the data source. requires some sort of map interaction in order to realize the change in visibility of the data source.

To help clarify the steps:

  1. Initialize Cesium using 2D web mercatur projection (map shows fine)
  2. Press show czml button. CzmlDataSource loads (first time pressed) and displays.
  3. Press hide button. CzmlDataSource hides
  4. Repeat steps 2 & 3 n times. CZML Data source shows and hides accordingly
  5. Pan the map or zoom into the map.
  6. Pressing show or hide button appears to do nothing. Panning or zooming the map will automatically refresh to the desired visibility state for the czml data source, but the ability to instantly see the show/hide state is gone. Manipulating the map in some fashion is now required to see any changes in the data source’s show state.

I found either a workaround or a solution to my problem. Initially, I was calling my Cesium.Viewer object’s render method after setting the show property of the czml data source object to true or false. This worked somewhat. I discovered that calling Cesium.Viewer object’s scene.requestRender method yielded consistent results of toggling the data source off/on.

Could someone please elaborate on the proper usage of the render function and why scene.requestRender would need to be called instead?

Hi @bpdavis77,

Did you initialize Cesium with requestRenderMode: true?

You can read more about why that mode exists and the render lifecycle functions in Improving Performance with Explicit Rendering. Also see the relevant sandcastle example.

Thanks. Yes, the requestRenderMode is set to true. Thanks for the examples.

Got it. With request render mode enabled, you’ll need to call scene.requestRender() right after setting properties.

1 Like