How to set the coordinates at which Cesium.Viewer is centered?

If you already have created a viewer, you can put this code after that viewer creation, to create a zoom to a specific Longitude, Latitude.

var center = Cesium.Cartesian3.fromDegrees(-82.5, 35.3);
viewer.camera.lookAt(center, new Cesium.Cartesian3(0.0, 0.0, 4200000.0));

And if you set the 3rd term in the 2nd line to 32500000.0 you will be farther away, similar to the effect of the home button. So try varying that 3rd term to get the zoom you want.


You can set the "default" camera view prior to constructing the Viewer widget, and this is used both for the initial view and for the "Home" button view. Set this using static properties DEFAULT_VIEW_FACTOR and DEFAULT_VIEW_RECTANGLE on the Camera class (reference doc), like this:

var west = 122.0;
var south = 33.0;
var east = 130.0;
var north = 47.0;

var rectangle = Cesium.Rectangle.fromDegrees(west, south, east, north);

Cesium.Camera.DEFAULT_VIEW_FACTOR = 0;
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = rectangle;

// NOTE: Viewer constructed after default view is set.
var viewer = new Cesium.Viewer('cesiumContainer');

Also note that the Sandcastle Camera Demo shows a number of ways to fly or snap the camera to locations at runtime, after construction. Use the drop-down box selector (upper-left of the globe) to see the different options there.

Tags:

Cesium