How to get the Geo-coordinates of the screen based on camera view.

Hi,

I want to get the Geo-coordinates of the current view (camera view). i.e. from the below snapshot, the rectangle area is my camera view. I suppose to get the coordinates of the rectangle area points (marked in yellow color in the image). I’ll use those Geo-coordinates as a reference and process it to get the models whose Geo-coordinates are with in the range.

Is there is a API or method to get the Geo-coordinates of the current view. Please do share some example for that.

Thanks in advance!

Not yet supported in Cesium, but this post has a working solution, as long as the sky is not visible on the screen:
https://groups.google.com/forum/#!searchin/cesium-dev/“Screen$20Coordinates”/cesium-dev/jYlLEnyv7lM/C34T1vQfbggJ

The post also has a link to a Github issue for this feature.

Willem

Hi Willem,

Thank you for the reply!

I’ve tried with the work around solution. But it did not work out. The getCamera API’s not a function. I believe it is removed.

function getExtentView(){

  •    var c2 = new Cesium.Cartesian2(0,0);*
    
  •    var leftTop = scene.getCamera().controller.pickEllipsoid(c2, ellipsoid);*
    
  •      *
    
  •    c2 = new Cesium.Cartesian2(scene.getCanvas().width, scene.getCanvas().height);*
    
  •    var rightDown = scene.getCamera().controller.pickEllipsoid(c2, ellipsoid);*
    
  •            *
    
  •    if(leftTop != null && rightDown != null){*
    
  •        leftTop = ellipsoid.cartesianToCartographic(leftTop);*
    
  •        rightDown = ellipsoid.cartesianToCartographic(rightDown);*
    
  •        return new Cesium.Extent(leftTop.longitude, rightDown.latitude, rightDown.longitude, leftTop.latitude);*
    
  •    }else{//The sky is visible in 3D*
    
  •        return null;*
    
  •    }*
    
  • }*

``

Can you update the code to support the latest library please.

Thanks in advance.

You can use the new API: scene.camera.pickEllipsoid(), it can be found easily in the documentation (https://cesiumjs.org/Cesium/Build/Documentation/Camera.html?classFilter=camer).
I don’t have a new version that I can copy/paste here.

Hi Willem,

Thanks for the response and sorry for delay in reply.

I’ve modified the code based on your suggestion. It works well, when the sky is not visible. I also want to get the position when the sky is visible.

function getExtentView() {

var cl2 = new Cesium.Cartesian2(0, 0);

var leftTop = viewer.scene.camera.pickEllipsoid(cl2, ellipsoid);

cr2 = new Cesium.Cartesian2(viewer.scene.canvas.width, viewer.scene.canvas.height);

var rightDown = viewer.scene.camera.pickEllipsoid(cr2, ellipsoid);

if (leftTop != null && rightDown != null) {

leftTop = ellipsoid.cartesianToCartographic(leftTop);

rightDown = ellipsoid.cartesianToCartographic(rightDown);

return new Cesium.Rectangle(leftTop.longitude, rightDown.latitude, rightDown.longitude, leftTop.latitude);

} else {//The sky is visible in 3D

console.log(“Sky is visible”);

return null;

}

}

``

I’ve also tried the suggestion given in the post(#871), but no luck :frowning:

Can you please help to sort it out!

Thanks in advance.

Hi,

I’m used the Bresenham algorithm code from the post to get the position, even the sky is visible.

Thanks!