Hi all!
I am trying to get coordinates on mouse click. My code:
//get position from globe and set model
function getPositionFromGlobe() {
var viewer = Earth.variables.cesiumViewer;
var scene = Earth.variables.cesiumScene;
var ellipsoid = scene.globe.ellipsoid;
var cartographic;
var longitudeString;
var latitudeString;
var heightString;
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas),
onEarthClick = function (e) {
if (e.which == 3) {//right button
$(this).unbind('mousedown', onEarthClick);
Earth.variables.currentModel.longitude = parseFloat(longitudeString);
Earth.variables.currentModel.latitude = parseFloat(latitudeString);
Earth.variables.currentModel.altitude = parseFloat(heightString);
setModelToCesium(Earth.variables.currentModel);
}
};
handler.setInputAction(function (movement) {
var cartesian = viewer.camera.pickEllipsoid(movement.endPosition, ellipsoid);
if (cartesian) {
cartographic = ellipsoid.cartesianToCartographic(cartesian);
longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(15);
latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(15);
heightString = Cesium.Math.toDegrees(cartographic.height).toFixed(15);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
$("#map3d").mousedown(onEarthClick);
}
If I use with standart terrain - I can get longitude and latitude, but altitude is always = 5 or 10.
When I use smallterrain (http://cesiumjs.org/tilesets/terrain/smallterrain) or STK World terrain meshes, I get altitude = 5 or 10 too.
It`s important for me to get altitude from clicked point. I can not put model correctly on the hills or mountains.
Anyone can tell me the way to do this?
Regards.