# How to switch between 2d and 3d scene mode

**URL:** <https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580>\
**Category:** CesiumJS\
**Created:** [July 26, 2021, 4:07pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580 "2021-07-26T16:07:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuhaoecopia](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yuhaoecopia/32/3476_2.png) [@yuhaoecopia](https://community.cesium.com/u/yuhaoecopia)\
**Post date:** [July 26, 2021, 4:07pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/1 "2021-07-26T16:07:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![janine](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/janine/32/5135_2.png) [@janine](https://community.cesium.com/u/janine)\
**Post date:** [July 26, 2021, 5:17pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/2 "2021-07-26T17:17:43Z")

</div>

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](https://sandcastle.cesium.com/) that demonstrates this issue?

Best,  
Janine

---

<div class="post-metadata">

**Author:** ![yuhaoecopia](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yuhaoecopia/32/3476_2.png) [@yuhaoecopia](https://community.cesium.com/u/yuhaoecopia)\
**Post date:** [July 26, 2021, 5:57pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/3 "2021-07-26T17:57:36Z")

</div>

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 [Ces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YkRkw3f34gG7X7VZ1rzxl/PP81n/nR4eL/EodJkrberWO/Pkn), 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

---

<div class="post-metadata">

**Author:** ![janine](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/janine/32/5135_2.png) [@janine](https://community.cesium.com/u/janine)\
**Post date:** [July 27, 2021, 3:53pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/4 "2021-07-27T15:53:26Z")

</div>

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.](https://sandcastle.cesium.com/#c=nVR/b9o6FP0qFu8PQKKmELp1jKHXEdQG8WOUdB0V0pNJLuDh2FnswMLU7z6bBBFG1W3PCMX2veeee8+1PeMz3gFJ4wA7gmMfFiRm6sbzQEpXrIGjD6gISW81v/XoiPach51TG1JHOvz+yus4b5x1+OVzp/cOa6dv/u3aONGpe08Hu4fGMLmsDW/vg747Tp4eH9T0cbwdJJfWk+1YQ7dbm7ofte8N7Xd64ZMONnQHVwP7QToBW/l6PXCn30fuuD78Oq0NrUvcCzoiuBr8Nxrf3n2qxTdL6yt7/PZ25133k+Tpyzu7s7gbDyM2vlsX38+4+SE9NiRCGwpbiHQ1HLYoq/jzfq9U9PbLjuCKUA5RsYJ+pEAzpAccLHvEWdJEC8IkVHJGYOApKrjDfeoRJaJznzmR0CcJRJ+ot4YXHBQNgGnicwvhNCAmfGZKLc/lY22mNEUZSFC6trRIvE8ZhxENqKIbkJj4fukYNS9B+rFsN41RyhVuRhyxJjqej3uQIo48wItIBDdSAxy/1LhuvK1Z5Uoe+Vw+rtJsTa5pdjshAleUsqyNFaF8pwLhg+XranzhxQFwhZegugzM9GOiCYuWXUxhR0D9VUA9BaSQRcz3LdvjJluqvFWpnKubLlApzQF7K9At88unqpyobDw1dabRxOwN9BaedLrDrmW/fwn5kgKZbqC7/H/Z6n/Nlp2n401JpTTnpbvR6vWpVJrCXJEV4UsoVo6aHQJlUv0ZpFAptKRKGLQPWfxLg1BEypy0EsZVBUHIiAJZncdaeoU9KY8p/6OEYHPd8h/56+Wtl5GIud9E0XJOSo16BR3+l/g6X3Cos6R82USN8Htuey4iH6KLiPg0lqfG5zNqvAKivfMpLPTLcbEFulyppg7G/HPKCyXCJro6oT2Y5kIpEZxanw8daVXzerV8ukHU/zAr/PJmzQrIY0RKbVnEjE3oDmaFdquq/c+gTBDDO9pAxEhi3Fa1dj/dxBi3qnr5MjLTQENylgNvqou2DUZ2F00eHbdz18zHSf3b+TPaojyMVRq8busiOAlAz9NnRq9VEpq1aY2YFaqnYEbmwLT6UYZu1+1Wdb95ZPxzfuv3/Ch7EF7Jw0RpW6/mkZ//BA)

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

---

<div class="post-metadata">

**Author:** ![yuhaoecopia](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/yuhaoecopia/32/3476_2.png) [@yuhaoecopia](https://community.cesium.com/u/yuhaoecopia)\
**Post date:** [July 27, 2021, 6:03pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/5 "2021-07-27T18:03:43Z")

</div>

ok thank you so much for the help!

---

<div class="post-metadata">

**Author:** ![janine](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/janine/32/5135_2.png) [@janine](https://community.cesium.com/u/janine)\
**Post date:** [July 27, 2021, 8:32pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/6 "2021-07-27T20:32:26Z")

</div>

Hi @yuhaoecopia,

I think the [`pickEllipsoid` function](https://cesium.com/learn/cesiumjs/ref-doc/Camera.html#pickEllipsoid) 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`](https://cesium.com/learn/cesiumjs/ref-doc/Camera.html#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

---

<div class="post-metadata">

**Author:** ![basant1431](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/basant1431/32/3476_2.png) [@basant1431](https://community.cesium.com/u/basant1431)\
**Post date:** [June 20, 2022, 10:30am UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/7 "2022-06-20T10:30:37Z")

</div>

Hi janine, I have also implemented switch functionality in my application and it’s working fine. The issue is, When I am switching from 3d to 2d then buildings are displacing from their original location. Can you help me to solve this issue?

Thank you

---

<div class="post-metadata">

**Author:** ![janine](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/janine/32/5135_2.png) [@janine](https://community.cesium.com/u/janine)\
**Post date:** [June 21, 2022, 1:29pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/8 "2022-06-21T13:29:41Z")

</div>

Hi @basant1431,

This is a known limitation with 2D mode – models are not accurately projected to 2D and will show up displaced from the original locations. However, we recently added an option to `ModelExperimental` to load things in 2D with accurate positions.

When creating a `Cesium3DTileset`, make sure to include these options in the constructor:

```auto
const tileset = new Cesium.Cesium3DTileset({
  url: // url here,
  enableModelExperimental: true,
  projectTo2D: true
});
viewer.scene.primitives.add(tileset);

```

Then, whenever the mode is switched to 2D / Columbus View, its positions should be properly projected. You can also see the links on Github below for more info. Let me know if you have any questions!

> <https://github.com/CesiumGS/cesium/pull/10384>
>
> This PR adds 2D / CV projection to \`ModelExperimental\` with the \`projectTo2D\` op…tion. This option is always set to true by tilesets, and it projects the positions more accurately than the old \`Model\` class. Here's a preview of the results:
> 
> | \`Model\` | \`ModelExperimental\` |
> | -------- | ----------------------- |
> | !\[image\](https://user-images.githubusercontent.com/32226860/168660741-9409668e-ce8f-464e-a36d-76b192bdebff.png) | !\[image\](https://user-images.githubusercontent.com/32226860/168660787-03bd6ed9-38cb-41cb-9dba-099ef12c0cfe.png) |
> 
> \*\*TODO:\*\*
> \- \[x\] Add an option to the \`ModelExperimental\` constructor to enable accurate projections. This will default to false for models loaded in with \`fromGltf\`, but should always be true for models loaded in from a tileset.
> - \[x\] Decide on a name for this -\> \`enableProjection2D\`? \`projectTo2D\`?
> - \[x\] This should control whether or not the vertex arrays should be loaded in.
> \- \[\] ~Add old \`Model\` projection code to \`ModelExperimental\` for models that aren't associated with a tileset. This allows models to show up in 2D / CV mode without breaking from options like \`minimumPixelSize\`~ -- will be done in a separate PR
> \- \[x\] Figure out lighting difference with \`ModelExperimental\` (only happens in 2D/CV)
> \- \[\] ~Fix instancing errors -- current method doesn't support instancing~ -- save for another PR
> \- \[x\] Unit tests
> 
> This is related to #9934, but the issue shouldn't be closed until \`ModelExperimental\` gets the old \`Model\` projection code for individual models (will be a separate PR).

> <https://github.com/CesiumGS/cesium/pull/10440>
>
> This is a similar adjustment to #10344. Accurate 2D projection requires extra me…mory, and we don't want it to tax the performance of users who will only ever use 3D. Therefore, we're adding a \`projectTo2D\` option in \`Cesium3DTileset\`. Similar to \`enableDebugWireframe\`, only the users who need it can opt-in and use the accurate 2D projection.
> 
> \[Sandcastle\](http://localhost:8080/Apps/Sandcastle/index.html#c=bVLva9swEP1XRD45kErp0jLI0rA2KSzQrqVJWwaGIUsXW5ssGemcLB373yf5R2i3frLv9N7Te3dijFzVSktlciI5ciJs7RD8gdgt+fptQe4qMMt4UFmHXE9JgVhNGdvv96fUHATN7Y55hcCkVYhMGYWKo9qBZxN5knXitOI5pEZY45HsFOzBkQtiYE8W4FVd0qeml6QD0dQLa5ArAy4djMjv1BCC4Fzo3Du7UxLctCcKBxzh2TotNy0kGY4iwQswcGslHKHrvkMXdzePt1eP6+9Pq+vn1PwZfkpNalpftCHSXNsMqIQKiw14vMyDssfuiuAdXQ0Nq82ESoMHfBuq/UyWm/YwaYLUTh8drax5AB9GLoBunS0vfYCtZPLxfHI2aWOA4ZluXOvrXxU4VYJpFhENNIjK2R8gcGM/LNtuF+hNnCoQVbMWyqVMOrtt7q6gYZLyEAZcKg8UCzDJtjYClTUkGbZb6DRfrC03Nokd0kcftdWr+F+CXtj9vUJRPHCTQ0cgZEzHo/7/ZEzPj0VvJbO1idx1VYAD6oJQ7QkjZ3TcQofxE+03UQejwczjQcO8F/qsyvhi47QTShlCWenwTjzLavEzXCC8j8QInbHX1JlUO6LkxTsvkQjNvQ8n21rrtXqBdDCfsYD/j6ptk/xuB07zQ4QVp/ObtkkpnbFQvs9Ea3XG3T/KfwE) for testing (comment / uncomment the \`projectTo2D\` option to see the difference)

---

<div class="post-metadata">

**Author:** ![basant1431](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/basant1431/32/3476_2.png) [@basant1431](https://community.cesium.com/u/basant1431)\
**Post date:** [June 21, 2022, 7:11pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/9 "2022-06-21T19:11:39Z")

</div>

Hi @janine,

Thanks you for your quick reply. As per your suggestion I added both mentioned options in my tileset and tried it in my application but when I am adding both options in tileset buildings are getting disappeared. My application is not laoding any building on at map. I have added code below, please have a look and let me know what wrong I am doing.

> var tileset = viewer.scene.primitives.add(  
> new Cesium.Cesium3DTileset({  
> url:‘./3DTilesData/300Build/tileset/tileset.json’,  
> picking:false,  
> maximumScreenSpaceError:512,  
> maximumMemoryUsage:1024,  
> skipLevelOfDetail:true,  
> preferLeaves:true,
> 
> ```
> dynamicScreenSpaceError : true,
> dynamicScreenSpaceErrorDensity : 0.00278,
> dynamicScreenSpaceErrorFactor : 4.0,
> dynamicScreenSpaceErrorHeightFalloff : 0.25,
> enableModelExperimental:true,
> projectTo2D:true
> })
> );
> 
> ```

Also attached screenshot of map below for your reference.

 ![AfterAddingoptions.PNG](https://global.discourse-cdn.com/cesium/original/3X/5/8/58375f5afb53d91d984196d5dd7550148a724a57.jpeg)  
 ![beforeaddingoptions.PNG](https://global.discourse-cdn.com/cesium/original/2X/0/095af7067c06b4a89b011133d543fd118839ce9a.jpeg)

Thank you

---

<div class="post-metadata">

**Author:** ![basant1431](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/basant1431/32/3476_2.png) [@basant1431](https://community.cesium.com/u/basant1431)\
**Post date:** [June 21, 2022, 7:13pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/10 "2022-06-21T19:13:02Z")

</div>

The first screenshot is after adding options that you have mentioned. second is before adding options.

---

<div class="post-metadata">

**Author:** ![janine](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/janine/32/5135_2.png) [@janine](https://community.cesium.com/u/janine)\
**Post date:** [June 23, 2022, 2:13pm UTC](https://community.cesium.com/t/how-to-switch-between-2d-and-3d-scene-mode/14580/11 "2022-06-23T14:13:40Z")

</div>

Hi @basant1431,

From a glance, I don’t see anything wrong with your code, so I wonder if this is related to the bug here:

> <https://github.com/CesiumGS/cesium/issues/10402>
>
> \#10384 added support for 2D / CV mode with tilesets that used \`ModelExperimental…\`, and this produces good results for the OSM buildings in New York. However, the models don't show up for some cities, e.g. Tokyo and Sydney. Here's a \[localhost Sandcastle\](http://localhost:8080/Apps/Sandcastle/index.html#c=fVLLbtswEPyVhU8SoNJOjSRtqhiFld4apKgN96ILTa4tohRX4MOuW+TfS0qxkTROTxKHM7PD3RVknIedwj1auAWDe6jQqdCyVY9l9Uj054qM58qgrUcF/KkNgEdrI/LN0k5JtDdHobDIPf4gq+VyoGR5bR7zT7WpzVCJOYEGWWdVq7zaoWNcyuyF/sG186C0VGbrsr6exHXYLhrazymYhK9IhxZvwNuARWKg4WuN9yRRf/nVYXTHGFoPjBThTAbBW7ScbfRhScc6zivDvSJzelPFrY9/3EzZxlJ7h1uL6LKL6Ud29aGA6SW7ui7g+nKS90HIqlR5sOhNARrkKfTJ8p77hnn6HlFuXPb+SQrQKS+at2jvjrzH4tTTBTdScOc1pjYuabvVOA/ek4nTG45QrdLcNlw7jJ9gRMoGWXISDYqfKGuTD1HVJnuC8mP2Fx1ryXbNkqrU/XVwaU+yCZukLDEWYCzxP9307hm7f8OoGJXOHzTOBhXAZ9V2ZD0EqzPGxh7bTsedcON1iLk8E84NBgDl+Lm0lGoHSt6e2VoQmjsXbzZB64X6jfVoVo4j/5VUUz+phx1azQ+J1lzMvg4gY6wcx+N5pSfSa27/cf4L) that shows this behavior for Tokyo.
> 
> This may have more to do with the tile bounding volumes in 2D, rather than the projection of the models themselves.

In short, we think there is a bug with the system that determines whether or not to render tiles in 2D / CV, and this may be affected by it. I’ll make a note of your post in the Github issue so we can keep track of the problem.
