天天看点

Cesium 核心类Viewer-查看器详解Cesium 核心类Viewer-查看器详解

Cesium 核心类Viewer-查看器详解

1 简介

A base widget for building applications. It composites all of the standard Cesium widgets into one reusable package. The widget can always be extended by using mixins, which add functionality useful for a variety of applications.

Viewer是一个用于构建应用程序的基本小部件。它将所有标准Cesium小部件组合到一个可重用的程序包中。我们可以通过使用mixin扩展窗口小部件,这些文件添加了对各种应用程序有用的功能。

2 初始化Cesium三维地球查看器函数

【函数名称】

new Cesium.Viewer(container, options)

【入参】

container,类型:Element/String,包含小部件的DOM元素或DOM元素的ID。

options(可选),类型:Viewer.ConstructorOptions对象,描述初始化选项的对象。

Viewer.ConstructorOptions详解:

  • animation,类型:Boolean,默认值:true,是否创建左下角动画(Anaimation)小部件,可以在此小部件中方便的操作动画播放/暂停,修改动画播放倍率。如果设置为false,则不会创建动画小部件。
  • baseLayerPicker,类型:Boolean,默认值:true,是否创建右上角底图选择器(baseLayerPicker)小部件,可在小部件选择底图和地形。如果设置为false,则不会创建底图选择器小部件。
  • fullscreenButton,类型:Boolean,默认值:true,是否创建右下角全屏按钮小部件。如果设置为false,则不会创建全屏按钮小部件。
  • vrButton,类型:Boolean,默认值:false,是否创建右下角VR按钮小部件。如果设置true,则会创建VR按钮小部件。
  • geocoder,类型:Boolean|Array.< GeocoderService >,默认值:true,是否创建地理编码器(geocoder)小部件,也就是右上角搜索框。如果设置为false,则不会创建地理编码器小部件。
  • homeButton,类型:Boolean,默认值:true,是否创建右上角主页按钮小部件,点击按钮可使三维地球视图回到主视图。如果设置为false,则不会创建主页按钮小部件。
  • infoBox,类型:Boolean,默认值:true,是否创建信息框小部件,点击三维地球上的实体时右上角弹出的方盒子,方盒子中默认显示实体ID。如果设置为false,则不会创建信息框小部件。
  • sceneModePicker,类型:Boolean,默认值:true,是否创建右上角场景模式选择器小部件,可选择的场景模式有:3D视图,2D视图,哥伦布视图(2.5D视图)。如果设置为false,则不创建场景模式选择器小部件。
  • selectionIndicator,类型:Boolean,默认值:true,是否创建选择指示符小部件,也就是在选择实体时实体本身会出现一个绿色方块。如果设置为false,则不创建选择指示符小部件。
  • timeline,类型:Boolean,默认值:true,是否创建下方时间线小部件。如果设置为false,则不创建时间线小部件。
  • navigationHelpButton,类型:Boolean,默认值:true,是否创建右上角导航帮助按钮,点击按钮弹出导航说明。如果设置为false,则不创建导航帮助按钮。
  • navigationInstructionsInitiallyVisible,类型:Boolean,默认值:true,初始化地球时导航说明是否可见。如果设置为true,则在初始化地球时就会自动弹出导航说明,如果设置为false,则初始化地球时不显示导航说明,点击导航帮助按钮时才会弹出导航说明。
  • scene3DOnly,类型:Boolean,默认值:false,是否只使用3D场景。如果设置为true,则每个几何实例都将以3D渲染,这样可以节省GPU内存。
  • shouldAnimate,类型:Boolean,默认值:false,如果时钟在默认情况下尝试提前模拟时间,设置为true,反之设置为false,这个设置的优先级大于 Viewer#clockViewModel 。
  • clockViewModel,类型:ClockViewModel,默认值:new ClockViewModel(clock),设置用于控制当前时间的时钟视图模型。
  • selectedImageryProviderViewModel,类型:ProviderViewModel,默认值:无,当前基础影像图层的视图模型,如果未提供,则使用第一个可用的基础图层, 即imageryProviderViewModels 中的第一个。仅当 baseLayerPicker 设置为true时,此值才有效。
  • imageryProviderViewModels,类型:Array.< ProviderViewModel >,默认值:createDefaultImageryProviderViewModels(),从 BaseLayerPicker 中可选择的 ProviderViewModels 数组。仅当 baseLayerPicker 设置为true时,此值才有效。
  • selectedTerrainProviderViewModel,类型:ProviderViewModel,默认值:无,当前基础地形图层的视图模型,如果未提供,则使用第一个可用的基础图层, 即imageryProviderViewModels 中的第一个。仅当 baseLayerPicker 设置为true时,此值才有效。
  • terrainProviderViewModels,类型:Array.< ProviderViewModel >,默认值:createDefaultTerrainProviderViewModels(),从 BaseLayerPicker 中可选择的 ProviderViewModels 数组。仅当 baseLayerPicker 设置为true时,此值才有效。
  • imageryProvider,类型:ImageryProvider,默认值:createWorldImagery(),初始化三维地球时使用的影像提供程序,仅当 baseLayerPicker 设置为false时,此值才有效。此处实测结果是,当 baseLayerPicker 为false时也会生效,只是无法在 baseLayerPicker 所列出图层中显示。
  • terrainProvider,类型:TerrainProvider,默认值:new EllipsoidTerrainProvider(),初始化三维地球时使用的地形提供程序。如果想要加载官方服务器地形的话,可使用Cesium.createWorldTerrain()函数。
  • skyBox,类型:SkyBox|false,默认值:无,设置渲染星空的天空盒。如果不设置,则会使用默认的星空,如果设置为false,则不会渲染任何星空,太阳,月亮等。
  • skyAtmosphere,类型:SkyAtmosphere|false,默认值:无,蔚蓝的天空和围绕在三维地球周边的辉光,也就是所谓的大气层。如果设置为false,则会关闭它。
  • fullscreenElement,类型:Element|String,默认值:document.body,当全屏按钮被按下时将被置于全屏模式的元素或元素ID。此处注意,这里的默认值是body,也就是说如果三维地球在body下首个div上渲染时才能完成真正的三维地球全屏。
  • useDefaultRenderLoop,类型:Boolean,默认值:true,如果需要控制渲染循环,则设置为true,反之,设置为false。
  • targetFrameRate,类型:Number,默认值:无,控制渲染循环的目标帧率。
  • showRenderLoopErrors,类型:Boolean,默认值:true,如果设置为true,在渲染循环出错时会自动为用户显示一个包含错误信息的html面板。
  • useBrowserRecommendedResolution,类型:Boolean,默认值:true,如果设置为true,以浏览器推荐的分辨率渲染,并忽略window.devicePixelRatio。
  • automaticallyTrackDataSourceClocks,类型:Boolean,默认值:true,如果设置为true,则此小部件将自动跟踪新添加的数据源的时钟设置,并在数据源的时钟发生更改时进行更新。如果要独立配置时钟,请将其设置为false。
  • contextOptions,类型:Object,默认值:无,传递给场景(scene)的与options相对应的上下文和WebGL创建属性。这个设置需要一些webGL相关知识,默认值是:{ webgl : { alpha : false, depth : true, stencil : false, antialias : true, powerPreference: ‘high-performance’, premultipliedAlpha : true, preserveDrawingBuffer : false, failIfMajorPerformanceCaveat : false }, allowTextureFilterAnisotropic : true }。其中, webgl.alpha 默认是false,之所以跟webGL默认的false不一样是因为这样可以提升性能,如果应用程序需要在其他HTML元素之上使用alpha混合,设置 webgl.alpha 为true。 allowTextureFilterAnisotropic 默认设置为true,当支持WebGL扩展时启用各向异性纹理过滤。将此设置为false会提高性能,但会损害视觉质量,尤其是对于地平线视图。其他用默认就好。
  • sceneMode,类型:SceneMode,默认值:SceneMode.SCENE3D,设置初始场景模式。共4种模式:1. SceneMode.MORPHING,在模式之间变换,如3D模式到2D模式。2. SceneMode.CPLUMBUS_VIEW,哥伦布视图模式,一个2.5D透视视图,其中地图是平的,可以在上面绘制非零高度的物体。3. SceneMode.SCENE2D,2D模式,地图从上到下用正投影观看。4. SceneMode.SCENE3D,3D模式,一个传统的三维视角的地球。
  • mapProjection,类型:MapProjection,默认值:new GeographicProjection(),在2D和Columbus View模式中使用的地图投影。默认是EPSG:4326,即WGS84经纬度投影,new GeographicProjection(),还可以选择EPSG:3875,即WGS84-WEB墨卡托投影,new WebMercatorProjection()。
  • globe,类型:Globe|false,默认值:new Globe(mapProjection.ellipsoid),场景(scene)中使用的地球仪。如果设置为false,则不会添加地球仪。
  • orderIndependentTranslucency,类型:Boolean,默认值:true,如果设置为true,并且配置支持它,则使用顺序独立半透明。
  • creditContainer,类型:Element|String,默认值:无,包含 CreditDisplay 的DOM元素或元素ID。如果未指定,则将credit信息添加到小部件本身的底部。
  • creditViewport,类型:Element|String,默认值:无,包含 CreditDisplay 创建的credit信息弹出窗口的DOM元素或元素ID。如果未指定,则将credit信息添加到小部件上。
  • dataSources,类型:DataSourceCollection,默认值:new DataSourceCollection(),小部件可视化的数据源集合。如果提供了此参数,该实例假定为调用者所有,并且在销毁查看器(viewer)时也不会销毁。
  • shadows,类型:Boolean,默认值:false,确定光源是否投射阴影。
  • terrainShadows,类型:ShadowMode,默认值:ShadowMode.RECEIVE_ONLY,确定地形是否从光源投射或接收阴影,默认只接收阴影。共4种模式:1. ShadowMode.DISABLED,代表物体不接收和投射阴影。2. ShadowMode.ENABLED,代表物体接收和投射阴影。3. ShadowMode.CAST_ONLY,代表物体只投射阴影。4. ShadowMode.RECEIVE_ONLY,代表物体只接收阴影。
  • mapMode2D,类型:MapMode2D,默认值:MapMode2D.INFINITE_SCROLL,确定2D地图是否可旋转或可以在水平方向上无限滚动,默认无线卷动。共2种模式:1. ROTATE,2D视图下不能无限滚动,但可以绕z轴旋转。2. INFINITE_SCROLL,可以无限滚动,但是无法绕z轴旋转。
  • projectionPicker,类型Boolean,默认值:false,如果设置为true,将创建投影选择器(ProjectionPicker)小部件。
  • requestRenderMode,类型:Boolean,默认值:false,如果设置为true,渲染帧只会在场景中发生变化时才会发生。启用该模式可以减少应用程序的CPU/GPU使用率,并在移动设备上使用更少的电池,但需要使用 Scene#requestRender 在这种模式下显式地渲染一个新帧。在API的其他部分对场景进行更改后,在许多情况下这是必要的。参考官方博客,译文放在这里:Improving Performance with Explicit Rendering(通过显式渲染提高性能)。
  • maximumRenderTimeChange,类型:Number,默认值:0.0,如果 requestRenderMode 为true,这个值定义了在请求渲染之前允许的模拟时间的最大变化。参考官方博客,译文放在这里:Improving Performance with Explicit Rendering(通过显式渲染提高性能)。

