1. A concise explanation of the problem you’re experiencing.
I have to get the range of the camera to 3d terrain for some functions (create labels, get radius, etc).
The problem is that if I use “camera.pickRay” too early (usually at startup) I get an error
An error occurred while rendering. Rendering has stopped.
TypeError: Cannot read property ‘x’ of undefined
TypeError: Cannot read property ‘x’ of undefined
at Function.a.subtract (https://cesiumjs.org/releases/1.61/Build/Cesium/Cesium.js:472:14500)
at Function.a.distance (https://cesiumjs.org/releases/1.61/Build/Cesium/Cesium.js:472:13973)
at Object.get range [as range] (http://localhost/360WebApp/src/map/cameraController.js:50:34)
at getLabelsFromGeoDB (http://localhost/360WebApp/src/map/labelsController.js:52:40)
at http://localhost/360WebApp/src/map/labelsController.js:21:5
at r.raiseEvent (https://cesiumjs.org/releases/1.61/Build/Cesium/Cesium.js:471:17744)
so, I should get an event or something like that when the 3d terrain is ready
2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.
/// Return the Cartesian3 point that is the intersection
/// of a ray from the camera to the specified x and y canvas positions
/// and the 3d terrain
function getPointFromCamera(xCanvas = null, yCanvas = null) {
const canvas = viewer.scene.canvas;
if (xCanvas === null || yCanvas === null) {
xCanvas = canvas.clientWidth / 2;
yCanvas = canvas.clientHeight / 2;
}
const ray = viewer.camera.getPickRay(new Cesium.Cartesian2(
Math.round(xCanvas), Math.round(yCanvas)
));
return point = viewer.scene.globe.pick(ray, viewer.scene);
}
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
I need to pick the coordinates in the center of the frame and get the camera range as soon as possible
to create labels around that point
4. The Cesium version you’re using, your operating system and browser.
1.61