sampleTerrainMostDetailed not accurate if zoomed out

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 only 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 and given to the method sampleTerrainMostDetailed for sampling the height information.

Here is my code:

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 = "---"
	};
});

And here is the content of the layer.json file of the terrain:

{
  "tilejson": "2.1.0",
  "name": "DGM05",
  "description": "",
  "version": "1.1.0",
  "format": "quantized-mesh-1.0",
  "attribution": "",
  "schema": "tms",
  "tiles": [ "{z}/{x}/{y}.terrain?v={version}" ],
  "projection": "EPSG:4326",
  "bounds": [ -180.00, -90.00, 180.00, 90.00 ],
  "available": [
    [ { "startX": 0, "startY": 0, "endX": 1, "endY": 0 } ]
   ,[ { "startX": 2, "startY": 1, "endX": 2, "endY": 1 } ]
   ,[ { "startX": 4, "startY": 3, "endX": 4, "endY": 3 } ]
   ,[ { "startX": 8, "startY": 6, "endX": 8, "endY": 6 } ]
   ,[ { "startX": 16, "startY": 12, "endX": 16, "endY": 12 } ]
   ,[ { "startX": 33, "startY": 25, "endX": 33, "endY": 25 } ]
   ,[ { "startX": 66, "startY": 50, "endX": 66, "endY": 50 } ]
   ,[ { "startX": 132, "startY": 100, "endX": 133, "endY": 100 } ]
   ,[ { "startX": 265, "startY": 201, "endX": 266, "endY": 201 } ]
   ,[ { "startX": 531, "startY": 402, "endX": 532, "endY": 402 } ]
   ,[ { "startX": 1063, "startY": 804, "endX": 1064, "endY": 805 } ]
   ,[ { "startX": 2127, "startY": 1609, "endX": 2129, "endY": 1611 } ]
   ,[ { "startX": 4254, "startY": 3219, "endX": 4259, "endY": 3223 } ]
   ,[ { "startX": 8509, "startY": 6438, "endX": 8518, "endY": 6446 } ]
   ,[ { "startX": 17018, "startY": 12876, "endX": 17036, "endY": 12892 } ]
   ,[ { "startX": 34037, "startY": 25753, "endX": 34072, "endY": 25785 } ]
   ,[ { "startX": 68074, "startY": 51507, "endX": 68145, "endY": 51570 } ]
   ,[ { "startX": 136149, "startY": 103015, "endX": 136291, "endY": 103141 } ]
   ,[ { "startX": 272298, "startY": 206030, "endX": 272583, "endY": 206282 } ]
   ,[ { "startX": 544596, "startY": 412060, "endX": 545166, "endY": 412564 } ]
  ]
}

Maybe there is something wrong with my code, but I can not find the solution.

For now, i just disabled the whole function if the camera is far away from the terrain and the results would be inaccurate. But I want to solve the “error” and use this function at every camera position.

Maybe someone can help me?

Best, Lennart

EDIT: Added content of layer.json