How to switch between 2d and 3d scene mode

I use viewer.scene.mode = Cesium.SceneMode.SCENE2D to switch from 3d to 2d,
and viewer.scene.mode = Cesium.SceneMode.SCENE3D to switch back. My scene in default is in 3d and I am able to switch to 2d, but not able to switch back afterwards. Any thoughts on this is appreciated!

Hi @yuhaoecopia,

I’d love to help, but I need more information. What does your code overall look like? Can you put together a Sandcastle that demonstrates this issue?

Best,
Janine

Hi Janine,

Thank you so much for the reply. I was able to figure the scene mode issue out myself, but I have another question. As you can see from this sandcastle I made Cesium Sandcastle, the scene initially is in 3d mode and looking at the barrel, but when switch to 2d mode, the camera just looking down on the ground, is there a way to recenter the camera to look on the barrel as well? More generally speaking, is there a way to make camera centerred at the position it was looking at in 3d mode not the position the camera was at?

Best,
Yuhao

Hi @yuhaoecopia,

In your sandcastle, once you switch the viewer.scene.mode you need to add a call to viewer.zoomTo(tileset) to recenter the camera on the barrels. I modified your Sandcastle to do this here.

I’m still experimenting with a general solution, such that the camera can get the position it is looking at and zoom to it when it switches modes, but I haven’t figured one out yet. I will update if I manage to get it to work.

Best,
Janine

ok thank you so much for the help!

Hi @yuhaoecopia,

I think the pickEllipsoid function in the Camera API should work as a general solution. You can call this function to get a Cartesian3 position, then call viewer.camera.lookAt to make the camera to look at that position. You may need to adjust the offset parameter in lookAt so that the barrels are correctly placed on the screen.

Hope that works for you!

Best,
Janine

1 Like