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

1,746 views
Skip to first unread message

Premkumar Jayaseelan

unread,
Sep 15, 2015, 10:34:33 AM9/15/15
to cesium-dev
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!


Willem van der Gugten

unread,
Sep 16, 2015, 1:31:31 AM9/16/15
to cesium-dev
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

Premkumar Jayaseelan

unread,
Sep 17, 2015, 6:11:51 AM9/17/15
to cesium-dev
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.

Willem van der Gugten

unread,
Sep 22, 2015, 3:33:04 AM9/22/15
to cesium-dev
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. 

Premkumar Jayaseelan

unread,
Nov 16, 2015, 2:39:18 AM11/16/15
to cesium-dev
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 :(

Can you please help to sort it out!

Thanks in advance.

Premkumar Jayaseelan

unread,
Nov 16, 2015, 6:07:05 AM11/16/15
to cesium-dev
Hi,

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

Thanks!
Reply all
Reply to author
Forward
0 new messages