Skip to content

Instantly share code, notes, and snippets.

@AlexZeller
Created May 4, 2018 12:46
Show Gist options
  • Select an option

  • Save AlexZeller/1452287607b0d1fad642bc3111bc531d to your computer and use it in GitHub Desktop.

Select an option

Save AlexZeller/1452287607b0d1fad642bc3111bc531d to your computer and use it in GitHub Desktop.
var viewer = new Cesium.Viewer('cesiumContainer');
var screenSpaceEventHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
//Function to add a point
function addPoint(x,y) {
var point = viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(x, y),
point : {
pixelSize : 10,
color : Cesium.Color.YELLOW
}
});
}
screenSpaceEventHandler.setInputAction(function(click) {
var mousePosition = viewer.camera.pickEllipsoid(click.position);
var cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(mousePosition);
var ray = viewer.camera.getPickRay(click.position);
var position = viewer.scene.globe.pick(ray, viewer.scene, position);
var cartographic2 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
var x2 = Cesium.Math.toDegrees(cartographic2.longitude);
var y2 = Cesium.Math.toDegrees(cartographic2.latitude);
addPoint(x2,y2);
console.log(x2, y2, cartographic2.height);
console.log(y2);
console.log(cartographic2.height);
var x = Cesium.Math.toDegrees(cartographic.longitude);
var y = Cesium.Math.toDegrees(cartographic.latitude);
//console.log(x,y);
addPoint(x,y);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
@AkshayGore
Copy link

How to measure length between three points?
Thanks
Akshay Gore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment