Getting Camera Position in 2D

1. A concise explanation of the problem you're experiencing.
2D mode seems to provide a significantly different camera position that 3D mode does at the same location.

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
Sandcastle link: https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=dVLbbtNAEP2VITzEFdZGiLfgRoWoQEUQCFs8WULb9aRdsd41e3HrRPl3xrfUSYsfbM/tnDOXmluoJT6ghUvQ+ABrdDKU7Ffni+aiM9dGey412nkMe4t/Azr/E3WB9pspcAneBjxcvM91rmsCVNz5H8ZJL40+Ou+5LtQ5TSosok4rLvC6Ru2/9ElRL4k5gRqZ4ATgWvgBgzn0N7oK/oNoKaJt0P3PBexzDfS0hGIUTZSFEaEkfEbSbZOiQuENtff6vL+WZQSohhaoftAjeImWs+qptzHXBE96KHOMsUd4AzSuOX2OvuYF325AIbnOKGTK3EU92qhlOk5i2MPjckITQzMxmxh2E3MHhwEk14f4f1PPmgrZ5vpT9nu9uVl/7ReZ65SmLYibRPGiyIxRt9x+DN7TpOefDWQGNhSGjRG8ZaPOnm9CbiF6Ne3gGGkfiz7YcY6Hye649aSV69NzWY/ud9EUsh3Cid2c2bvjWk/2uFVNZqJ9QdcsddfC8om5u2d6zeJZ4nyjcNVDXMmyMtZDsCpibOGxrBSnksVtEH/QM+G6U00WY1FSyBpkcZnPzo4tn4EgmY4i26BUKneYz1bJgvJPypThhdR332u0ijdtyv3b1aZ3MsaSBZnPq3y/rwniPw

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
In our application we have the capability to save the current camera location with a name so that the user can quickly return to that location. The problem is though, that the camera position in 2D mode seems to be incorrect.

The SandCastle example I setup demonstrates what I am talking about. In it:

(In 3D mode)
1. Zoom into a location (I chose Lake Okeechobee in south Florida).
2. Click the Viewer. If you watch the console, it will console log the viewer.camera.position.
3. Click the Home button to go back to the default
4. Click the Go To Last Location button

It should return you to the same location that you were at when you clicked to set the position.

Next..
1. Click Home to return to the default view
2. Switch to 2D mode
3. Click the Go To Last Location

It should return to the correct location again

Finally
1. Click the Viewer again to save that location
2. Click Go To Last Location

Seeing as how the position that is being saved is being pulled from the camera position, I would have expected the position from the second click to be the same as the first click, especially since I had just gotten Cesium to navigate to that location from before. However, if you look at the console, the values are vastly different and, in my example, instead of taking me to Lake Okeechobee again, it took me over to the edge of the Bearing Sea.

Is this the correct behavior? Is there something else I'm supposed to be doing that I'm unaware of to correctly get that camera position in 2D mode and have it match what I did in 3D mode?

4. The Cesium version you're using, your operating system and browser.
Tested this in 1.54 in Cesium sandcastle in the latest version of Google Chrome on macOS 10.14.2 on a 2018 MacBook Pro.

Any help you could provide would be greatly appreciated.

Thanks for the well made Sandcastle!

I think the problem is that the coordinates of the camera are always stored as a 3D position. So going to the correct 2D area in 2D would involve doing the projection yourself.

An easier way to do this might be to just use the camera’s computeViewRectangle when in 2D mode. I’ve modified the Sandcastle to do this so it now works for any locations stored in a given mode, but not for going to locations across modes.

Aw man, thank you so much! I knew there had to be something I was missing or not doing right.