【抛出异常】

DeveloperError:开发异常,ID为’容器’的元素在文档中不存在。

DeveloperError:开发异常,options.selectedImageryProviderViewModel在不使用BaseLayerPicker小部件时不可用,请指定options.imageryProvider。

DeveloperError:开发异常,options.selectedTerrainProviderViewModel在不使用BaseLayerPicker小部件时不可用,请指定options.terrainProvider。

3 Viewer的成员属性(Members)

3.1 allowDataSourcesToSuspendAnimation

【类型】

Boolean

【官方解释】

Gets or sets whether or not data sources can temporarily pause animation in order to avoid showing an incomplete picture to the user. For example, if asynchronous primitives are being processed in the background, the clock will not advance until the geometry is ready.

【中文翻译】

获取或设置数据源是否可以暂时暂停动画,以避免向用户显示不完整的图片。例如,如果异步原始类型(asynchronous primitives)在后台处理,时钟将不会前进,直到几何图形准备好。

3.2 animation(只读)

【类型】

Animation

【官方解释】

Gets the Animation widget.

【中文翻译】

获取动画(Animation)小部件。

3.3 baseLayerPicker(只读)

【类型】

BaseLayerPicker

【官方解释】

Gets the BaseLayerPicker.

【中文翻译】

获取底图选择器(baseLayerPicker)小部件。

