cesium js 路径_如何设置默认视图位置(Cesium 1.6)

在Cesium应用中设置默认视图或主页位置,不仅希望首次加载时飞往指定位置,还要求该位置能在应用其他部分复用,如HomeButton组件。通过尝试设置Camera.DEFAULT_VIEW_RECTANGLE未成功。正确做法是在创建Viewer之前设置Cesium.Camera.DEFAULT_VIEW_RECTANGLE,并可能需要调整Camera.DEFAULT_VIEW_FACTOR为0,以确保默认视图与设定矩形完全匹配。初始化Viewer时,包括地形提供者、地图投影、时间线和动画选项等。
摘要由CSDN通过智能技术生成

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.

解决方案

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

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值