How to set the default location (Cesium 1.6)

I want to set a standard view / source location for a cesium application.

I do not just want to fly to a place once; I want the location to be set as the default / home - so that it can be used elsewhere in the application. in HomeButton Widget.

I tried setting Camera.DEFAULT_VIEW_RECTANGLE (docs here) as follows:

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

But that does not work.

For completeness, here's how I initialize the application:

 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 information is needed, please let me know.

+5
source share
1 answer

DEFAULT_VIEW_RECTANGLE is a static property on Cesium.Camera . That way, you can assign a value before the Viewer is built, and then the newly created widgets will be initialized to your custom default view rectangle.

EDIT: Also keep abreast of Camera.DEFAULT_VIEW_FACTOR . You can set this value to zero to make the default view exactly match your rectangle. Its default value will make your default view revert to the selected 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 }); 
+6
source

Source: https://habr.com/ru/post/1214124/


All Articles