Viewer

new Cesium.Viewer(container, options)

用于构建应用程序的基本小部件。它将所有标准的铯部件组合成一个可重用的包。 小部件总是可以通过使用mixin进行扩展,mixin添加了对各种应用程序有用的功能。
Name Type Description
container Element | String 将包含小部件的DOM元素或ID。
options Viewer.ConstructorOptions optional 描述初始化选项的对象
Throws:
  • DeveloperError :文档中不存在id为“container”的元素。
  • DeveloperError : options.SelectedImageProviderViewModel不使用BaseLayerPicker小部件时不可用,请指定options.imageryProvider选项相反。
  • DeveloperError : options.selectedTerrainProviderViewModel不使用BaseLayerPicker小部件时不可用,请指定选项.terrainProvider相反。
Example:
//Initialize the viewer widget with several custom options and mixins.
var viewer = new Cesium.Viewer('cesiumContainer', {
    //Start in Columbus Viewer
    sceneMode : Cesium.SceneMode.COLUMBUS_VIEW,
    //Use Cesium World Terrain
    terrainProvider : Cesium.createWorldTerrain(),
    //Hide the base layer picker
    baseLayerPicker : false,
    //Use OpenStreetMaps
    imageryProvider : new Cesium.OpenStreetMapImageryProvider({
        url : 'https://a.tile.openstreetmap.org/'
    }),
    skyBox : new Cesium.SkyBox({
        sources : {
          positiveX : 'stars/TychoSkymapII.t3_08192x04096_80_px.jpg',
          negativeX : 'stars/TychoSkymapII.t3_08192x04096_80_mx.jpg',
          positiveY : 'stars/TychoSkymapII.t3_08192x04096_80_py.jpg',
          negativeY : 'stars/TychoSkymapII.t3_08192x04096_80_my.jpg',
          positiveZ : 'stars/TychoSkymapII.t3_08192x04096_80_pz.jpg',
          negativeZ : 'stars/TychoSkymapII.t3_08192x04096_80_mz.jpg'
        }
    }),
    // Show Columbus View map with Web Mercator projection
    mapProjection : new Cesium.WebMercatorProjection()
});

//Add basic drag and drop functionality
viewer.extend(Cesium.viewerDragDropMixin);

//Show a pop-up alert if we encounter an error when processing a dropped file
viewer.dropError.addEventListener(function(dropHandler, name, error) {
    console.log(error);
    window.alert(error);
});
Demo:
See:

Members

allowDataSourcesToSuspendAnimation : Boolean

获取或设置数据源是否可以临时暂停 动画,以避免向用户显示不完整的图片。 例如,如果异步原语在 背景,在几何体准备好之前,时钟不会前进。
获取动画小部件。

readonly baseLayerPicker : BaseLayerPicker

获取BaseLayerPicker。

readonly bottomContainer : Element

获取包含 CreditDisplay和其他可能的东西。
拿到相机。

readonly canvas : HTMLCanvasElement

得到画布。

readonly cesiumWidget : CesiumWidget

得到塞西姆维吉特。
拿到时钟。

clockTrackedDataSource : DataSource

获取或设置要跟踪查看器时钟的数据源。

readonly clockViewModel : ClockViewModel

获取时钟视图模型。

readonly container : Element

获取父容器。

readonly dataSourceDisplay : DataSourceDisplay

获取用于DataSource可视化的显示。
获取要可视化的DataSource个实例集。
获取未绑定到特定数据源的实体的集合。 这是dataSourceDisplay.defaultDataSource.entities的捷径。

readonly fullscreenButton : FullscreenButton

获取全屏按钮。
获取地理编码器。
获取HomeButton。
获取将在全局上呈现的图像层的集合。
获取信息框。
获取NavigationHelpButton。
获取后处理阶段。

readonly projectionPicker : ProjectionPicker

获取ProjectionPicker。

resolutionScale : Number

