Search code examples
javascriptdictionarycesiumjs

Cesium JS : center map in 2d scene mode


I am using Cesium JS and I am a beginner. I initialised Cesium in 2D scene mode and I can't center the map.

Here is what I tried:

var widget = new Cesium.CesiumWidget('cesiumContainer', {
    sceneMode : Cesium.SceneMode.SCENE2D
});
// try to center somewhere in Europe
widget.scene.camera.setPositionCartographic(Cesium.Cartographic.fromDegrees(10, 45, 500000));

I also tried with scene.camera.viewRectangle(rectangle, ellipsoid); as explained here. I tried the flight too.

All methods above work great in 3D scene mode but not in 2D. So I tried to put my camera where I want in 3D and switch to 2D mode with SceneModePickerViewModel.morphTo2D(). Still not working...

I know I am missing the whole point about center the map in 2D scene mode. Can anyone help me? :)


Solution

  • The flyTo method worked for me. I'm using Cesium 1.37.

    viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(0.0, 0.0, 40000000),
        duration: 0
    });