Select to view content in your preferred language

The camera coordinate system is changing on move.

662
3
04-01-2019 12:48 AM
KennethLindhardt1
Frequent Contributor

Hi I’m stuck here. I need to keep track of my XYZ of the camera, and assign that information to a point later in the script. I found out that the coordinate system seems to change, but not on my point. I need the point to always stay in front of my camera, but when it starts with:

x: 7.654 y: 45.919 Z: 5183 and changes to: x: 852275.0892005145 y: 5767392.023641216 Z: 5223.5517142592, then I’m a little lost in what to do. I could use some help in getting it to keep the prober coordinates on the camera. Thanks.

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>CameraTest</title>

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

<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>

<script>
require([
"esri/Map",
"esri/views/SceneView",
"esri/WebScene",
"esri/layers/GraphicsLayer",
"esri/Graphic",
"esri/core/watchUtils",
],
function(
Map, SceneView, WebScene, GraphicsLayer, Graphic,watchUtils
) {

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

var view = new SceneView({
map: scene,
container: "viewDiv",
camera: {
position: [7.654, 45.919, 5183],
tilt: 80},
padding: {
top: 40
}
});
var graphicsLayer = new GraphicsLayer();
scene.add(graphicsLayer);

cameraX = view.camera.position.x
cameraY = view.camera.position.y

watchUtils.whenTrue(view, "stationary", function() {
var info = "<br> <span> the view center changed. </span> x: " +
view.camera.position.x + " y: " +
view.camera.position.y + " Z: " +
view.camera.position.z ;
displayMessage(info);

});
function displayMessage(info) {
outputMessages.innerHTML += info;
outputMessages.scrollTop = outputMessages.scrollHeight;
}

});
</script>
</head>

<body>
<div id="viewDiv">
<div id="outputMessages"></div>
<div id="titleDiv"></div>

</div>
</body>

</html>
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Kenneth,

  Though you can set the camera using Geographic coordinates like you are, they will be projected to the basemaps coodinate system which is web mercator. You have access to a client side utility called WebMercatorUtils to do the conversion from WKID 102100 (web mercator) back to  WKID 4326 (Geographic).

https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-support-webMercatorUtils...

KennethLindhardt1
Frequent Contributor

Hi Robert, thank you for taking you time to answer, I tried your answer, but I think I did it wrong, it didn’t had the outcome I was expecting. I changed the view.camera.position.x to view.camera.position.longtitude and that seem to fix the issue.

Thank you

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kenneth,

   So do you still have a question?

0 Kudos