3.4 bottomContainer(只读)

【类型】

Element

【官方解释】

Gets the DOM element for the area at the bottom of the window containing the CreditDisplay and potentially other things.

【中文翻译】

获取包含 CreditDisplay 和其他内容的窗口底部区域的DOM元素。

3.5 camera(只读)

【类型】

Camera

【官方解释】

Gets the camera.

【中文翻译】

获取相机(camera)对象。

3.6 canvas(只读)

【类型】

HTMLCanvasElement

【官方解释】

Gets the canvas.

【中文翻译】

获取canvas画布 DOM元素。

3.7 cesiumWidget(只读)

【类型】

CesiumWidget

【官方解释】

Gets the CesiumWidget.

【中文翻译】

获取CesiumWidget小部件。

3.8 clock(只读)

【类型】

Clock

【官方解释】

Gets the clock.

【中文翻译】

获取时钟(clock)对象。

3.9 clockTrackedDataSource

【类型】

DataSource

【官方解释】

Gets or sets the data source to track with the viewer’s clock.

【中文翻译】

获取或设置要使用查看器(Viewer)的时钟跟踪的数据源。

3.10 clockViewModel(只读)

【类型】

DataSource

【官方解释】

Gets the clock view model.

【中文翻译】

获取时钟视图模型。

