# Camera height in 2D

**URL:** <https://community.cesium.com/t/camera-height-in-2d/1004>\
**Category:** CesiumJS\
**Created:** [February 18, 2014, 2:18am UTC](https://community.cesium.com/t/camera-height-in-2d/1004 "2014-02-18T02:18:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaoyuncheng.happy](https://avatars.discourse-cdn.com/v4/letter/g/8baadc/32.png) [@gaoyuncheng.happy](https://community.cesium.com/u/gaoyuncheng.happy)\
**Post date:** [February 18, 2014, 2:18am UTC](https://community.cesium.com/t/camera-height-in-2d/1004/1 "2014-02-18T02:18:45Z")

</div>

How can I get the camera height in 2D mode?

I try to use  
var height = ellipsoie.cartesianToCartographic(scene.getCamera().position).height;  
to get the camera height.

In 3D mode,it works well.But in 2D mode,the value of height remains the same.

---

<div class="post-metadata">

**Author:** ![Matt\_Amato](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/matt_amato/32/1993_2.png) [@Matt\_Amato](https://community.cesium.com/u/Matt_Amato)\
**Post date:** [February 18, 2014, 2:25am UTC](https://community.cesium.com/t/camera-height-in-2d/1004/2 "2014-02-18T02:25:40Z")

</div>

You can use “positionWC” to get the camera in world coordinates, regardless of SceneMode. So your code would like like

var height = ellipsoid.cartesianToCartographic(scene.getCamera().positionWC).height;

The reason position is not what you expect in 2D is because the primary camera properties are SceneMode/ReferenceFrame/projection dependant.

---

<div class="post-metadata">

**Author:** ![gaoyuncheng.happy](https://avatars.discourse-cdn.com/v4/letter/g/8baadc/32.png) [@gaoyuncheng.happy](https://community.cesium.com/u/gaoyuncheng.happy)\
**Post date:** [February 18, 2014, 3:03am UTC](https://community.cesium.com/t/camera-height-in-2d/1004/3 "2014-02-18T03:03:39Z")

</div>

thanks for your reply,Matthew.I follow you to change position to positionWC,but in 2D mode, when I zoom in to get closer to ground, the value of height still remains the same.

---

<div class="post-metadata">

**Author:** ![Matt\_Amato](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/matt_amato/32/1993_2.png) [@Matt\_Amato](https://community.cesium.com/u/Matt_Amato)\
**Post date:** [February 18, 2014, 3:09am UTC](https://community.cesium.com/t/camera-height-in-2d/1004/4 "2014-02-18T03:09:43Z")

</div>

Sorry to hear that didn’t work, I’ll have to ask around to see why that’s the case. In the mean time, you can try the below line of code, which is 2D-specific. So check the SceneMode before using it. height will be in meters.

var height = camera.frustum.right - camera.frustum.left;

---

<div class="post-metadata">

**Author:** ![gaoyuncheng.happy](https://avatars.discourse-cdn.com/v4/letter/g/8baadc/32.png) [@gaoyuncheng.happy](https://community.cesium.com/u/gaoyuncheng.happy)\
**Post date:** [February 18, 2014, 3:20am UTC](https://community.cesium.com/t/camera-height-in-2d/1004/5 "2014-02-18T03:20:37Z")

</div>

thanks very much.

---

<div class="post-metadata">

**Author:** ![vrcraze2010](https://avatars.discourse-cdn.com/v4/letter/v/ac8455/32.png) [@vrcraze2010](https://community.cesium.com/u/vrcraze2010)\
**Post date:** [February 18, 2014, 5:25am UTC](https://community.cesium.com/t/camera-height-in-2d/1004/6 "2014-02-18T05:25:17Z")

</div>

hi Matthew, I guess that the value of camera's height above ground should be:

var height = (camera.frustum.right - camera.frustum.left) \* 0.5 , since I found following code in UniformState.prototype.update(context, frameState){  
...  
this.\_frustum2DWidth = camera.frustum.right - camera.frustum.left;  
this.\_eyeHeight2D.x = this.\_frustum2DWidth \* 0.5;  
...  
}, and following annotation in UniformState.js:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// In 2D, the camera height is always 12.7 million meters.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// The apparent height is equal to half the frustum width.

Can't sure if that is correct, and wonder why change frustum instead of change camera position? And why the camera height is always 12.7 million meters ? Just a few explanation could help me understand, thanks!

在 2014年2月18日星期二UTC+8上午11时09分43秒，Matthew Amato写道：

---

<div class="post-metadata">

**Author:** ![Ellen\_Beck](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@Ellen\_Beck](https://community.cesium.com/u/Ellen_Beck)\
**Post date:** [February 18, 2014, 4:10pm UTC](https://community.cesium.com/t/camera-height-in-2d/1004/7 "2014-02-18T16:10:15Z")

</div>

This works pretty good. How do I get camera height for Columbus View?

---

<div class="post-metadata">

**Author:** ![Dan\_Bagnell](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@Dan\_Bagnell](https://community.cesium.com/u/Dan_Bagnell)\
**Post date:** [February 18, 2014, 10:50pm UTC](https://community.cesium.com/t/camera-height-in-2d/1004/8 "2014-02-18T22:50:58Z")

</div>

The camera height is dependent on the scene mode.

For 3D:

var height = ellipsoid.cartesianToCartographic(camera.position).height;

For Columbus View:

```
var height = camera.position.z;

```

For 2D:

```
var height = (camera.frustum.right - camera.frustum.left) * 0.5;

```

The reason the camera is zoomed using the frustum instead of decreasing the distance in 2D is because of the nature of orthographic projection (as opposed to perspective projection used for 3D and Columbus view). If you’re interested, see the page on [projections](http://en.wikipedia.org/wiki/Graphical_projection) on Wikipedia for more information.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Ellen\_Beck](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@Ellen\_Beck](https://community.cesium.com/u/Ellen_Beck)\
**Post date:** [February 19, 2014, 1:42pm UTC](https://community.cesium.com/t/camera-height-in-2d/1004/9 "2014-02-19T13:42:25Z")

</div>

Thanks Daniel. That’s exactly what I needed!!
