Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set the Default View Location (Cesium 1.6)

I want to set the default view/home location for a cesium app.

I don't just want to flyTo the location once; I want the location set as the default/home - so that it can be used elsewhere in the app - e.g. in the HomeButton Widget.

I've tried setting the Camera.DEFAULT_VIEW_RECTANGLE (docs here) like this:

var extent = Cesium.Rectangle.fromDegrees(117.940573,-29.808406,118.313421,-29.468825);

viewer.camera.DEFAULT_VIEW_RECTANGLE = extent;

But it doesn't work..

For completeness, here's how I'm initializing the app:

var viewer = new Cesium.Viewer('cesiumContainer', {
        terrainProvider : new Cesium.CesiumTerrainProvider({
            url : '//cesiumjs.org/stk-terrain/tilesets/world/tiles'
        }),
        mapProjection : new Cesium.WebMercatorProjection(),
        timeline: false,
        animation: false,
});

Any suggestions? If any further info is needed please let me know.

like image 814
danwild Avatar asked Feb 25 '15 00:02

danwild


1 Answers

overwrite home button event, like this:

 viewer.homeButton.viewModel.command.beforeExecute.addEventListener(
   function(e) {
      e.cancel = true;
      viewer.scene.camera.flyTo(homeCameraView);
   });
like image 134
caohong Avatar answered Oct 11 '22 18:10

caohong