CesiumGS / CesiumGS/cesium

sampleTerrain + sampleTerrainMostDetailed only returns height of RENDERED terrain

Open
#9,758 0 comments 0 reactions 0 assignees View on GitHub
category - terrain and imagery
Dominant language
JavaScript
Stars
15.8k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

Hi all,

I have a small issue with the methods _sampleTerrain_ and _sampleTerrainMostDetaild_:

I want to get the height of the most detailed terrain tile for given coordinates (mouse location), but both methods olny return the value of the rendered tile. If I zoom out, the returned value gets more and more inaccurate. The coordinates for sampling are generated by _globe.pick_ with a _PickRay_.

Here is my code:
```javascript
viewer.scene.canvas.addEventListener('mousemove', function(e) {
var ray = camera.getPickRay(new Cesium.Cartesian2(e.clientX, e.clientY));
var cartesian = globe.pick(ray, scene)
if (cartesian) {
var cartographic = Cesium.Cartographic.fromCartesian(cartesian)
var lon = Cesium.Math.toDegrees(cartographic.longitude);
var lat = Cesium.Math.toDegrees(cartographic.latitude);
var coords_utm = proj4(wgs84, utm, [lon, lat]);
var promise = Cesium.sampleTerrain(terrainProvider, 19, cartographic);
Cesium.when(promise, function (updatedCartographic) {
//console.log(cartographic, updatedCartographic)
document.getElementById("coords").innerHTML = Math.round(coords_utm[0]) + "     " + Math.round(coords_utm[1])
document.getElementById("height").innerHTML = parseFloat(updatedCartographic.height.toFixed(1)).toLocaleString('de')
}).otherwise(function(err) {
console.error(err);
});
} else {
document.getElementById("coords").innerHTML = "---"
document.getElementById("height").innerHTML = "---"
};
});
```
I think there is something wrong with my code, but I can not find a solution.
Best, Lennart

Contributor guide

Open the contributing guide

Research direction

Start by reading the sampleTerrain and sampleTerrainMostDetailed entry points alongside Globe.pick and PickRay, using the provided mouse-move example to reproduce the height difference while zoomed out. Trace whether sampling uses the requested terrain level or the rendered tile, then verify that the returned height matches the most detailed available terrain for the selected coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.