3.11 container(只读)

【类型】

Element

【官方解释】

Gets the parent container.

【中文翻译】

获取父容器。

3.12 dataSourceDisplay(只读)

【类型】

DataSourceDisplay

【官方解释】

Gets the display used for DataSource visualization.

【中文翻译】

获取用于 DataSource 可视化的显示。

3.13 dataSources(只读)

【类型】

DataSourceCollection

【官方解释】

Gets the set of DataSource instances to be visualized.

【中文翻译】

获取要可视化的 DataSource 实例集。

3.14 entities(只读)

【类型】

EntityCollection

【官方解释】

Gets the collection of entities not tied to a particular data source. This is a shortcut to dataSourceDisplay.defaultDataSource.entities.

【中文翻译】

获取未绑定到特定数据源的实体的集合。这是 dataSourceDisplay.defaultDataSource.entities 的快捷方式。

3.15 fullscreenButton(只读)

【类型】

FullscreenButton

【官方解释】

Gets the FullscreenButton.

【中文翻译】

获取全屏按钮(FullscreenButton)小部件。

3.16 geocoder(只读)

【类型】

Geocoder

【官方解释】

Gets the Geocoder.

【中文翻译】

获取地理编码器(geocoder)小部件。

3.17 homeButton(只读)

【类型】

HomeButton

【官方解释】

Gets the HomeButton.

【中文翻译】

获取主页按钮(HomeButton)小部件。

3.18 imageryLayers(只读)

【类型】

ImageryLayerCollection

【官方解释】

Gets the collection of image layers that will be rendered on the globe.

【中文翻译】

获取将在地球上(globe)渲染的图像图层的集合。

3.19 infoBox(只读)

【类型】

InfoBox

【官方解释】

Gets the info box.

【中文翻译】

获取信息框(info box)小部件。

3.20 navigationHelpButton(只读)

【类型】

NavigationHelpButton

【官方解释】

Gets the NavigationHelpButton.

【中文翻译】

获取导航帮助按钮(NavigationHelpButton)小部件。

3.21 postProcessStages(只读)

【类型】

PostProcessStageCollection

【官方解释】

Gets the post-process stages.

【中文翻译】

获取后期处理效果集合。

3.22 projectionPicker(只读)

【类型】

ProjectionPicker

【官方解释】

Gets the ProjectionPicker.

【中文翻译】

获取投影选择器(ProjectionPicker)小部件。

3.23 resolutionScale

【类型】

Number

【默认值】

1.0

【官方解释】

Gets or sets a scaling factor for rendering resolution. Values less than 1.0 can improve performance on less powerful devices while values greater than 1.0 will render at a higher resolution and then scale down, resulting in improved visual fidelity. For example, if the widget is laid out at a size of 640x480, setting this value to 0.5 will cause the scene to be rendered at 320x240 and then scaled up while setting it to 2.0 will cause the scene to be rendered at 1280x960 and then scaled down.

