CesiumJS viewer and Webworkers


I am working on a new project that will use CesiumJS to display some ground data. I am new to CesiumJS and things are going good but I have a question about Webworkers: can the CesiumJS viewer (retrieved through new Cesium.Viewer(…)) be accessed from a Webworker? I pass it in a message to the Webworker but I am getting: “DataCloneError: The object could not be cloned.” It appears it can’t be passed but I would like to verify before desisting.

A related question: is there any examples that uses Webworkers? I searched through the Sandcastle ones but did not find one.

I am using CesiumJS 1.56.1 in a Linux Mint system.

Jose Rodriguez

Can you describe a bit what you’re trying to do? Web workers generally don’t have access to the DOM, so passing in the whole Viewer may not be useful since it creates all the canvas/DOM resources.

Are you trying to offload some computation to a worker? A lot of CesiumJS’s internals already do that, such as when creating a lot of geometry. It may be a better strategy to do whatever computation you need on a worker and just pass the result back to the main thread.