包含 Cesium 场景的小部件。 A widget containing a Cesium scene.
| 名称 Name |
类型 Type |
说明 Description |
container |
Element
|
string
|
将包含小部件的 DOM 元素或 ID。 The DOM element or ID that will contain the widget. |
options |
object
|
可选 optional
具有以下属性的对象: Object with the following properties:
| 名称 Name |
类型 Type |
默认值 Default |
说明 Description |
clock |
Clock
|
new Clock()
|
可选 optional
用于控制当前时间的时钟。 The clock to use to control current time. |
shouldAnimate |
boolean
|
false
|
可选 optional
true 如果时钟默认尝试提前模拟时间, if the clock should attempt to advance simulation time by default, false otherwise. |
ellipsoid |
Ellipsoid
|
Ellipsoid.default
|
可选 optional
默认椭球体。 The default ellipsoid. |
baseLayer |
ImageryLayer
|
false
|
ImageryLayer.fromWorldImagery()
|
可选 optional
应用于地球的最底层图像层。如果设置为 The bottommost imagery layer applied to the globe. If set to false,不会添加任何图像提供者。 , no imagery provider will be added. |
terrainProvider |
TerrainProvider
|
new EllipsoidTerrainProvider(options.ellipsoid)
|
可选 optional
地形提供者。 The terrain provider. |
terrain |
Terrain
|
|
可选 optional
处理异步地形提供者的地形对象。仅当 options.terrainProvider 未定义时才能指定。 A terrain object which handles asynchronous terrain provider. Can only specify if options.terrainProvider is undefined. |
skyBox |
SkyBox
|
false
|
|
可选 optional
用于渲染星星的天空盒。当 The skybox used to render the stars. When undefined 和使用的WGS84椭球体,使用默认的星星。如果设置为 and the WGS84 ellipsoid used, the default stars are used. If set to false,不会添加天空盒、太阳或月亮。 , no skyBox, Sun, or Moon will be added. |
skyAtmosphere |
SkyAtmosphere
|
false
|
|
可选 optional
蓝色的天空,以及地球边缘周围的光芒。使用默认椭球体时启用。设置为 Blue sky, and the glow around the Earth's limb. Enabled when the default ellipsoid used. Set to false 将其关闭。 to turn it off. |
sceneMode |
SceneMode
|
SceneMode.SCENE3D
|
可选 optional
初始场景模式。 The initial scene mode. |
scene3DOnly |
boolean
|
false
|
可选 optional
When true,每个几何实例将仅以 3D 形式渲染以节省 GPU 内存。 , each geometry instance will only be rendered in 3D to save GPU memory. |
orderIndependentTranslucency |
boolean
|
true
|
可选 optional
如果为 true 并且配置支持它,则使用顺序无关的半透明。 If true and the configuration supports it, use order independent translucency. |
mapProjection |
MapProjection
|
new GeographicProjection(options.ellipsoid)
|
可选 optional
在 2D 和哥伦布视图模式下使用的地图投影。 The map projection to use in 2D and Columbus View modes. |
globe |
Globe
|
false
|
new Globe(options.ellipsoid)
|
可选 optional
在场景中使用的地球仪。如果设置为 The globe to use in the scene. If set to false,不会添加地球仪,并且默认隐藏天空大气。 , no globe will be added and the sky atmosphere will be hidden by default. |
useDefaultRenderLoop |
boolean
|
true
|
可选 optional
如果此小部件应控制渲染循环,则为 true,否则为 false。 True if this widget should control the render loop, false otherwise. |
useBrowserRecommendedResolution |
boolean
|
true
|
可选 optional
如果为 true,则以浏览器建议的分辨率渲染并忽略 If true, render at the browser's recommended resolution and ignore window.devicePixelRatio. |
targetFrameRate |
number
|
|
可选 optional
使用默认渲染循环时的目标帧速率。 The target frame rate when using the default render loop. |
showRenderLoopErrors |
boolean
|
true
|
可选 optional
如果为 true,则如果发生渲染循环错误,此小部件将自动向用户显示包含错误的 HTML 面板。 If true, this widget will automatically display an HTML panel to the user containing the error, if a render loop error occurs. |
automaticallyTrackDataSourceClocks |
boolean
|
true
|
可选 optional
如果为 true,则此小部件将自动跟踪新添加的数据源的时钟设置,并在数据源的时钟发生变化时进行更新。如果您想独立配置时钟,请将此设置为 false。 If true, this widget will automatically track the clock settings of newly added DataSources, updating if the DataSource's clock changes. Set this to false if you want to configure the clock independently. |
contextOptions |
ContextOptions
|
|
可选 optional
上下文和 WebGL 创建属性传递给 Context and WebGL creation properties passed to Scene. |
creditContainer |
Element
|
string
|
|
可选 optional
将包含的 DOM 元素或 ID The DOM element or ID that will contain the CreditDisplay。如果未指定,积分将添加到小部件本身的底部。 . If not specified, the credits are added to the bottom of the widget itself. |
creditViewport |
Element
|
string
|
|
可选 optional
将包含由创建的信用弹出窗口的 DOM 元素或 ID The DOM element or ID that will contain the credit pop up created by the CreditDisplay。如果未指定,它将显示在小部件本身之上。 . If not specified, it will appear over the widget itself. |
dataSources |
DataSourceCollection
|
new DataSourceCollection()
|
可选 optional
由小部件可视化的数据源的集合。如果提供此参数,则假定该实例由调用者拥有,并且在销毁小部件时不会被销毁。 The collection of data sources visualized by the widget. If this parameter is provided, the instance is assumed to be owned by the caller and will not be destroyed when the widget is destroyed. |
shadows |
boolean
|
false
|
可选 optional
确定光源是否投射阴影。 Determines if shadows are cast by light sources. |
terrainShadows |
ShadowMode
|
ShadowMode.RECEIVE_ONLY
|
可选 optional
确定地形是否投射或接收来自光源的阴影。 Determines if the terrain casts or receives shadows from light sources. |
mapMode2D |
MapMode2D
|
MapMode2D.INFINITE_SCROLL
|
可选 optional
确定 2D 地图是否可旋转或可在水平方向无限滚动。 Determines if the 2D map is rotatable or can be scrolled infinitely in the horizontal direction. |
blurActiveElementOnCanvasFocus |
boolean
|
true
|
可选 optional
如果为 true,则当单击小部件的画布时,活动元素将变得模糊。当单击画布仅用于检索位置或实体数据而不实际意味着将画布设置为活动元素时,将此设置为 false 非常有用。 If true, the active element will blur when the widget's canvas is clicked. Setting this to false is useful for cases when the canvas is clicked only for retrieving position or an entity data without actually meaning to set the canvas to be the active element. |
requestRenderMode |
boolean
|
false
|
可选 optional
如果为 true,则仅在需要时才会渲染帧,具体取决于场景内的变化。启用可提高应用程序的性能,但需要使用 If true, rendering a frame will only occur when needed as determined by changes within the scene. Enabling improves performance of the application, but requires using Scene#requestRender 在此模式下显式渲染新帧。在许多情况下,在 API 其他部分更改场景后,这是必要的。参见 to render a new frame explicitly in this mode. This will be necessary in many cases after making changes to the scene in other parts of the API. See Improving Performance with Explicit Rendering. |
maximumRenderTimeChange |
number
|
0.0
|
可选 optional
如果 requestRenderMode 为 true,则该值定义请求渲染之前允许的模拟时间的最大变化。参见 If requestRenderMode is true, this value defines the maximum change in simulation time allowed before a render is requested. See Improving Performance with Explicit Rendering. |
msaaSamples |
number
|
4
|
可选 optional
如果提供,该值控制多重采样抗锯齿的速率。典型的多重采样率为每像素 2 个、4 个,有时甚至 8 个样本。较高的 MSAA 采样率可能会影响性能,但会提高视觉质量。该值仅适用于支持多重采样渲染目标的 WebGL2 上下文。设置为 1 以禁用 MSAA。 If provided, this value controls the rate of multisample antialiasing. Typical multisampling rates are 2, 4, and sometimes 8 samples per pixel. Higher sampling rates of MSAA may impact performance in exchange for improved visual quality. This value only applies to WebGL2 contexts that support multisample render targets. Set to 1 to disable MSAA. |
|
抛出: Throws:
-
DeveloperError
:文档中不存在 ID 为“container”的元素。
: Element with id "container" does not exist in the document.
示例: Example:
// For each example, include a link to CesiumWidget.css stylesheet in HTML head,
// and in the body, include: <div id="cesiumContainer"></div>
// Widget with no terrain and default Bing Maps imagery provider.
const widget = new Cesium.CesiumWidget("cesiumContainer");
// Widget with ion imagery and Cesium World Terrain.
const widget2 = new Cesium.CesiumWidget("cesiumContainer", {
baseLayer: Cesium.ImageryLayer.fromWorldTerrain(),
terrain: Cesium.Terrain.fromWorldTerrain()
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
sceneMode: Cesium.SceneMode.COLUMBUS_VIEW,
mapProjection: new Cesium.WebMercatorProjection()
});
演示: Demo:
成员 Members
获取或设置数据源是否可以暂时暂停动画以避免向用户显示不完整的图片。例如,如果在后台处理异步基元,则在几何体准备好之前,时钟将不会前进。 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.
拿到相机。 Gets the camera.
获取画布。 Gets the canvas.
获取时钟。 Gets the clock.
获取或设置要跟踪小部件时钟的数据源。 Gets or sets the data source to track with the widget's clock.
获取父容器。 Gets the parent container.
获取信用容器。 Gets the credit container.
管理要在屏幕和灯箱中显示的制作人员列表。 Manages the list of credits to display on screen and in the lightbox.
获取信用视口 Gets the credit viewport
获取用于的显示
Gets the display used for DataSource visualization.
得到的集合为
Gets the set of DataSource 要可视化的实例。
instances to be visualized.
获取场景的默认椭球体。 Gets the default ellipsoid for the scene.
获取将在地球上渲染的图像图层的集合。 Gets the collection of image layers that will be rendered on the globe.
获取或设置渲染分辨率的比例因子。小于 1.0 的值可以提高功能较弱的设备上的性能,而大于 1.0 的值将以更高的分辨率渲染,然后按比例缩小,从而提高视觉保真度。例如,如果小部件的布局尺寸为 640x480,则将此值设置为 0.5 将导致场景以 320x240 渲染,然后放大,而设置为 2.0 将导致场景以 1280x960 渲染,然后缩小。 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
获取场景。 Gets the scene.
获取屏幕空间事件处理程序。 Gets the screen space event handler.
获取或设置小部件的目标帧速率 Gets or sets the target frame rate of the widget when useDefaultRenderLoop
是真的。如果未定义,则浏览器的 requestAnimationFrame 实现确定帧速率。如果定义,该值必须大于 0。高于底层 requestAnimationFrame 实现的值将无效。 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.
地形提供者为地球提供表面几何形状。 The terrain provider providing surface geometry for the globe.
获取或设置相机当前正在跟踪的Entity实例。 Gets or sets the Entity instance currently being tracked by the camera.
获取当跟踪的实体发生更改时引发的事件。 Gets the event that is raised when the tracked entity changes.
布尔标志,指示是否使用浏览器推荐的分辨率。如果为 true,则忽略浏览器的设备像素比并使用 1.0,从而有效地基于 CSS 像素而不是设备像素进行渲染。这可以提高具有高像素密度的功能较弱的设备的性能。当为 false 时,渲染将以设备像素为单位。
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. CesiumWidget#resolutionScale 无论该标志为真还是假,都仍然有效。
will still take effect whether this flag is true or false.
true
获取或设置此小部件是否应控制渲染循环。如果为 true,小部件将使用 requestAnimationFrame 来执行小部件的渲染和调整大小,以及驱动模拟时钟。如果设置为 false,则必须手动调用
Gets or sets whether or not this widget should control the render loop. If 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 将引发事件并且该属性将设置为 false。必须将其设置回 true 才能在错误发生后继续渲染。
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.
方法 Methods
销毁小部件。如果从布局中永久删除小部件,则应调用。 Destroys the widget. Should be called if permanently removing the widget from layout.
将相机飞行到提供的一个或多个实体或数据源。如果数据源仍在加载过程中或可视化仍在加载中,则此方法会在执行飞行之前等待数据准备就绪。
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.
偏移量是以边界球体中心为中心的局部东西向参考系中的航向/俯仰/范围。航向角和俯仰角在当地的东西向参考系中定义。航向是与 y 轴的角度并朝 x 轴增加。俯仰角是相对于 xy 平面的旋转。正俯仰角位于平面上方。负俯仰角位于平面下方。范围是距中心的距离。如果范围为零,则将计算一个范围,使得整个边界球体可见。 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.
在 2D 中,必须有一个自顶向下的视图。相机将放置在目标上方,俯视。目标上方的高度将是范围。航向将根据偏移量确定。如果无法根据偏移确定航向,则航向将为北。 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.
返回: Returns:
如果飞行成功,则 Promise 解析为 true;如果目标当前未在场景中可视化或飞行被取消,则解析为 false。 //TODO: 清理实体提及 A Promise that resolves to true if the flight was successful or false if the target is not currently visualized in the scene or the flight was cancelled. //TODO: Cleanup entity mentions
返回: Returns:
如果对象已被销毁,则为 true,否则为 false。 true if the object has been destroyed, false otherwise.
渲染场景。该函数会自动调用,除非 Renders the scene. This function is called automatically unless useDefaultRenderLoop 设置为 false; is set to false;
更新画布大小、相机纵横比和视口大小。该函数会根据需要自动调用,除非 Updates the canvas size, camera aspect ratio, and viewport size. This function is called automatically as needed unless
useDefaultRenderLoop 设置为 false。 is set to false.
向用户显示一个错误面板,其中包含标题和较长的错误消息,可以使用“确定”按钮将其关闭。如果在构造小部件时 showRenderLoopErrors 不为 false,则当发生渲染循环错误时,会自动显示此面板。 Show an error panel to the user containing a title and a longer error message, which can be dismissed using an OK button. This panel is displayed automatically when a render loop error occurs, if showRenderLoopErrors was not false when the widget was constructed.
| 名称 Name |
类型 Type |
说明 Description |
title |
string
|
要在错误面板上显示的标题。该字符串被解释为文本。 The title to be displayed on the error panel. This string is interpreted as text. |
message |
string
|
可选 optional
在详细错误信息之前显示一条有用的、面向用户的消息。该字符串被解释为 HTML。 A helpful, user-facing message to display prior to the detailed error information. This string is interpreted as HTML. |
error |
string
|
可选 optional
要在错误面板上显示的错误。该字符串的格式使用 The error to be displayed on the error panel. This string is formatted using formatError 然后显示为文本。 and then displayed as text. |
异步设置相机以查看提供的一个或多个实体或数据源。如果数据源仍在加载过程中或可视化仍在加载,则此方法将等待数据准备好后再执行缩放。
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.
偏移量是以边界球体中心为中心的局部东西向参考系中的航向/俯仰/范围。航向角和俯仰角在当地的东西向参考系中定义。航向是与 y 轴的角度并朝 x 轴增加。俯仰角是相对于 xy 平面的旋转。正俯仰角位于平面上方。负俯仰角位于平面下方。范围是距中心的距离。如果范围为零,则将计算一个范围,使得整个边界球体可见。 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.
在 2D 中,必须有一个自顶向下的视图。相机将放置在目标上方,俯视。目标上方的高度将是范围。航向将根据偏移量确定。如果无法根据偏移确定航向,则航向将为北。 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.
返回: Returns:
如果缩放成功,则 Promise 解析为 true;如果目标当前未在场景中可视化或缩放被取消,则解析为 false。 A Promise that resolves to true if the zoom was successful or false if the target is not currently visualized in the scene or the zoom was cancelled.