【中文翻译】

获取或设置渲染分辨率的比例因子。小于1.0的值可以在功能不太强大的设备上提高性能,而大于1.0的值将以更高的分辨率渲染,然后缩小,从而提高视觉保真度。例如,如果小部件的布局尺寸为640x480,将此值设置为0.5将导致场景以320x240渲染,然后缩放,而将其设置为2.0将导致场景以1280x960渲染,然后缩小。

3.24 scene(只读)

【类型】

Scene

【官方解释】

Gets the scene.

【中文翻译】

获取场景(scene)对象。

3.25 sceneModePicker(只读)

【类型】

SceneModePicker

【官方解释】

Gets the SceneModePicker.

【中文翻译】

获取场景模式选择器(SceneModePicker)小部件。

3.26 screenSpaceEventHandler(只读)

【类型】

ScreenSpaceEventHandler

【官方解释】

Gets the screen space event handler.

【中文翻译】

获取屏幕空间事件处理程序。参考我另一篇博文:Cesium 事件详解。

3.27 selectedEntity

【类型】

Entity|undefined

【官方解释】

Gets or sets the object instance for which to display a selection indicator. If a user interactively picks a Cesium3DTilesFeature instance, then this property will contain a transient Entity instance with a property named “feature” that is the instance that was picked.

【中文翻译】

获取或设置要为其显示选择指示器的对象实例。如果用户交互式地选择了一个Cesium3DTilesFeature实例,那么这个属性将包含一个瞬时实体实例,其属性名为“feature”,即被选择的实例。

3.28 selectedEntityChanged(只读)

【类型】

Event

【官方解释】

Gets the event that is raised when the selected entity changes.

【中文翻译】

获取当选择的实体(entity)发生变化时触发的事件。

3.29 selectionIndicator(只读)

【类型】

SelectionIndicator

【官方解释】

Gets the selection indicator.

【中文翻译】

获取选择指示符(selectionIndicator)小部件。

3.30 shadowMap(只读)

【类型】

ShadowMap

【官方解释】

Get the scene’s shadow map.

【中文翻译】

获取场景阴影贴图。

3.31 shadows

【类型】

Boolean

【官方解释】

Determines if shadows are cast by light sources.

【中文翻译】

确定是否由光源投射阴影。

3.32 targetFrameRate

【类型】

Number

【官方解释】

Gets or sets the target frame rate of the widget when useDefaultRenderLoop is true. If undefined, the browser’s requestAnimationFrame implementation determines the frame rate. If defined, this value must be greater than 0. A value higher than the underlying requestAnimationFrame implementation will have no effect.

【中文翻译】

获取或设置当 useDefaultRenderLoop 为 true 时小部件的目标帧速率。如果未定义,浏览器的 requestAnimationFrame 实现决定帧速率。如果定义了,这个值必须大于0。高于底层 requestAnimationFrame 实现的值不起作用。

3.33 terrainProvider

【类型】

TerrainProvider

【官方解释】

The terrain provider providing surface geometry for the globe.

【中文翻译】

地形提供程序为地球(globe)提供表面几何形状。

3.34 terrainShadows

【类型】

ShadowMode

【官方解释】

Determines if the terrain casts or shadows from light sources.

【中文翻译】

确定地形是否投射或接收光源的阴影。

3.35 timeline(只读)

【类型】

Timeline

【官方解释】

Gets the Timeline widget.

【中文翻译】

获取时间线(Timeline)小部件。

3.36 trackedEntity

【类型】

Entity|undefined

【官方解释】

Gets or sets the Entity instance currently being tracked by the camera.

【中文翻译】

获取或设置当前被摄像机跟踪的实体实例(Entity instance)。

3.37 trackedEntityChanged(只读)

【类型】

Event

【官方解释】

Gets the event that is raised when the tracked entity changes.

【中文翻译】

获取当追踪的实体(entity)发生变化时触发的事件。

3.38 useBrowserRecommendedResolution

【类型】

Boolean

【默认值】

true

【官方解释】

