Simple way to get camera position?

2339
8
11-08-2016 06:47 AM
MeganWirth
Occasional Contributor

Is there a simple way to set a scenes camera position? i.e. Lat, long, z, heading, and tilt? I ask because i spend a lot of time trying to set these parameters in the api.

Tags (2)
8 Replies
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   Sure use:

// Clone the camera to modify its properties
var camera = view.camera.clone();

// Set new values for heading and tilt
camera.heading = 180;
camera.tilt = 45;

// Set the new properties on the view's camera
view.camera = camera;
MeganWirth
Occasional Contributor

Thanks for the reply Robert hope all is well with you.

I believe I need to rephrase the question. Is it possible to be able to pan, tilt  and zoom a scene manually and then be able to see the camera parameters so that you can set the camera position values for the camera? Sorry hard to explain ha

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   Ok, now I understand. You can use your browsers developer tools to watch the cameras properties:

Watch variables in Sources  |  Web  |  Google Developers 

MeganWirth
Occasional Contributor

Robert Can you show me a screen grab of this working? Would appreciate it man I have tried and tried to get it to work.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

  Sure here it is:

KenBuja
MVP Esteemed Contributor

The other way to do it is in the code. You can set up watches on different properties

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Get started with SceneView - Create a 3D map - 4.1</title>
  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <link rel="stylesheet" href="https://js.arcgis.com/4.1/esri/css/main.css">
  <script src="https://js.arcgis.com/4.1/"></script>

  <script>
    require([
      "esri/Map",
      "esri/views/SceneView",
      "dojo/domReady!"
    ], function(Map, SceneView) {

      var map = new Map({
        basemap: "streets",
        ground: "world-elevation"
      });

      var view = new SceneView({
        container: "viewDiv",
        map: map,
        scale: 50000000,
        center: [-101.17, 21.78]
      });

      view.watch('camera.tilt', function(newValue, oldValue, property, object) {
          console.log(property , newValue);
      });
    });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>
</html>

Take a look at the Watching Properties section: Working with properties | ArcGIS API for JavaScript 4.1 

MeganWirth
Occasional Contributor

Thank you guys for taking the time to help! appreciate it 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

No problem. Be sure to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos