最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Set the Default View Location (Cesium 1.6) - Stack Overflow

programmeradmin4浏览0评论

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/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.

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.

Share Improve this question asked Feb 25, 2015 at 0:26 danwilddanwild 2,0463 gold badges27 silver badges34 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 17

DEFAULT_VIEW_RECTANGLE is a static property on Cesium.Camera. This way, you can assign the value before Viewer is constructed, and then newly constructed widgets will initialize to your custom default view rectangle.

EDIT: Also, be aware of Camera.DEFAULT_VIEW_FACTOR. You can set this to zero, to make the default view match your rectangle exactly. Its default value will make your default view stand well back from your chosen rectangle.

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

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

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,
    baseLayerPicker: false
});

overwrite home button event, like this:

 viewer.homeButton.viewModel.command.beforeExecute.addEventListener(
   function(e) {
      e.cancel = true;
      viewer.scene.camera.flyTo(homeCameraView);
   });
发布评论

评论列表(0)

  1. 暂无评论