camera.computeViewRectangle is returning a wrong extent when extent crosses the IDL.

When the extent crosses the IDL the rectangle.west is returning as negative when it is supposed to be positive. The east is returning positive when it is supposed to be negative.

Use the following code in Sandcastle to see the issue. Go to the Pacific area near the IDL (keep IDL at center of view) and zoom in to an altitude where the sky is not visible. The label will show the current mouse coordinate and current west and east value of the extent. I’m also attaching a snapshot.

var viewer = new Cesium.Viewer(‘cesiumContainer’, {
selectionIndicator : false,
infoBox : false
});

var scene = viewer.scene;
var handler;

Sandcastle.addDefaultToolbarButton(‘Show Cartographic Position on Mouse Over’, function() {
var entity = viewer.entities.add({
label : {
show : false
}
});

// Mouse over the globe to see the cartographic position
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
    var cartesian = viewer.camera.pickEllipsoid(movement.endPosition, scene.globe.ellipsoid);
    var extent = viewer.scene.camera.computeViewRectangle(viewer.scene.globe.ellipsoid);
    if (cartesian) {
        var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);

        entity.position = cartesian;
        entity.label.show = true;
        entity.label.text = '(' + longitudeString + ', ' + latitudeString + ')  extent: ' + 'west =' + extent.west.toFixed(2) + ' east = ' + extent.east.toFixed(2);
    } else {
        entity.label.show = false;
    }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

});

Sandcastle.reset = function() {
viewer.entities.removeAll();
handler = handler && handler.destroy();
};

Thanks,

Alberto

Thanks for the code example Alberto!
I’ve filed an issue on GitHub to fix the bug: https://github.com/AnalyticalGraphicsInc/cesium/issues/3717

It looks like we forgot to switch the west and east values for rectangles that cross the IDL

Thanks again,

Hannah