I need to know how far camera is looking.

I think of something like:

C.Cartesian3.distance(, C.Cartesian2(C.canvas.width/2, C.canvas.height/2)))

But how to account for terrain?

Thank you.

If you want to get pick position onto a terrain surface use

var ray = Cesium.Cartesian2( viewer.canvas.clientWidth / 2,viewer.canvas.clientHeight / 2));
var pos = scene.globe.pick(ray, scene);


If you want to get pick position onto an Ellipsoid surface use

var pos = Cesium.Cartesian2( viewer.canvas.clientWidth / 2,viewer.canvas.clientHeight / 2));


Then get range using

var CC3 = Cesium.Cartesian3;
var range = CC3.magnitude(CC3.subtract(camera.position,pos,new CC3()));


pickEllipsoid picks ellipsoid regardless of terrain being on or off.

getPickRay will pick terrain if it’s on, otherwise it will pick ellipsoid.

(this all assumes 3D mode)


You’re welcome. Looking at the code I noticed that pickEllipsoid also calls camera.getPickRay. However what it does with the ray is different.

IntersectionTests.rayEllipsoid(ray, ellipsoid);


Yields the distance to the ellipsoid (t.)

Ray.getPoint(ray, t, result);


Determines the end point of the ray if you travel t distance along the ray from its origin in the ray’s direction.

Perhaps there should be a Camera.prototype.pickTerrain modeled after Camera.prototype.pickEllipsoid.

There’s a switch within pickEllipsoid:




So within pickTerrain there could also be a similar switch




Each of these sub functions pick terrain properly for their mode.

-pickTerrain3D would use scene.globe.pick

-Columbus View can have terrain, does scene.globe.pick work in this mode?

-2DMode currently has no terrain option so it would just pick the flat surface.

It seems that 2D is Columbus View with projection switched from Perspective to Orthographic. If you could pitch in 2D mode then terrain in 2D would make sense.