Boolean flag indicating if the browser’s recommended resolution is used. If true, the browser’s device pixel ratio is ignored and 1.0 is used instead, effectively rendering based on CSS pixels instead of device pixels. This can improve performance on less powerful devices that have high pixel density. When false, rendering will be in device pixels. Viewer#resolutionScale will still take effect whether this flag is true or false.

【中文翻译】

是否使用浏览器推荐的分辨率,布尔类型(Boolean)。如果设置为true,则会忽略浏览器的设备像素比率,取而代之的是1.0,这样根据CSS像素而不是设备像素有效地渲染。这样可以改善在像素密度较高的功能较弱的设备上的性能。如果设置为false,则渲染将以设备像素为单位。 无论设置为true还是false,Viewer#resolutionScale 都有效。

3.39 useDefaultRenderLoop

【类型】

Boolean

【默认值】

true

【官方解释】

Gets or sets whether or not this widget should control the render loop. If set to true the widget will use requestAnimationFrame to perform rendering and resizing of the widget, as well as drive the simulation clock. If set to false, you must manually call the resize, render methods as part of a custom render loop. If an error occurs during rendering, Scene’s renderError event will be raised and this property will be set to false. It must be set back to true to continue rendering after the error.

【中文翻译】

获取或设置此小部件是否应控制渲染循环。如果设置为true,小部件将使用 requestAnimationFrame 来执行小部件的渲染(rendering)和调整大小(resizing),以及驱动模拟时钟。如果设置为false,您必须手动调用resize, render方法作为自定义渲染循环的一部分。如果在渲染过程中发生错误,场景(Scene)的renderError事件将触发,并且此属性将被设置为false。必须将其设置回true才能在错误之后继续渲染。

3.40 vrButton(只读)

【类型】

VRButton

【官方解释】

Gets the VRButton.

【中文翻译】

获取VR按钮(VRButton)小部件。

4 Viewer的成员方法(Methods)

4.1 函数:destroy()

【官方解释】

Destroys the widget. Should be called if permanently removing the widget from layout.

【中文翻译】

销毁小部件。如果小部件从布局中永久删除,应该调用此方法释放内存。

4.2 函数:extend(mixin, options)

【官方解释】

Extends the base viewer functionality with the provided mixin. A mixin may add additional properties, functions, or other behavior to the provided viewer instance.

【中文翻译】

使用所提供的mixin扩展基本查看器(viewer)的功能。mixin可以向所提供的查看器实例添加额外的属性、函数或其他行为。

【入参】

mixin,类型:Viewer.ViewerMixin,要添加到实例上的查看器混入(mixin)。

options(可选),类型:Object,要传给mixin函数的选项对象。

4.3 函数:flyTo(target, options)(常用)

【官方解释】

Flies the camera to the provided entity, entities, or data source. If the data source is still in the process of loading or the visualization is otherwise still loading, this method waits for the data to be ready before performing the flight.

The offset is heading/pitch/range in the local east-north-up reference frame centered at the center of the bounding sphere. The heading and the pitch angles are defined in the local east-north-up reference frame. The heading is the angle from y axis and increasing towards the x axis. Pitch is the rotation from the xy-plane. Positive pitch angles are above the plane. Negative pitch angles are below the plane. The range is the distance from the center. If the range is zero, a range will be computed such that the whole bounding sphere is visible.

In 2D, there must be a top down view. The camera will be placed above the target looking down. The height above the target will be the range. The heading will be determined from the offset. If the heading cannot be determined from the offset, the heading will be north.

【中文翻译】

将摄像机飞向所提供的单个实体、多个实体或数据源。如果数据源仍在加载过程中,或者可视化仍在加载过程中,则该方法等待数据准备就绪后再执行飞行。

偏移量(offset)是在以边界球中心为中心的站心坐标系(ENU坐标系)中的航向(heading)/俯仰(pitch)/范围。航向和俯仰是在站心坐标系中定义的。航向是从y轴向x轴增加的角度。俯仰是从xy平面开始的旋转J角度,往平面上方旋转为正,往平面下方旋转为负。范围就是到中心的距离,如果范围为零,将自动计算一个能使整个边界球可见范围。

在2D中,必须是自上而下的视图,需要把摄像机放置在目标的上方向下看,目标上方的高度就是范围。航向将由偏移量确定。如果不能从偏移量确定航向,则航向将是向北的。

