user3659695
user3659695

Reputation: 43

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? :)

Upvotes: 4

Views: 3649

Answers (2)

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

Upvotes: 3

Sean
Sean

Reputation: 879

A centering - in a sense of changing the origin - of a map is not supported in 2D mode, if you have zoomed completely out. you can take a look at the forums : https://groups.google.com/forum/#!searchin/cesium-dev/centering/cesium-dev/rj2pDY1Hie8/hH2xJhIzCC0J

Try SCENE3D, and COLUMBUS_VIEW, with viewRectangle - works for me. If you are in Columbus view, do not forget to add a camera.setPositionCartographic ( Cesium.Cartographic.fromDegrees(a,b,c));, where a,b,c, are usually -90, 45, and a small number of your choice, e.g. 2 to orient the direction of the map.

Upvotes: 1

Related Questions