1. A concise explanation of the problem you’re experiencing.
Trying to compute the distance between two Cartesian3 points using Cesium.Cartesian3.distance() but returning NaN
2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.
Sandcastle.addToolbarButton(‘Calculate Distance’, function() {
clickPositions = removeDup(clickPositions); // Removes any duplicate values in the clickPositions array
// Adds an if loop to check there are only two points in the array
if (clickPositions.length = 2) {
var distance = (new Cesium.Cartesian3.fromArray(clickPositions[0]), new Cesium.Cartesian3.fromArray(clickPositions[1]));
console.log("Distance: " + distance);
confirm("First point is: " + clickPositions[0] +
"\nSecond Point is: " + clickPositions[1] +
"\nDistance: " + distance);
} else {
confirm("You have clicked on more than two points");
}
});
[<img src="https://lh3.googleusercontent.com/-yMUc6waTxN8/WX9QksUsxBI/AAAAAAAAA4M/sgHGQJgc6Gc5KF40c6GjcapDFy3vC79hACLcBGAs/s320/Screen%2BShot%2B2017-07-31%2Bat%2B16.43.26.png" border="0" width="320" height="132">](https://lh3.googleusercontent.com/-yMUc6waTxN8/WX9QksUsxBI/AAAAAAAAA4M/sgHGQJgc6Gc5KF40c6GjcapDFy3vC79hACLcBGAs/s1600/Screen%2BShot%2B2017-07-31%2Bat%2B16.43.26.png)
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
Trying to measure the distance between two points, in order to measure the height of a building for example.
4. The Cesium version you’re using, your operating system and browser.
Cesium ver: 1.34, OS: MacOS Sierra, Browser: Chrome
Any help would be appreciated.
Thanks,
Chris