【入参】

target,类型:Entity | Array.< Entity > | EntityCollection | DataSource | ImageryLayer | Cesium3DTileset | TimeDynamicPointCloud | Promise.< (Entity|Array.< Entity >|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud) >,要查看的实体、实体数组、实体集合、数据源、Cesium3DTileset、点云、或成像层,还可以传递一个Promise对象,解析成前面提到的类型之一。

options(可选),类型:Object,此对象具有以下属性:

  • duration(默认值:3.0),类型:Number,飞行持续时间,以秒为单位。
  • maximumHeight,类型:Number,飞行高峰时的最大高度。
  • offset,类型:HeadingPitchRange,在以目标为中心的站心坐标系(ENU坐标系)中,距目标的偏移量。

【出参】

类型:Promise.< Boolean >,一个Promise对象,如果飞行成功,则解析为true;如果目标当前未在场景中显示或飞行已经取消,则解析为false。

4.3 函数:forceResize()

【官方解释】

This forces the widget to re-think its layout, including widget sizes and credit placement.

【中文翻译】

强制小部件重新考虑其布局,包括小部件的尺寸和credit信息的位置。

4.4 函数:isDestroyed()

【出参】

对象如果已经销毁,则返回true,否则返回false。

4.5 函数:render()

【官方解释】

Renders the scene. This function is called automatically unless useDefaultRenderLoop is set to false;

【中文翻译】

渲染场景。这个函数一般会自动调用,除非 useDefaultRenderLoop 设置为false。

4.6 函数:resize()

【官方解释】

Resizes the widget to match the container size. This function is called automatically as needed unless useDefaultRenderLoop is set to false.

【中文翻译】

调整小部件以匹配容器大小。这个函数一般会自动调用,除非 useDefaultRenderLoop 设置为false。

4.7 函数:zoomTo(target, options)(常用)

【官方解释】

Asynchronously sets the camera to view the provided entity, entities, or data source. If the data source is still in the process of loading or the visualization is otherwise still loading, this method waits for the data to be ready before performing the zoom.

The offset is heading/pitch/range in the local east-north-up reference frame centered at the center of the bounding sphere. The heading and the pitch angles are defined in the local east-north-up reference frame. The heading is the angle from y axis and increasing towards the x axis. Pitch is the rotation from the xy-plane. Positive pitch angles are above the plane. Negative pitch angles are below the plane. The range is the distance from the center. If the range is zero, a range will be computed such that the whole bounding sphere is visible.

In 2D, there must be a top down view. The camera will be placed above the target looking down. The height above the target will be the range. The heading will be determined from the offset. If the heading cannot be determined from the offset, the heading will be north.

【中文翻译】

异步设置相机以查看所提供的单个实体、多个实体或数据源。如果数据源仍在加载过程中,或者可视化仍在加载过程中,则该方法等待数据准备就绪后再执行缩放(zoom)操作。

偏移量(offset)是在以边界球中心为中心的站心坐标系(ENU坐标系)中的航向(heading)/俯仰(pitch)/范围。航向和俯仰是在站心坐标系中定义的。航向是从y轴向x轴增加的角度。俯仰是从xy平面开始的旋转J角度,往平面上方旋转为正,往平面下方旋转为负。范围就是到中心的距离,如果范围为零,将自动计算一个能使整个边界球可见范围。

在2D中,必须是自上而下的视图,需要把摄像机放置在目标的上方向下看,目标上方的高度就是范围。航向将由偏移量确定。如果不能从偏移量确定航向,则航向将是向北的。

【入参】

target,类型:Entity | Array.< Entity > | EntityCollection | DataSource | ImageryLayer | Cesium3DTileset | TimeDynamicPointCloud | Promise.< (Entity|Array.< Entity >|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud) >,要查看的实体、实体数组、实体集合、数据源、Cesium3DTileset、点云、或成像层,还可以传递一个Promise对象,解析成前面提到的类型之一。

offset(可选),类型:HeadingPitchRange,在以目标为中心的站心坐标系(ENU坐标系)中,距目标的偏移量。

【出参】

类型:Promise.< Boolean >,一个Promise对象,如果缩放成功,则解析为true;如果目标当前未在场景中显示或缩放已经取消,则解析为false。

继续阅读