Javascript 在场景变换后设置摄影机位置

Javascript 在场景变换后设置摄影机位置,javascript,cesium,Javascript,Cesium,在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 sout

在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...');    
});
上面的代码与“变形完成”事件挂钩,场景转换完成后,“视图矩形”将设置为欧洲的一个区域。至少这是我预期的行为。
观察到的行为是在变形完成后,铯视图矩形在国外。我的问题是如何在场景转换后设置贴图视图矩形?

看起来这是我们的相机处理中的一个错误,显然我们在触发
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...');
    });
});

我刚刚申请了这个。

windows.scene=scene的目的是什么?您可以在事件处理程序中使用
scene
而不是
windows.scene
。。。但我仍然有同样的问题,它正确地记录了信息,但相机的位置没有改变。这是加勒比海某处的默认设置(对于3D视图)。你也一样吗?或者您所处的位置与默认位置和预期位置不同?window.scene是多余的,您是对的。是的,在加勒比海的某个地方,肖恩也在我这边。