获取或设置呈现分辨率的比例因子。小于1.0的值可以提高 当值大于1.0时,在功能较弱的设备上的性能将以更高的速度呈现 然后缩小分辨率,从而提高视觉逼真度。 例如,如果小部件的布局尺寸为640x480,则将该值设置为0.5 将导致场景渲染为320x240,然后在设置时按比例放大 将其设置为2.0将导致场景渲染为1280x960,然后按比例缩小。
Default Value: 1.0
得到现场。

readonly sceneModePicker : SceneModePicker

获取SceneModePicker。

readonly screenSpaceEventHandler : ScreenSpaceEventHandler

获取屏幕空间事件处理程序。

selectedEntity : Entity|undefined

获取或设置要显示其选择指示器的对象实例。 如果用户以交互方式选择一个Cesium3DTilesFeature实例,则此属性 将包含一个具有名为“feature”的属性的临时实体实例 选择的实例。

readonly selectedEntityChanged : Event

获取所选实体更改时引发的事件。

readonly selectionIndicator : SelectionIndicator

获取选择指示器。
获取场景的阴影贴图

shadows : Boolean

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

targetFrameRate : Number

useDefaultRenderLoop时,获取或设置小部件的目标帧速率 是真的。如果未定义,则浏览器的requestAnimationFrame实现 确定帧速率。如果已定义,则此值必须大于0。更高的价值 否则,实现将没有底层框架的动画效果。
为地球提供曲面几何图形的地形提供商。
确定地形是从光源投射还是阴影。
获取时间线小部件。

trackedEntity : Entity|undefined

获取或设置摄像机当前跟踪的实体实例。

readonly trackedEntityChanged : Event

获取当跟踪的实体更改时引发的事件。

useBrowserRecommendedResolution : Boolean

指示是否使用浏览器建议的分辨率的布尔标志。 如果为true,则忽略浏览器的设备像素比,而使用1.0, 有效地基于CSS像素而不是设备像素进行渲染。这可以改善 在像素密度较高、功能较弱的设备上的性能。如果为false,则渲染 将以设备像素为单位。Viewer#resolutionScale是否仍将生效 此标志为真或假。
Default Value: true

useDefaultRenderLoop : Boolean

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

Methods

销毁小部件。如果是永久性的 正在从布局中删除小部件。

extend(mixin, options)

使用提供的mixin扩展基本查看器功能。 mixin可以添加额外的属性、函数或其他行为 到提供的查看器实例。
Name Type Description
mixin Viewer.ViewerMixin 要添加到此实例的查看器mixin。
options Object optional 要传递给mixin函数的options对象。
See:

flyTo(target, options)Promise.<Boolean>

将摄影机飞到提供的实体、实体或数据源。 如果数据源仍在加载过程中或可视化仍在加载, 此方法在执行飞行之前等待数据准备就绪。

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.

Name Type Description
target Entity | Array.<Entity> | EntityCollection | DataSource | ImageryLayer | Cesium3DTileset | TimeDynamicPointCloud | Promise.<(Entity|Array.<Entity>|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud)> 要查看的实体、实体数组、实体集合、数据源、CESUM3DTileset、点云或图像层。您还可以传递一个解析为前面提到的类型之一的promise。
options Object optional 具有以下属性的对象:
Name Type Default Description
duration Number 3.0 optional 飞行的持续时间(秒)。
maximumHeight Number optional 飞行高峰时的最大高度。
offset HeadingPitchRange optional 在以目标为中心的局部东-北上参考坐标系中与目标的偏移。
Returns:
一种承诺,如果飞行成功,则为真;如果目标当前未出现在场景中或飞行被取消,则为假。//TODO:清理实体提到
这迫使小部件重新考虑其布局,包括 小部件尺寸和信贷安排。

isDestroyed()Boolean

