如何设置默认视图位置

如何设置默认视图位置

本文介绍了如何设置默认视图位置(Cesium 1.6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置cesium应用的默认视图/家庭位置。

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

我不只是想飞到该位置一次;我希望将位置设置为默认/ home - 以便可以在应用程序的其他位置使用 - 例如在小工具中。

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.

我已尝试设置 Camera.DEFAULT_VIEW_RECTANGLE 像这样:

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;

但它不起作用..

为了完整性,这里是我如何初始化应用程序:

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.

推荐答案

DEFAULT_VIEW_RECTANGLE Cesium.Camera 上的静态属性。这样,您可以在构造 Viewer 之前分配值,然后新构建的小部件将初始化为您的自定义默认视图矩形。

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.

编辑:另外,请注意。您可以将此值设置为零,以使默认视图与您的矩形完全匹配。它的默认值将使您的默认视图远离您选择的矩形。

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
});

这篇关于如何设置默认视图位置(Cesium 1.6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:02