Camera.computeViewRectangle give false rectangle in australia

Hello,
I’m using camera computeViewRectangle method.It run properly nearly everywhere. But When I’m looking to avustralia (or near locations )and save cameraviewrectangle and later when I try to fly to this rectangle with it fly to other region like africa.

I’m modified viewRectangle sandcastle to show faulty result .

function viewRectangle() {

Sandcastle.declare(viewRectangle);

var west = -3.1415926;

var south =-1.57079;

var east = 3.1415926;

var north = 1.57079;

var rect=scene.camera.computeViewRectangle(viewer.scene.globe.ellipsoid);

var rectangle = Cesium.Rectangle.fromDegrees(west, south, east, north);

viewer.camera.flyTo({

destination: rect,

duration:3

});

console.log(rect);

// Show the rectangle. Not required; just for show.

viewer.entities.add({

rectangle : {

coordinates : rect,

fill : false,

outline : true,

outlineColor : Cesium.Color.WHITE

}

});

}

If you are try view rectangle choice when looking australia. You can see faulty result and faulty rectangle drawwing.

This error can be solve. Is it a bug or my fault.

Thanks .

Esra ERİK

Hello,

I wasn’t able to reproduce the error you were seeing. Here is the example I tested with:

var viewer = new Cesium.Viewer(‘cesiumContainer’);
var west = -3.1415926;
var south =-1.57079;
var east = 3.1415926;
var north = 1.57079;

function callback() {
return new Cesium.Rectangle(west, south, east, north);
}

Sandcastle.addToolbarButton(‘Save’, function() {
var rect = viewer.scene.camera.computeViewRectangle();
west = rect.west;
south = rect.south;
east = rect.east;
north = rect.north;
});

Sandcastle.addToolbarButton(‘Load’, function() {
viewer.camera.flyTo({
destination: new Cesium.Rectangle(west, south, east, north)
});
});

viewer.entities.add({
rectangle : {
coordinates : new Cesium.CallbackProperty(callback, false),
fill : false,
outline : true,
outlineColor : Cesium.Color.WHITE
}
});

``

Make sure you are using the latest version of Cesium. I know at one point we had a bug where computeViewRectangle wasn’t working correctly in the southern hemisphere.

For saving and loading the camera position, I would recommend the method described in this forum post instead: https://groups.google.com/d/msg/cesium-dev/lolHXdDitOg/GC4iPNiICgAJ

computeViewRectangle isn’t the most accurate for certain tilted and zoomed out views. Saving the position/heading/pitch/roll will give you better results.

Best,

Hannah