Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 484
user3659695 Avatar asked Nov 15 '25 08:11

user3659695


2 Answers

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
});
like image 159
Karó Gyökér Avatar answered Nov 17 '25 20:11

Karó Gyökér


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.

like image 41
Sean Avatar answered Nov 17 '25 20:11

Sean