Error when Switching Terrain After Loading and Unloading KML in CesiumJS

Description:

I’m developing an application that allows users to toggle between different terrain providers (e.g., createWorldTerrain and EllipsoidTerrainProvider). During the development process, I encountered an issue when switching the terrain provider after loading and unloading a KML file. The following sequence of actions leads to the error:

  1. Initialize the viewer with createWorldTerrain as the terrain provider.
  2. Load a KML file into the viewer.
  3. Unload the KML file from the viewer.
  4. Change the terrain provider to EllipsoidTerrainProvider.

After performing these steps, the following error appears in the console:

cesium.js?v=c3a5bb9c:108503 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_scene')
    at Billboard._updateClamping (cesium.js?v=c3a5bb9c:108503:28)
    at Billboard._updateClamping (cesium.js?v=c3a5bb9c:108499:13)
    at Proxy.<anonymous> (cesium.js?v=c3a5bb9c:109376:27)
    at Event.raiseEvent (cesium.js?v=c3a5bb9c:17660:20)
    at Proxy.set (cesium.js?v=c3a5bb9c:192343:38)
    at Reflect.set (<anonymous>)
    at MutableReactiveHandler.set (vue.js?v=c3a5bb9c:1224:28)
    at Proxy.set (cesium.js?v=c3a5bb9c:219440:36)
    at Reflect.set (<anonymous>)
    at MutableReactiveHandler.set (vue.js?v=c3a5bb9c:1224:28)

Additional Information:

  • This error occurs consistently when following the steps above.
  • The issue does not appear when testing similar code in Cesium Sandcastle, indicating that it might be specific to my local environment or setup.

You can view the code samples in the links below:

Request for Help::

If anyone has encountered a similar issue or has insights into what might be causing this behavior, I would greatly appreciate your assistance. It seems to be related to switching terrain providers after loading and unloading KML files, and I haven’t been able to replicate it in Cesium Sandcastle, so it may be specific to my setup. Any advice or suggestions would be really helpful. Thank you!

Hi there @akirin103,

I am not deeply familiar with vue, but I wonder if the added reactivity by using ref for the Viewer is causing unexpected results.

Thanks,
Gabby

Thank you for pointing out that the ref might be causing the issue. You were absolutely right!

I’ve been managing the Viewer instance with ref without encountering problems before, but this might not have been the best practice.

After switching to shallowRef, which only tracks the reference itself without reacting to changes inside the object, the problem was resolved.

Thanks again for your help!

1 Like