Hi,
I am trying to figure out how to get the height on mouse click (above sea level).
Preferabbly, I would like to get the heightmap from GeoServer, though corrently I’m simply using the default cesium maps.
I couldn’t find any posts which suit my needs.
In the following function I get the position of the mouse click, convert it to lng/lat, and then attempt to use the Cesium.sampleTerrainMostDetailed. But the height I get back is always zero.
I’ll also note that I initiated the TerrainProvider with maptiler’s free provider (Free Terrain Tiles for Cesium | MapTiler).
Blockquote
function onMouseLeftClick(position: Cartesian2){
console.log(“Left Click Position:”, position);
if(!viewerRef.current || !viewerRef.current.cesiumElement){
return;
//get height
const viewer = viewerRef.current.cesiumElement;
const cartographicPosition = convertScreenPixelToLocation(position)
if(!cartographicPosition){
return;
}
const cartographic = new Cesium.Cartographic(cartographicPosition.lng, cartographicPosition.lat);
Cesium.sampleTerrainMostDetailed(viewer.terrainProvider, [cartographic]).then(function(terrainData) {
console.log(“Terrain Data :”, terrainData[0]);
})
Thank you