1

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

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...');    
});

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

4

1 回答 1

2

Looks like this is a bug in our camera handling, apparently we set the camera one last time after firing the morphComplete event.

You can work around it by waiting for one animation frame to pass before taking control of the camera yourself. For example:

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...');
    });
});

I just filed Issue #2203 for this.

于 2014-10-17T13:17:58.210 回答