cesium: Camera.computeViewRectangle doesn't work in 2D or CV
Reported on the forum: https://groups.google.com/forum/?hl=en#!topic/cesium-dev/Ildibeod608
var viewer = new Cesium.Viewer('cesiumContainer', {
sceneMode: Cesium.SceneMode.SCENE2D
});
viewer.scene.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(-90, 43, 50000),
duration: 0,
});
viewer.camera.moveEnd.addEventListener(logViewRectangle);
function logViewRectangle() {
console.log('camera.computeViewRectangle() is ' + JSON.stringify(viewer.scene.camera.computeViewRectangle()));
}
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 2
- Comments: 23 (13 by maintainers)
I’ve used this. (Cesium.Rectangle)
I just ran into this issue as well. Are there any updates on a fix?
You can see in my workaround a few posts back that I use
camera.pickEllipsoid
to find aCartesian3
on the surface based on screen-space (pixel) coordinates. I use the edges of the canvas, but you could use some fractional offset to determine if, say, more than 20% of the screen on one side is empty space.viewer.scene.camera.pickEllipsoid(new Cesium.Cartesian2(pixWidth * 0.2, pixHeight * 0.2))
would give you a Cartesian3 of a point 20% of the way in from the left side of the canvas, and 20% down from the top. If you get anundefined
result, it means that you’ve zoomed out enough that this point is out in space, not over the globe.