CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.94k stars 3.49k forks source link

Camera.flyTo doesn't work right after mophComplete #4742

Open hpinkos opened 7 years ago

hpinkos commented 7 years ago

Reported on the forum: https://groups.google.com/forum/?hl=en#!topic/cesium-dev/aalnZv0HAaQ

If you morph to 3D when the example is loaded, the camera flight never gets executed. camera.flyTo is being called, but the animation must be getting removed somewhere. Adding a short setTimeout fixes the problem. (The user is trying to work around #2647)

var viewer = new Cesium.Viewer('cesiumContainer', {
    sceneMode: Cesium.SceneMode.SCENE2D
});

var scene = viewer.scene;
var camera = viewer.camera;

scene.morphComplete.addEventListener(function() {
    console.log('morph complete');
    camera.flyTo({
        destination : Cesium.Cartesian3.fromDegrees(-74.0, 41.0, 15000.0),
        complete: function() {
            console.log('flyto complete');
        },
        cancel: function() {
            console.log('flyto cancelled');
        }
    });
});

More info from the user:

With the default setting of completeMorphOnUserInput=true, clicking the map during the morph completes it and initiates the flyTo correctly even without the setTimeout.

mramato commented 7 years ago

In the provided code example, morphComplete will never be called because no morph is happening. Add scene.morphTo3D(); to the end and it will morph (and expose the bug). I'm guessing that we are firing morphComplete too early and doing something that clears the flight before the morph is completely finished.

hpinkos commented 7 years ago

I was morphing to 3D using the scene mode picker. Forgot to include that instruction, sorry

mramato commented 7 years ago

Oh, that makes total sense then 😄

DustinPham commented 7 years ago

@hpinkos Did you ever find a fix to this?

hpinkos commented 7 years ago

Hi @DustinPham, no sorry we haven't had a chance to look at this yet. I'll ping you when we do.

If you have time to look into it, we would be happy to review a pull request! Thanks!

DustinPham commented 7 years ago

@hpinkos Thanks for the quick response! I did find a workaround using setView instead of flyTo, but it doesn't look as nice.