Returns:
如果对象已被销毁,则为true,否则为false。
渲染场景。此函数将自动调用 除非useDefaultRenderLoop设置为false;
调整小部件的大小以匹配容器大小。 此函数根据需要自动调用,除非 useDefaultRenderLoop设置为false。

zoomTo(target, offset)Promise.<Boolean>

异步设置相机以查看提供的实体、实体或数据源。 如果数据源仍在加载过程中或可视化仍在加载, 此方法在执行缩放之前等待数据准备就绪。

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.

Name Type Description
target Entity | Array.<Entity> | EntityCollection | DataSource | ImageryLayer | Cesium3DTileset | TimeDynamicPointCloud | Promise.<(Entity|Array.<Entity>|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud)> 要查看的实体、实体数组、实体集合、数据源、CESUM3DTileset、点云或图像层。您还可以传递一个解析为前面提到的类型之一的promise。
offset HeadingPitchRange optional 从局部“东-北”向上参照系中图元中心的偏移。
Returns:
一种承诺,如果缩放成功,则解析为true;如果场景中当前未显示目标或取消缩放,则解析为false。

Type Definitions

Cesium.Viewer.ConstructorOptions

查看器构造函数的初始化选项
Properties:
Name Type Attributes Default Description
animation Boolean <optional>
true 如果设置为false,则不会创建动画小部件。
baseLayerPicker Boolean <optional>
true 如果设置为false,则不会创建BaseLayerPicker小部件。
fullscreenButton Boolean <optional>
true 如果设置为false,则不会创建FullscreenButton小部件。
vrButton Boolean <optional>
false 如果设置为true,将创建VRButton小部件。
geocoder Boolean | Array.<GeocoderService> <optional>
true 如果设置为false,则不会创建Geocoder小部件。
homeButton Boolean <optional>
true 如果设置为false,则不会创建HomeButton小部件。
infoBox Boolean <optional>
true 如果设置为false,则不会创建InfoBox小部件。
sceneModePicker Boolean <optional>
true 如果设置为false,则不会创建SceneModePicker小部件。
selectionIndicator Boolean <optional>
true 如果设置为false,则不会创建SelectionIndicator小部件。
timeline Boolean <optional>
true 如果设置为false,则不会创建时间线小部件。
navigationHelpButton Boolean <optional>
true 如果设置为false,则不会创建导航帮助按钮。
navigationInstructionsInitiallyVisible Boolean <optional>
true 如果导航指令最初应该可见,则为True,如果在用户明确单击按钮之前不应显示导航指令,则为false。
scene3DOnly Boolean <optional>
false true时,每个几何体实例将仅以3D形式呈现,以节省GPU内存。
shouldAnimate Boolean <optional>
false true,如果时钟应尝试提前模拟时间,否则为false。此选项优先于设置Viewer#clockViewModel
clockViewModel ClockViewModel <optional>
new ClockViewModel(clock) 用于控制当前时间的时钟视图模型。
selectedImageryProviderViewModel ProviderViewModel <optional>
当前基础图像层的视图模型,如果未提供,则使用第一个可用的基础层。此值仅在“baseLayerPicker”设置为true时有效。
imageryProviderViewModels Array.<ProviderViewModel> <optional>
createDefaultImageryProviderViewModels() 可从BaseLayerPicker中选择的ProviderViewModels数组。此值仅在“baseLayerPicker”设置为true时有效。
selectedTerrainProviderViewModel ProviderViewModel <optional>
当前基础地形图层的视图模型,如果未提供,则使用第一个可用的基础图层。此值仅在“baseLayerPicker”设置为true时有效。
terrainProviderViewModels Array.<ProviderViewModel> <optional>
createDefaultTerrainProviderViewModels() 可从BaseLayerPicker中选择的ProviderViewModels数组。此值仅在“baseLayerPicker”设置为true时有效。
imageryProvider ImageryProvider <optional>
createWorldImagery() 要使用的图像提供商。此值仅在“baseLayerPicker”设置为false时有效。
terrainProvider TerrainProvider <optional>
new EllipsoidTerrainProvider() 要使用的地形提供程序
skyBox SkyBox | false <optional>
用来渲染星星的天空盒。当undefined时,使用默认的星形。如果设置为false,则不会添加skyBox、太阳或月亮。
skyAtmosphere SkyAtmosphere | false <optional>
蓝色的天空,以及环绕地球的光辉。设置为false可将其关闭。
fullscreenElement Element | String <optional>
document.body 当按下全屏按钮时要置于全屏模式的元素或标识。
useDefaultRenderLoop Boolean <optional>
true 如果此小部件应控制渲染循环,则为True,否则为false。
targetFrameRate Number <optional>
使用默认渲染循环时的目标帧速。
showRenderLoopErrors Boolean <optional>
true 如果为true,则当出现呈现循环错误时,此小部件将自动向用户显示包含错误的HTML面板。
useBrowserRecommendedResolution Boolean <optional>
true 如果为true,则以浏览器建议的分辨率渲染,并忽略window.devicePixelRatio
automaticallyTrackDataSourceClocks Boolean <optional>
true 如果为true,此小部件将自动跟踪新添加数据源的时钟设置,并在数据源的时钟更改时更新。如果要独立配置时钟,请将此设置为false。
contextOptions Object <optional>
options对应的上下文和WebGL创建属性传递给Scene
sceneMode SceneMode <optional>
SceneMode.SCENE3D 初始场景模式。
mapProjection MapProjection <optional>
new GeographicProjection() 要在二维和哥伦布视图模式中使用的地图投影。
globe Globe | false <optional>
new Globe(mapProjection.ellipsoid) 要在场景中使用的地球仪。如果设置为false,则不会添加任何球体。
orderIndependentTranslucency Boolean <optional>
true 如果为true且配置支持它,请使用与顺序无关的半透明。
creditContainer Element | String <optional>
将包含CreditDisplay的DOM元素或ID。如果未指定,则信用证将添加到小部件本身的底部。
creditViewport Element | String <optional>
包含CreditDisplay创建的信用弹出窗口的DOM元素或ID。如果没有指定,它将出现在小部件本身的上方。
dataSources DataSourceCollection <optional>
new DataSourceCollection() 由小部件可视化的数据源集合。如果提供了此参数, 当调用方不被销毁时,该实例将被假定为不被销毁。
terrainExaggeration Number <optional>
1.0 用来夸大地形的标量。请注意,地形放大不会修改任何其他基本体,因为它们相对于椭球体定位。
shadows Boolean <optional>
false 确定阴影是否由光源投射。
terrainShadows ShadowMode <optional>
ShadowMode.RECEIVE_ONLY 确定地形是投射还是接收来自光源的阴影。
mapMode2D MapMode2D <optional>
MapMode2D.INFINITE_SCROLL 确定二维贴图是可旋转的还是可以在水平方向无限滚动。
projectionPicker Boolean <optional>
false 如果设置为true,将创建ProjectionPicker小部件。
requestRenderMode Boolean <optional>
false 如果为true,则仅在需要时渲染帧(由场景中的更改决定)。启用可减少应用程序的CPU/GPU使用量,并在移动设备上使用更少的电池,但需要使用Scene#requestRender在这种模式下显式呈现新帧。在许多情况下,在API的其他部分对场景进行更改后,这是必需的。见Improving Performance with Explicit Rendering
maximumRenderTimeChange Number <optional>
0.0 如果requestRenderMode为true,则此值定义请求渲染之前允许的模拟时间的最大更改。见Improving Performance with Explicit Rendering

Cesium.Viewer.ViewerMixin(viewer, options)

用附加功能扩充查看器实例的函数。
Name Type Description
viewer Viewer 查看器实例。
options Object 要传递给mixin函数的Options对象。
See: