# how to calculate the destination of camera by giving (x1,y1)

hi all.

how to calculate the destination of camera by giving (x1,y1), to make sure the map center at (x1,y1),

the height attribute using current height of the camera, the orientation of the camera are fixed.

``````               viewer.camera.setView( {
destination : Cesium.Cartesian3.fromDegrees(x,y,120000),//how to calculate by x1, y1
orientation: {//fixed
roll : 0.0
}
});
``````

Hi,

What is (x1, y1)? Are they a latitude/longiutude pair? If so, you can just use Cesium.Cartesian3.fromDegrees like you do in your example. There are many function to create a Cartesian depending on what (x1, y1) are, see the Cartesian3 docs.

Thanks,

Gabby

thank you gabby.
maybe I didn’t describe my question clearly.
for example, I want the globe center on (116, 40), how can I calculate the position of the camera.
the height is the current height of camera, and orientation of camera is fixed.

``````    viewer.camera.setView( {
//how to calculate x,y to make sure globe center on (116, 40)
destination : Cesium.Cartesian3.fromDegrees(x,y,120000),
orientation: {//fixed
roll : 0.0
}
});
``````

I want a formula, because I need to change the position by user click data list.

Hello,

When you set the view to a location, it should center on that point. You don’t have to set the camera position. I don’t understand what the problem is you’re running into here, can you be more specific?

Thanks,

Gabby

thank you, gabby.

you said: ‘When you set the view to a location, it should center on that point’
when the orientation–pitch attribute of the camera is -90, this is right. (left part of the picture)

but my question is the right part of the picture, the camera was not perpendicular to the ground，I thouht a formula

var distance = viewer.camera.positionCartographic.height/Math.abs(tan(40));
var degree = distance / (2 * Math.PI * 6378137.0) * 360;

I think the distance should be latitude, but my test was lost.

thank you, gabby.

you said: ‘When you set the view to a location, it should center on that point’
when the orientation–pitch attribute of the camera is -90, this is right. (left part of the picture)

but my question is the right part of the picture, the camera was not perpendicular to the ground，I thouht a formula

var distance = viewer.camera.positionCartographic.height/Math.abs(tan(40));
var degree = distance / (2 * Math.PI * 6378137.0) * 360;

I think the distance should be latitude, but my test was lost.

Try using Camera.lookAt instead. The target would be the position you want to center on, and you can adjust the offset to your needs.

I’m sorry, this forum is specifically about Cesium, so I can’t provide you with the formula. Try asking on another relevant forum.

Thanks,

Gabby

thank you for your patiention and friendly, gabby.

I used this method before, maybe my parameter was not appropriate, I was success just now, thank you very much.

thank you for your patiention and friendly, gabby.

I used this method before, maybe my parameter was not appropriate, I was success just now, thank you very much.