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:

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
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.

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

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.