Select to view content in your preferred language

How to set both camera and center positions in SceneView

2087
4
06-15-2017 11:23 AM
ChristianMorin
New Contributor III

I’ve been scratching my head trying to figure out how to set both the camera position and the center position simultaneously in 3D. I’m used to being able to do just that in Three.js, but it seems when I try to set both positions in the Arcgis JavaScript API the result is never what I expect.

I tried to do it by using the goTo method and it didn’t work. I tried doing it by setting the camera and center property on the view, but that also didn’t work. The result is always that the camera or the center is correct, but not the other.

Anybody knows how to do it? How to have both the camera and center be at specific desired positions?

Cheers,

Christian.

0 Kudos
4 Replies
ThomasSolow
Regular Contributor

I think, in general, the center and camera properties are going to conflict with one another. 

My recollection is that setting the center (or extent) or a sceneview may change the position of the camera, but it won't change the tilt and heading of the camera.  It may be that you're expecting to be able to set the position of the camera and then set the center in order to rotate the camera so that it's facing the new center.

To get something close to this behavior, you could try something like this:

// maintain current position of camera, but set the center
// to something new
view.on('click', e => {
  view.goTo({
    target: e.mapPoint,
    position: view.camera.position
  });
});‍‍‍‍‍‍

I might be misunderstanding the behavior you're after though.

0 Kudos
ChristianMorin
New Contributor III

Hi Thomas,

     Thanks for the prompt response. This does work if I want to change the center and keep the camera in the same position. So that's half my problem. I also want to be able to keep the same center but change the location of the camera. I tried using the pattern you described above, but it doesn't work for that case. Do you have an idea of how I can change the position of the camera keeping it looking at the same center?

Cheers,
Christian. 

0 Kudos
ThomasSolow
Regular Contributor

What you're describing is more or less the behavior when you hold down right mouse button and move the mouse.

You might try something like this:

view.on('click', e => {
  // the map point will be an x/y point on the earth's
  // surface.  to fix this, just maintain the current z
  // of the camera
  e.mapPoint.hasZ = true;
  e.mapPoint.z = view.camera.position.z;
  view.goTo({
    target: view.center,
    position: e.mapPoint
  });
});‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
ChristianMorin
New Contributor III

Hi Thomas,

    I still not working quite right for me. I'm also using a local scene, not a globe. I'll work on creating a small sample that outlines what I'm trying to do.

Cheers,

Christian.

0 Kudos