在场景转换后设置相机位置

时间:2014-10-16 05:08:15

标签: javascript cesium

在Cesium Sandcastle应用程序中,我编辑了Camera教程以包含下面的代码片段:

window.scene = scene;
scene.morphComplete.addEventListener(function (){
    console.log('Morph completed...');
    var west = Cesium.Math.toRadians(10);
    var east = Cesium.Math.toRadians(40);
    var south = Cesium.Math.toRadians(35);
    var north = Cesium.Math.toRadians(45);
    var rectangle = new Cesium.Rectangle(west,south,east,north);    
    window.scene.camera.viewRectangle(rectangle);
    console.log('Camera view rectangle updated...');    
});

上面的代码挂钩变形完成事件,一旦场景转换完成,视图矩形就会设置为欧洲的一个区域。至少这是我预期的行为。 观察到的行为是在变形完成后,铯视图矩形在海外。我的问题是如何在场景转换后设置地图视图矩形?

1 个答案:

答案 0 :(得分:2)

看起来这是我们的相机处理中的一个错误,显然我们在解除morphComplete事件后最后一次设置了相机。

您可以通过等待一个动画帧通过来解决它,然后再自己控制相机。例如:

scene.morphComplete.addEventListener(function (){
    Cesium.requestAnimationFrame(function() {   // This is the workaround.
        console.log('Morph completed...');
        var west = Cesium.Math.toRadians(10);
        var east = Cesium.Math.toRadians(40);
        var south = Cesium.Math.toRadians(35);
        var north = Cesium.Math.toRadians(45);
        var rectangle = new Cesium.Rectangle(west,south,east,north);
        window.scene.camera.viewRectangle(rectangle);
        console.log('Camera view rectangle updated...');
    });
});

我刚刚为此提交了Issue #2203

相关问题