In order to display mouse position, I added this function to a “Hello World” Map which includes terrain provider: I just get the xy coordinates and cartesian Z value or a very low height value. See following code and image. How to fix this and show the correct elevation value? Thanks.
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var scene = viewer.scene;
var centralBody = scene.primitives.centralBody;
centralBody.depthTestAgainstTerrain = true;
var handler;
//var ellipsoid = Cesium.Ellipsoid.WGS84;
var ellipsoid = centralBody.ellipsoid;
centralBody.terrainProvider = new Cesium.CesiumTerrainProvider({
url : 'http://cesiumjs.org/smallterrain'
});
function pickCartographicPosition(scene, ellipsoid) {
// Mouse over the globe to see the cartographic position
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
var cartesian = scene.camera.controller.pickEllipsoid(movement.endPosition, ellipsoid);
if (cartesian) {
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
var position = new Cesium.Cartographic(cartographic.longitude, cartographic.latitude);
var coords = Cesium.Math.toDegrees(cartographic.longitude).toFixed(6) + ', ' + Cesium.Math.toDegrees(cartographic.latitude).toFixed(6) + ';<br/> Cartesian Z: '+ cartesian.z.toFixed(2);
//or try to get the height value, result is very low value or zero
//var coords = Cesium.Math.toDegrees(cartographic.longitude).toFixed(6) + ', ' + Cesium.Math.toDegrees(cartographic.latitude).toFixed(6) + ';<br/> Height: '+ cartographic.height ;
document.getElementById('coords').innerHTML = '<p style="display: block;position: absolute;top: 30px;right: 6px" />'+ coords +'<br/><p/>';
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
}
pickCartographicPosition(scene, ellipsoid);
Is this possible to use Cesium.sampleTerrain to get mouse position height value?