In the official CesiumJS tutorial there is a sample HelloWorld application, which shows a map viewer.

When the user opens the page, I want the globe to be centered above a certain point and with a certain zoom:


How can I achieve this?

I assumed that it can be configured via Cesium.Viewer constructor parameters (like timeline below), but didn't find them in the reference.

  <div id="cesiumContainer"></div>
    var viewer = new Cesium.Viewer('cesiumContainer', 
        timeline: false,
        animation: false

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.

| improve this answer | |

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.

| improve this answer | |
  • That seems to mess up the mouse for me so that panning moves the globe about the new centered point. – Richard Apr 21 '17 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.