English中文

Scene

new Cesium.Scene(options)

Cesium 虚拟场景中所有 3D 图形对象和状态的容器。一般来说,场景不是直接创建的;相反,它是由隐式创建的 The container for all 3D graphical objects and state in a Cesium virtual scene. Generally, a scene is not created directly; instead, it is implicitly created by CesiumWidget.
名称 Name 类型 Type 说明 Description
options object 具有以下属性的对象: Object with the following properties:
名称 Name 类型 Type 默认值 Default 说明 Description
canvas HTMLCanvasElement 用于创建场景的 HTML 画布元素。 The HTML canvas element to create the scene for.
contextOptions ContextOptions 可选 optional 上下文和 WebGL 创建属性。 Context and WebGL creation properties.
creditContainer Element 可选 optional 将显示制作人员名单的 HTML 元素。如果未指定,将创建一个信用容器并将其添加为画布的同级容器。 The HTML element in which the credits will be displayed. If not specified, a credit container will be created and added as a sibling of the canvas.
creditViewport Element 可选 optional 用于显示信用弹出窗口的 HTML 元素。如果未指定,视口将添加为画布的同级。 The HTML element in which to display the credit popup. If not specified, the viewport will be added as a sibling of the canvas.
ellipsoid Ellipsoid Ellipsoid.default 可选 optional 默认椭球体。如果未指定,则使用默认椭球体。 The default ellipsoid. If not specified, the default ellipsoid is used.
mapProjection MapProjection new GeographicProjection(options.ellipsoid) 可选 optional 在 2D 和哥伦布视图模式下使用的地图投影。 The map projection to use in 2D and Columbus View modes.
orderIndependentTranslucency boolean true 可选 optional 如果为 true 并且配置支持它,则使用顺序无关的半透明。 If true and the configuration supports it, use order independent translucency.
scene3DOnly boolean false 可选 optional 如果为 true,则优化 3D 模式的内存使用和性能,但禁用使用 2D 或哥伦布视图的功能。 If true, optimizes memory use and performance for 3D mode but disables the ability to use 2D or Columbus View.
shadows boolean false 可选 optional 确定光源是否投射阴影。 Determines if shadows are cast by 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.
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.
depthPlaneEllipsoidOffset number 0.0 可选 optional 调整深度平面以解决椭球零高程以下的渲染伪影。 Adjust the DepthPlane to address rendering artefacts below ellipsoid zero elevation.
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 : options 和 options.canvas 是必需的。 : options and options.canvas are required.
示例: Example:
// Create scene without anisotropic texture filtering
const scene = new Cesium.Scene({
  canvas : canvas,
  contextOptions : {
    allowTextureFilterAnisotropic : false
  }
});
另见: See:

成员 Members

static Cesium.Scene.defaultLogDepthBuffer

使用它来设置默认值 Use this to set the default value for Scene#logarithmicDepthBuffer 在新构建的场景中,此属性依赖于所支持的fragmentDepth。 in newly constructed Scenes This property relies on fragmentDepth being supported.

_enableEdgeVisibility : boolean

是否启用 3D 图块的边缘可见性渲染。启用后,创建具有多个渲染目标的帧缓冲区,以实现高级边缘检测和可见性技术。 Whether or not to enable edge visibility rendering for 3D tiles. When enabled, creates a framebuffer with multiple render targets for advanced edge detection and visibility techniques.
默认值: Default Value: false
影响 3D Tiles 和模型渲染的气氛照明效果的设置。这不要与 Settings for atmosphere lighting effects affecting 3D Tiles and model rendering. This is not to be confused with Scene#skyAtmosphere 它负责渲染天空。 which is responsible for rendering the sky.
背景颜色,仅在没有天空盒时才可见,即 The background color, which is only visible if there is no sky box, i.e., Scene#skyBox is undefined.
默认值: Default Value: Color.BLACK
另见: See:
获取或设置相机。 Gets or sets the camera.

readonly cameraUnderground : boolean

相机是否位于地球下方。 Whether or not the camera is underneath the globe.
默认值: Default Value: false

readonly canvas : HTMLCanvasElement

获取此场景绑定到的画布元素。 Gets the canvas element to which this scene is bound.

readonly clampToHeightSupported : boolean

Returns true 如果 if the Scene#clampToHeight and Scene#clampToHeightMostDetailed 支持功能。 functions are supported.
另见: See:

completeMorphOnUserInput : boolean

确定是否在用户输入时立即完成场景过渡动画。 Determines whether or not to instantly complete the scene transition animation on user input.
默认值: Default Value: true

debugCommandFilter : function|undefined

该属性仅用于调试;它不用于生产用途。 This property is for debugging only; it is not for production use.

确定执行哪些命令的函数。如下例所示,该函数接收命令的 A function that determines what commands are executed. As shown in the examples below, the function receives the command's owner 作为参数,并返回一个布尔值,指示是否应执行该命令。 as an argument, and returns a boolean indicating if the command should be executed.

默认为 The default is undefined,表示所有命令都已执行。 , indicating that all commands are executed.

默认值: Default Value: undefined
示例: Example:
// Do not execute any commands.
scene.debugCommandFilter = function(command) {
    return false;
};

// Execute only the billboard's commands.  That is, only draw the billboard.
const billboards = new Cesium.BillboardCollection();
scene.debugCommandFilter = function(command) {
    return command.owner === billboards;
};

readonly debugFrustumStatistics : object|undefined

该属性仅用于调试;它不用于生产用途。 This property is for debugging only; it is not for production use.

When Scene.debugShowFrustums is true,这包含有关每个视锥体的命令执行数量统计信息的属性。 , this contains properties with statistics about the number of command execute per frustum. totalCommands 是执行的命令总数,忽略重叠。 is the total number of commands executed, ignoring overlap. commandsInFrustums 是一个数组,其中包含命令冗余执行的次数,例如,有多少命令重叠两个或三个视锥体。 is an array with the number of times commands are executed redundantly, e.g., how many commands overlap two or three frustums.

默认值: Default Value: undefined

debugShowCommands : boolean

该属性仅用于调试;它不用于生产用途。 This property is for debugging only; it is not for production use.

When true,命令随机着色。这对于性能分析非常有用,可以查看场景或模型的哪些部分命令密集并且可以从批处理中受益。 , commands are randomly shaded. This is useful for performance analysis to see what parts of a scene or model are command-dense and could benefit from batching.

默认值: Default Value: false

debugShowDepthFrustum : number

该属性仅用于调试;它不用于生产用途。 This property is for debugging only; it is not for production use.

指示哪个视锥体将显示深度信息。 Indicates which frustum will have depth information displayed.

默认值: Default Value: 1

debugShowFramesPerSecond : boolean

该属性仅用于调试;它不用于生产用途。 This property is for debugging only; it is not for production use.

显示每秒帧数和帧之间的时间。 Displays frames per second and time between frames.

默认值: Default Value: false

debugShowFrustumPlanes : boolean

该属性仅用于调试;它不用于生产用途。 This property is for debugging only; it is not for production use.

When true,绘制轮廓以显示相机视锥体的边界 , draws outlines to show the boundaries of the camera frustums

默认值: Default Value: false

debugShowFrustums : boolean

该属性仅用于调试;它不用于生产用途。 This property is for debugging only; it is not for production use.

When true,命令根据它们重叠的截锥体进行着色。最近的视锥体中的命令为红色,次近的视锥体中的命令为绿色,最远的视锥体中的命令为蓝色。如果命令与多个视锥体重叠,则颜色分量将被组合,例如,与前两个视锥体重叠的命令被染成黄色。 , commands are shaded based on the frustums they overlap. Commands in the closest frustum are tinted red, commands in the next closest are green, and commands in the farthest frustum are blue. If a command overlaps more than one frustum, the color components are combined, e.g., a command overlapping the first two frustums is tinted yellow.

默认值: Default Value: false

readonly drawingBufferHeight : number

底层 GL 上下文的绘图缓冲区高度。 The drawingBufferHeight of the underlying GL context.
另见: See:

readonly drawingBufferWidth : number

底层 GL 上下文的绘图缓冲区宽度。 The drawingBufferWidth of the underlying GL context.
另见: See:
椭球体。如果未指定,则使用默认椭球体。 The ellipsoid. If not specified, the default ellipsoid is used.

eyeSeparation : number

用于 Cardboard 或 WebVR 的眼睛间隔距离(以米为单位)。 The eye separation distance in meters for use with cardboard or WebVR.

farToNearRatio : number

使用普通深度缓冲区时多视锥体的远近比。 The far-to-near ratio of the multi-frustum when using a normal depth buffer.

该值用于为多截锥体的每个截锥体创建近距值和远距值。它仅在以下情况下使用 This value is used to create the near and far values for each frustum of the multi-frustum. It is only used when Scene#logarithmicDepthBuffer is false。当 . When logarithmicDepthBuffer is true, 使用 , use Scene#logarithmicDepthFarToNearRatio.

默认值: Default Value: 1000.0

focalLength : number

使用 Cardboard 或 WebVR 时使用的焦距。 The focal length for use when with cardboard or WebVR.
将大气与远离相机的几何体混合以获取地平线视图。通过渲染更少的几何图形和分派更少的地形请求,可以进一步提高性能。如果使用 WGS84 以外的椭球体,则默认禁用。 Blends the atmosphere to geometry far from the camera for horizon views. Allows for additional performance improvements by rendering less geometry and dispatching less terrain requests. Disbaled by default if an ellipsoid other than WGS84 is used.
用于伽玛校正的值。这只在高动态范围渲染时使用。 The value used for gamma correction. This is only used when rendering with high dynamic range.
默认值: Default Value: 2.2
获取或设置深度测试椭球体。 Gets or sets the depth-test ellipsoid.
获取地面图元的集合。 Gets the collection of ground primitives.

highDynamicRange : boolean

是否使用高动态范围渲染。 Whether or not to use high dynamic range rendering.
默认值: Default Value: false

readonly highDynamicRangeSupported : boolean

是否支持高动态范围渲染。 Whether or not high dynamic range rendering is supported.
默认值: Default Value: true

readonly id : string

获取该场景的唯一标识符。 Gets the unique identifier for this scene.
获取将在地球上渲染的图像图层的集合。 Gets the collection of image layers that will be rendered on the globe.

invertClassification : boolean

When false,3D Tiles 将正常渲染。当 , 3D Tiles will render normally. When true,分类的 3D Tile 几何体将正常渲染,未分类的 3D Tile 几何体将使用颜色乘以 , classified 3D Tile geometry will render normally and unclassified 3D Tile geometry will render with the color multiplied by Scene#invertClassificationColor.
默认值: Default Value: false

invertClassificationColor : Color

未分类 3D Tile 几何体时的高亮颜色 The highlight color of unclassified 3D Tile geometry when Scene#invertClassification is true.

当颜色的 Alpha 小于 1.0 时,3D 图块的未分类部分将无法与 3D 图块的分类位置正确混合。 When the color's alpha is less than 1.0, the unclassified portions of the 3D Tiles will not blend correctly with the classified positions of the 3D Tiles.

此外,当颜色的 alpha 小于 1.0 时,必须支持 WEBGL_depth_texture 和 EXT_frag_depth WebGL 扩展。 Also, when the color's alpha is less than 1.0, the WEBGL_depth_texture and EXT_frag_depth WebGL extensions must be supported.

默认值: Default Value: Color.WHITE

readonly invertClassificationSupported : boolean

Returns true 如果 if the Scene#invertClassification 是支持的。 is supported.
另见: See:

readonly lastRenderTime : JulianDate|undefined

获取场景上次渲染时的模拟时间。退货 Gets the simulation time when the scene was last rendered. Returns undefined 如果场景尚未渲染。 if the scene has not yet been rendered.
用于遮光的光源。默认为来自太阳的定向光。 The light source for shading. Defaults to a directional light from the Sun.

logarithmicDepthBuffer : boolean

是否使用对数深度缓冲区。启用此选项将允许减少多截锥体中的截锥体,从而提高性能。此属性依赖于所支持的fragmentDepth。 Whether or not to use a logarithmic depth buffer. Enabling this option will allow for less frustums in the multi-frustum, increasing performance. This property relies on fragmentDepth being supported.

logarithmicDepthFarToNearRatio : number

使用对数深度缓冲区时多平截头体的远近比。 The far-to-near ratio of the multi-frustum when using a logarithmic depth buffer.

该值用于为多截锥体的每个截锥体创建近距值和远距值。它仅在以下情况下使用 This value is used to create the near and far values for each frustum of the multi-frustum. It is only used when Scene#logarithmicDepthBuffer is true。当 . When logarithmicDepthBuffer is false, 使用 , use Scene#farToNearRatio.

默认值: Default Value: 1e9
确定 2D 地图是否可旋转或可在水平方向无限滚动。 Determines if the 2D map is rotatable or can be scrolled infinitely in the horizontal direction.
获取在 2D 和哥伦布视图模式下使用的地图投影。 Get the map projection to use in 2D and Columbus View modes.
默认值: Default Value: new GeographicProjection()

readonly maximumAliasedLineWidth : number

此 WebGL 实现支持的最大别名线宽度(以像素为单位)。至少会有一个。 The maximum aliased line width, in pixels, supported by this WebGL implementation. It will be at least one.
另见: See:
  • glGet with ALIASED_LINE_WIDTH_RANGE.

readonly maximumCubeMapSize : number

此 WebGL 实现支持的立方体贴图一条边的最大长度(以像素为单位)。至少会是16个。 The maximum length in pixels of one edge of a cube map, supported by this WebGL implementation. It will be at least 16.
另见: See:
  • glGet with GL_MAX_CUBE_MAP_TEXTURE_SIZE.

maximumRenderTimeChange : number

If Scene#requestRenderMode is true,该值定义请求渲染之前允许的模拟时间的最大变化。较低的值会增加渲染的帧数,较高的值会减少渲染的帧数。如果 , this value defines the maximum change in simulation time allowed before a render is requested. Lower values increase the number of frames rendered and higher values decrease the number of frames rendered. If undefined,对模拟时间的更改永远不会请求渲染。该值会影响场景中变化(例如光照、实体属性更新和动画)的渲染速率。 , changes to the simulation time will never request a render. This value impacts the rate of rendering for changes in the scene like lighting, entity property updates, and animations.
默认值: Default Value: 0.0
另见: See:

minimumDisableDepthTestDistance : number

禁用广告牌、标签和点的深度测试的距相机的距离,例如,防止地形剪切。当设置为零时,应始终应用深度测试。当小于零时,不应应用深度测试。设置广告牌、标签或点的disableDepthTestDistance属性将覆盖该值。 The distance from the camera at which to disable the depth test of billboards, labels and points to, for example, prevent clipping against terrain. When set to zero, the depth test should always be applied. When less than zero, the depth test should never be applied. Setting the disableDepthTestDistance property of a billboard, label or point will override this value.
默认值: Default Value: 0.0
获取或设置场景的当前模式。 Gets or sets the current mode of the scene.
默认值: Default Value: SceneMode.SCENE3D
The Moon
默认值: Default Value: undefined
该事件在场景转换完成时触发。 The event fired at the completion of a scene transition.
默认值: Default Value: Event()
该事件在场景转换开始时触发。 The event fired at the beginning of a scene transition.
默认值: Default Value: Event()
2D/哥伦布视图和 3D 之间的当前变形过渡时间,0.0 为 2D 或哥伦布视图,1.0 为 3D。 The current morph transition time between 2D/Columbus View and 3D, with 0.0 being 2D or Columbus View and 1.0 being 3D.
默认值: Default Value: 1.0

msaaSamples : number

多重采样抗锯齿的采样率(大于 1 的值启用 MSAA)。 The sample rate of multisample antialiasing (values greater than 1 enable MSAA).
默认值: Default Value: 4

readonly msaaSupported : boolean

Returns true 如果场景的上下文支持 MSAA。 if the Scene's context supports MSAA.

nearToFarDistance2D : number

确定二维多平截头体的每个平截头体的统一深度尺寸(以米为单位)。如果接近表面的图元或模型显示 z-fighting,减少此值将消除伪影,但会降低性能。另一方面,增加这个值会提高性能,但可能会导致靠近表面的基元之间发生 z 冲突。 Determines the uniform depth size in meters of each frustum of the multifrustum in 2D. If a primitive or model close to the surface shows z-fighting, decreasing this will eliminate the artifact, but decrease performance. On the other hand, increasing this will increase performance but may cause z-fighting among primitives close to the surface.
默认值: Default Value: 1.75e6

readonly orderIndependentTranslucency : boolean

获取场景是否启用了顺序独立半透明。请注意,这仅反映了原始构建选项,还有其他因素可能会阻止 OIT 在给定的系统配置上运行。 Gets whether or not the scene has order independent translucency enabled. Note that this only reflects the original construction option, and there are other factors that could prevent OIT from functioning on a given system configuration.

readonly pickPositionSupported : boolean

Returns true 如果 if the Scene#pickPosition 支持功能。 function is supported.
另见: See:

pickTranslucentDepth : boolean

When true,允许使用深度缓冲区拾取半透明几何体。请注意 , enables picking translucent geometry using the depth buffer. Note that Scene#useDepthPicking 也必须如此才能使其发挥作用。 must also be true for enabling this to work.

启用后性能会下降。有额外的绘制调用来写入半透明几何体的深度。 There is a decrease in performance when enabled. There are extra draw calls to write depth for translucent geometry.

默认值: Default Value: false
示例: Example:
// picking the position of a translucent primitive
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
     const pickedFeature = viewer.scene.pick(movement.position);
     if (!Cesium.defined(pickedFeature)) {
         // nothing picked
         return;
     }
     const worldPosition = viewer.scene.pickPosition(movement.position);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
应用于最终渲染的后处理效果。 Post processing effects applied to the final render.
获取场景渲染后立即引发的事件。事件的订阅者接收场景实例作为第一个参数,当前时间作为第二个参数。 Gets the event that will be raised immediately after the scene is rendered. Subscribers to the event receive the Scene instance as the first parameter and the current time as the second parameter.
另见: See:
获取在场景更新后和渲染场景之前立即引发的事件。事件的订阅者接收场景实例作为第一个参数,当前时间作为第二个参数。 Gets the event that will be raised immediately after the scene is updated and before the scene is rendered. Subscribers to the event receive the Scene instance as the first parameter and the current time as the second parameter.
另见: See:
获取在场景更新之后和渲染场景之前将引发的事件。事件的订阅者接收场景实例作为第一个参数,当前时间作为第二个参数。 Gets the event that will be raised after the scene is updated and immediately before the scene is rendered. Subscribers to the event receive the Scene instance as the first parameter and the current time as the second parameter.
另见: See:
获取在更新或渲染场景之前将引发的事件。事件的订阅者接收场景实例作为第一个参数,当前时间作为第二个参数。 Gets the event that will be raised before the scene is updated or rendered. Subscribers to the event receive the Scene instance as the first parameter and the current time as the second parameter.
另见: See:
获取基元的集合。 Gets the collection of primitives.

readonly renderError : Event

获取内部抛出错误时将引发的事件 Gets the event that will be raised when an error is thrown inside the render 功能。场景实例和抛出的错误是传递给事件处理程序的唯一两个参数。默认情况下,引发此事件后不会重新引发错误,但可以通过设置来更改 function. The Scene instance and the thrown error are the only two parameters passed to the event handler. By default, errors are not rethrown after this event is raised, but that can be changed by setting the rethrowRenderErrors property.

requestRenderMode : boolean

When 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.
默认值: Default Value: false
另见: See:

rethrowRenderErrors : boolean

异常发生在 Exceptions occurring in render 总是被抓住以提高 are always caught in order to raise the renderError 事件。如果此属性为 true,则在引发事件后将重新引发错误。如果该属性为 false,则 event. If this property is true, the error is rethrown after the event is raised. If this property is false, the render 函数在引发事件后正常返回。 function returns normally after raising the event.
默认值: Default Value: false

readonly sampleHeightSupported : boolean

Returns true 如果 if the Scene#sampleHeight and Scene#sampleHeightMostDetailed 支持功能。 functions are supported.
另见: See:

readonly scene3DOnly : boolean

获取场景是否针对仅 3D 观看进行了优化。 Gets whether or not the scene is optimized for 3D only viewing.

readonly screenSpaceCameraController : ScreenSpaceCameraController

获取用于相机输入处理的控制器。 Gets the controller for camera input handling.
场景光源的阴影贴图。启用后,模型、图元和地球可以投射和接收阴影。 The shadow map for the scene's light source. When enabled, models, primitives, and the globe may cast and receive shadows.
绘制全球各地的天空气氛。 The sky atmosphere drawn around the globe.
默认值: Default Value: undefined
The SkyBox 用来画星星。 used to draw the stars.
默认值: Default Value: undefined
另见: See:

specularEnvironmentMaps : string

KTX2 文件的 url,其中包含镜面反射环境贴图和用于 PBR 模型基于图像的照明的复杂 mipmap。 The url to the KTX2 file containing the specular environment map and convoluted mipmaps for image-based lighting of PBR models.

readonly specularEnvironmentMapsSupported : boolean

Returns true 是否支持镜面环境贴图。 if specular environment maps are supported.
另见: See:

sphericalHarmonicCoefficients : Array.<Cartesian3>

PBR 模型基于图像的照明的球谐系数。 The spherical harmonic coefficients for image-based lighting of PBR models.

splitPosition : number

获取或设置分割器在视口中的位置。有效值介于 0.0 和 1.0 之间。 Gets or sets the position of the splitter within the viewport. Valid values are between 0.0 and 1.0.
The Sun.
默认值: Default Value: undefined
启用后,在太阳上使用布隆过滤器。 Uses a bloom filter on the sun when enabled.
默认值: Default Value: true
地形提供者为地球提供表面几何形状。 The terrain provider providing surface geometry for the globe.

readonly terrainProviderChanged : Event

获取地形提供者更改时引发的事件 Gets an event that's raised when the terrain provider is changed

useDepthPicking : boolean

When true,允许使用深度缓冲区进行拾取。 , enables picking using the depth buffer.
默认值: Default Value: true
When true,将场景分成两个视口,为左眼和右眼提供立体视图。用于纸板和 WebVR。 , splits the scene into two viewports with steroscopic views for the left and right eyes. Used for cardboard and WebVR.
默认值: Default Value: false

verticalExaggeration : number

场景的垂直夸张。当设置为 1.0 时,不会应用夸大。 The vertical exaggeration of the scene. When set to 1.0, no exaggeration is applied.
默认值: Default Value: 1.0

verticalExaggerationRelativeHeight : number

场景垂直夸张的参考高度。当设置为 0.0 时,将相对于椭球面进行夸大。 The reference height for vertical exaggeration of the scene. When set to 0.0, the exaggeration is applied relative to the ellipsoid surface.
默认值: Default Value: 0.0

方法 Methods

cartesianToCanvasCoordinates(position, result)Cartesian2|undefined

将笛卡尔坐标中的位置转换为画布坐标。这通常用于将 HTML 元素放置在与场景中的对象相同的屏幕位置。 Transforms a position in cartesian coordinates to canvas coordinates. This is commonly used to place an HTML element at the same screen position as an object in the scene.
名称 Name 类型 Type 说明 Description
position Cartesian3 笛卡尔坐标中的位置。 The position in cartesian coordinates.
result Cartesian2 可选 optional 一个可选对象,用于返回转换为画布坐标的输入位置。 An optional object to return the input position transformed to canvas coordinates.
返回: Returns:
修改后的结果参数或新的 Cartesian2 实例(如果未提供)。这可能是 The modified result parameter or a new Cartesian2 instance if one was not provided. This may be undefined 如果输入位置靠近椭球体的中心。 if the input position is near the center of the ellipsoid.
示例: Example:
// Output the canvas position of longitude/latitude (0, 0) every time the mouse moves.
const scene = widget.scene;
const position = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
    console.log(scene.cartesianToCanvasCoordinates(position));
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

clampToHeight(cartesian, objectsToExclude, width, result)Cartesian3|undefined

沿着大地表面法线将给定的笛卡尔位置钳制到场景几何体。返回夹紧位置或 Clamps the given cartesian position to the scene geometry along the geodetic surface normal. Returns the clamped position or undefined 如果没有场景几何体可以夹紧。可用于将对象固定到地球仪、3D Tiles或场景中的图元。 if there was no scene geometry to clamp to. May be used to clamp objects to the globe, 3D Tiles, or primitives in the scene.

此功能仅限制在当前视图中渲染的地球图块和 3D 图块。钳位到所有其他图元,无论其可见性如何。 This function only clamps to globe tiles and 3D Tiles that are rendered in the current view. Clamps to all other primitives regardless of their visibility.

名称 Name 类型 Type 默认值 Default 说明 Description
cartesian Cartesian3 笛卡尔位置。 The cartesian position.
objectsToExclude Array.<object> 可选 optional 不钳制的图元、实体或 3D Tiles 功能的列表。 A list of primitives, entities, or 3D Tiles features to not clamp to.
width number 0.1 可选 optional 交叉口体积的宽度(以米为单位)。 Width of the intersection volume in meters.
result Cartesian3 可选 optional 用于返回夹紧位置的可选对象。 An optional object to return the clamped position.
返回: Returns:
修改后的结果参数或新的 Cartesian3 实例(如果未提供)。这可能是 The modified result parameter or a new Cartesian3 instance if one was not provided. This may be undefined 如果没有场景几何体可以夹紧。 if there was no scene geometry to clamp to.
抛出: Throws:
  • DeveloperError :clampToHeight 仅在 3D 模式下支持。 : clampToHeight is only supported in 3D mode.
  • DeveloperError :clampToHeight 需要深度纹理支持。检查clampToHeightSupported。 : clampToHeight requires depth texture support. Check clampToHeightSupported.
示例: Example:
// Clamp an entity to the underlying scene geometry
const position = entity.position.getValue(Cesium.JulianDate.now());
entity.position = viewer.scene.clampToHeight(position);
另见: See:

clampToHeightMostDetailed(cartesians, objectsToExclude, width)Promise.<Array.<(Cartesian3|undefined)>>

启动异步 Initiates an asynchronous Scene#clampToHeight 查询数组 query for an array of Cartesian3 使用场景中 3D 图块集的最大细节级别进行定位。返回一个在查询完成时解决的承诺。每个位置都修改到位。如果某个位置由于无法在该位置采样几何体而无法夹紧,或者发生其他错误,则数组中的元素将设置为未定义。 positions using the maximum level of detail for 3D Tilesets in the scene. Returns a promise that is resolved when the query completes. Each position is modified in place. If a position cannot be clamped because no geometry can be sampled at that location, or another error occurs, the element in the array is set to undefined.
名称 Name 类型 Type 默认值 Default 说明 Description
cartesians Array.<Cartesian3> 使用夹紧位置更新笛卡尔位置。 The cartesian positions to update with clamped positions.
objectsToExclude Array.<object> 可选 optional 不钳制的图元、实体或 3D Tiles 功能的列表。 A list of primitives, entities, or 3D Tiles features to not clamp to.
width number 0.1 可选 optional 交叉口体积的宽度(以米为单位)。 Width of the intersection volume in meters.
返回: Returns:
查询完成后解析为提供的职位列表的承诺。 Positions may become A promise that resolves to the provided list of positions when the query has completed. Positions may become undefined 如果无法夹紧。 if they cannot be clamped.
抛出: Throws:
  • DeveloperError :clampToHeightMostDetailed 仅在 3D 模式下受支持。 : clampToHeightMostDetailed is only supported in 3D mode.
  • DeveloperError :clampToHeightMostDetailed 需要深度纹理支持。检查clampToHeightSupported。 : clampToHeightMostDetailed requires depth texture support. Check clampToHeightSupported.
示例: Example:
const cartesians = [
    entities[0].position.getValue(Cesium.JulianDate.now()),
    entities[1].position.getValue(Cesium.JulianDate.now())
];
const promise = viewer.scene.clampToHeightMostDetailed(cartesians);
promise.then(function(updatedCartesians) {
    entities[0].position = updatedCartesians[0];
    entities[1].position = updatedCartesians[1];
}
另见: See:
立即完成主动转换。 Instantly completes an active transition.
销毁该对象持有的 WebGL 资源。销毁对象可以确定性地释放 WebGL 资源,而不是依赖垃圾收集器来销毁该对象。 Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.

一旦对象被销毁,就不应再使用;调用除 Once an object is destroyed, it should not be used; calling any function other than isDestroyed 将导致 will result in a DeveloperError 例外。因此,分配返回值( exception. Therefore, assign the return value (undefined) 到对象,如示例中所做的那样。 ) to the object as done in the example.
抛出: Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
scene = scene && scene.destroy();
另见: See:

drillPick(windowPosition, limit, width, height)Array.<any>

返回一个对象列表,每个对象包含一个 Returns a list of objects, each containing a primitive 属性,适用于特定窗口坐标位置的所有图元。还可以根据图元的类型来设置其他属性,并且可以使用其他属性来进一步识别所拾取的对象。列表中的图元按其在场景中的视觉顺序(从前到后)排序。 property, for all primitives at a particular window coordinate position. Other properties may also be set depending on the type of primitive and may be used to further identify the picked object. The primitives in the list are ordered by their visual order in the scene (front to back).
名称 Name 类型 Type 默认值 Default 说明 Description
windowPosition Cartesian2 用于执行拾取操作的窗口坐标。 Window coordinates to perform picking on.
limit number 可选 optional 如果提供,请在收集这么多镐后停止钻孔。 If supplied, stop drilling after collecting this many picks.
width number 3 可选 optional 选取矩形的宽度。 Width of the pick rectangle.
height number 3 可选 optional 选取矩形的高度。 Height of the pick rectangle.
返回: Returns:
对象数组,每个对象包含 1 个选取的基元。 Array of objects, each containing 1 picked primitives.
抛出: Throws:
  • DeveloperError :窗口位置未定义。 : windowPosition is undefined.
示例: Example:
const pickedObjects = scene.drillPick(new Cesium.Cartesian2(100.0, 200.0));
另见: See:

getCompressedTextureFormatSupported(format)boolean

确定是否支持压缩纹理格式。 Determines if a compressed texture format is supported.
名称 Name 类型 Type 说明 Description
format string 纹理格式。可能是格式的名称或 WebGL 扩展名称,例如s3tc 或 WEBGL_compressed_texture_s3tc。 The texture format. May be the name of the format or the WebGL extension name, e.g. s3tc or WEBGL_compressed_texture_s3tc.
返回: Returns:
是否支持该格式。 Whether or not the format is supported.

isDestroyed()boolean

如果该对象被销毁则返回 true;否则为假。 Returns true if this object was destroyed; otherwise, false.

如果该对象被破坏,则不应使用它;调用除 If this object was destroyed, it should not be used; calling any function other than isDestroyed 将导致 will result in a DeveloperError exception.
返回: Returns:
true 如果该物体被摧毁;否则, if this object was destroyed; otherwise, false.
另见: See:

morphTo2D(duration)

将场景异步转换为 2D。 Asynchronously transitions the scene to 2D.
名称 Name 类型 Type 默认值 Default 说明 Description
duration number 2.0 可选 optional 过渡动画完成所需的时间(以秒为单位)。 The amount of time, in seconds, for transition animations to complete.

morphTo3D(duration)

将场景异步转换为 3D。 Asynchronously transitions the scene to 3D.
名称 Name 类型 Type 默认值 Default 说明 Description
duration number 2.0 可选 optional 过渡动画完成所需的时间(以秒为单位)。 The amount of time, in seconds, for transition animations to complete.

morphToColumbusView(duration)

将场景异步转换为哥伦布视图。 Asynchronously transitions the scene to Columbus View.
名称 Name 类型 Type 默认值 Default 说明 Description
duration number 2.0 可选 optional 过渡动画完成所需的时间(以秒为单位)。 The amount of time, in seconds, for transition animations to complete.

pick(windowPosition, width, height)object|undefined

返回一个带有 a 的对象 Returns an object with a primitive 包含场景中特定窗口坐标处的第一个(顶部)基元的属性或 property that contains the first (top) primitive in the scene at a particular window coordinate or undefined 如果该位置没有任何东西。其他属性可能会根据基元的类型进行设置,并且可用于进一步识别拾取的对象。 if nothing is at the location. Other properties may potentially be set depending on the type of primitive and may be used to further identify the picked object.

当选择 3D Tiles 瓷砖集的某个功能时, When a feature of a 3D Tiles tileset is picked, pick 返回一个 returns a Cesium3DTileFeature object.

名称 Name 类型 Type 默认值 Default 说明 Description
windowPosition Cartesian2 用于执行拾取操作的窗口坐标。 Window coordinates to perform picking on.
width number 3 可选 optional 选取矩形的宽度。 Width of the pick rectangle.
height number 3 可选 optional 选取矩形的高度。 Height of the pick rectangle.
返回: Returns:
包含拾取的基元的对象或 Object containing the picked primitive or undefined 如果该位置没有任何东西。 if nothing is at the location.
示例: Example:
// On mouse over, color the feature yellow.
handler.setInputAction(function(movement) {
    const feature = scene.pick(movement.endPosition);
    if (feature instanceof Cesium.Cesium3DTileFeature) {
        feature.color = Cesium.Color.YELLOW;
    }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

pickAsync(windowPosition, width, height)Promise.<(Object|undefined)>

执行与 Scene.pick 相同的操作,但异步操作,不会阻塞主渲染线程。需要 WebGL2,否则使用后备。 Performs the same operation as Scene.pick but asynchonosly without blocking the main render thread. Requires WebGL2 else using fallback.
名称 Name 类型 Type 默认值 Default 说明 Description
windowPosition Cartesian2 用于执行拾取操作的窗口坐标。 Window coordinates to perform picking on.
width number 3 可选 optional 选取矩形的宽度。 Width of the pick rectangle.
height number 3 可选 optional 选取矩形的高度。 Height of the pick rectangle.
返回: Returns:
包含拾取的基元的对象或 Object containing the picked primitive or undefined 如果该位置没有任何东西。 if nothing is at the location.
示例: Example:
// On mouse over, color the feature yellow.
handler.setInputAction(function(movement) {
    const feature = scene.pickAsync(movement.endPosition).then(function(feature) {
       if (feature instanceof Cesium.Cesium3DTileFeature) {
           feature.color = Cesium.Color.YELLOW;
       }
    });
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
另见: See:

pickMetadata(windowPosition, schemaId, className, propertyName)MetadataValue|undefined

在给定窗口位置选择一个元数据值。 Pick a metadata value at the given window position.
名称 Name 类型 Type 说明 Description
windowPosition Cartesian2 用于执行拾取操作的窗口坐标。 Window coordinates to perform picking on.
schemaId string | undefined 要从中选取值的元数据架构的 ID。如果这是 The ID of the metadata schema to pick values from. If this is undefined,然后它将从对象中选取与给定类名称和属性名称匹配的值,而不管架构 ID。 , then it will pick the values from the object that match the given class- and property name, regardless of the schema ID.
className string 要从中选取值的元数据类的名称 The name of the metadata class to pick values from
propertyName string 要从中选取值的元数据属性的名称 The name of the metadata property to pick values from
返回: Returns:
元数据值,或 The metadata value, or undefined 当在给定位置没有找到匹配的元数据时 when no matching metadata was found at the given position
实验性 Experimental

此功能不是最终版本,可能会在没有 Cesium 标准弃用政策的情况下进行更改。 This feature is not final and is subject to change without Cesium's standard deprecation policy.

pickMetadataSchema(windowPosition)MetadataSchema|undefined

选择给定位置的对象元数据的模式 Pick the schema of the metadata of the object at the given position
名称 Name 类型 Type 说明 Description
windowPosition Cartesian2 用于执行拾取操作的窗口坐标。 Window coordinates to perform picking on.
返回: Returns:
元数据模式,或 The metadata schema, or undefined 如果给定位置没有具有关联元数据的对象。 if there is no object with associated metadata at the given position.
实验性 Experimental

此功能不是最终版本,可能会在没有 Cesium 标准弃用政策的情况下进行更改。 This feature is not final and is subject to change without Cesium's standard deprecation policy.

pickPosition(windowPosition, result)Cartesian3

返回根据深度缓冲区和窗口位置重建的笛卡尔位置。 Returns the cartesian position reconstructed from the depth buffer and window position.

从 2D 深度缓冲区重建的位置可能与 3D 和哥伦布视图中重建的位置略有不同。这是由于透视和正投影的深度值分布差异造成的。 The position reconstructed from the depth buffer in 2D may be slightly different from those reconstructed in 3D and Columbus view. This is caused by the difference in the distribution of depth values of perspective and orthographic projection.

Set Scene#pickTranslucentDepth to true 包括半透明图元的深度;否则,这本质上是通过半透明基元进行选择。 to include the depth of translucent primitives; otherwise, this essentially picks through translucent primitives.

名称 Name 类型 Type 说明 Description
windowPosition Cartesian2 用于执行拾取操作的窗口坐标。 Window coordinates to perform picking on.
result Cartesian3 可选 optional 要在其上恢复结果的对象。 The object on which to restore the result.
返回: Returns:
笛卡尔位置。 The cartesian position.
抛出: Throws:
  • DeveloperError :不支持从深度缓冲区中选取。检查 pickPositionSupported。 : Picking from the depth buffer is not supported. Check pickPositionSupported.

pickVoxel(windowPosition, width, height)VoxelCell|undefined

返回一个 Returns a VoxelCell 对于在特定窗口坐标处渲染的体素样本,或者 for the voxel sample rendered at a particular window coordinate, or undefined 如果在该位置没有渲染体素。 if no voxel is rendered at that position.
名称 Name 类型 Type 默认值 Default 说明 Description
windowPosition Cartesian2 用于执行拾取操作的窗口坐标。 Window coordinates to perform picking on.
width number 3 可选 optional 选取矩形的宽度。 Width of the pick rectangle.
height number 3 可选 optional 选取矩形的高度。 Height of the pick rectangle.
返回: Returns:
有关在拾取位置渲染的体素单元的信息或 Information about the voxel cell rendered at the picked position or undefined 如果在该位置没有渲染体素。 if no voxel is rendered at that position.
示例: Example:
On left click, report the value of the "color" property at that voxel sample.
handler.setInputAction(function(movement) {
  const voxelCell = scene.pickVoxel(movement.position);
  if (defined(voxelCell)) {
    console.log(voxelCell.getProperty("color"));
  }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
实验性 Experimental

此功能不是最终版本,可能会在没有 Cesium 标准弃用政策的情况下进行更改。 This feature is not final and is subject to change without Cesium's standard deprecation policy.

更新并渲染场景。通常不需要直接调用该函数,因为 Update and render the scene. It is usually not necessary to call this function directly because CesiumWidget 会自动完成。 will do it automatically.
名称 Name 类型 Type 说明 Description
time JulianDate 可选 optional 渲染的模拟时间。 The simulation time at which to render.
请求新的渲染帧时 Requests a new rendered frame when Scene#requestRenderMode 设置为 is set to true。渲染速率不会超过 . The render rate will not exceed the CesiumWidget#targetFrameRate.
另见: See:

sampleHeight(position, objectsToExclude, width)number|undefined

返回给定制图位置处场景几何体的高度或 Returns the height of scene geometry at the given cartographic position or undefined 如果没有场景几何体来采样高度。输入位置的高度将被忽略。可用于将对象固定到地球仪、3D Tiles或场景中的图元。 if there was no scene geometry to sample height from. The height of the input position is ignored. May be used to clamp objects to the globe, 3D Tiles, or primitives in the scene.

此函数仅对当前视图中渲染的地球图块和 3D 图块的高度进行采样。从所有其他图元的高度进行采样,无论其可见性如何。 This function only samples height from globe tiles and 3D Tiles that are rendered in the current view. Samples height from all other primitives regardless of their visibility.

名称 Name 类型 Type 默认值 Default 说明 Description
position Cartographic 从制图位置到样本高度。 The cartographic position to sample height from.
objectsToExclude Array.<object> 可选 optional 不从中采样高度的图元、实体或 3D Tiles 功能的列表。 A list of primitives, entities, or 3D Tiles features to not sample height from.
width number 0.1 可选 optional 交叉口体积的宽度(以米为单位)。 Width of the intersection volume in meters.
返回: Returns:
高度。这可能是 The height. This may be undefined 如果没有场景几何体来采样高度。 if there was no scene geometry to sample height from.
抛出: Throws:
  • DeveloperError :sampleHeight 仅在 3D 模式下支持。 : sampleHeight is only supported in 3D mode.
  • DeveloperError :sampleHeight 需要深度纹理支持。检查示例高度支持。 : sampleHeight requires depth texture support. Check sampleHeightSupported.
示例: Example:
const position = new Cesium.Cartographic(-1.31968, 0.698874);
const height = viewer.scene.sampleHeight(position);
console.log(height);
另见: See:

sampleHeightMostDetailed(positions, objectsToExclude, width)Promise.<Array.<(Cartographic|undefined)>>

启动异步 Initiates an asynchronous Scene#sampleHeight 查询数组 query for an array of Cartographic 使用场景中 3D 图块集的最大细节级别进行定位。输入位置的高度被忽略。返回一个在查询完成时解决的承诺。每个点的高度都被适当修改。如果由于无法在该位置采样几何图形而无法确定高度,或者发生其他错误,则高度将设置为 positions using the maximum level of detail for 3D Tilesets in the scene. The height of the input positions is ignored. Returns a promise that is resolved when the query completes. Each point height is modified in place. If a height cannot be determined because no geometry can be sampled at that location, or another error occurs, the height is set to undefined.
名称 Name 类型 Type 默认值 Default 说明 Description
positions Array.<Cartographic> 使用采样高度更新的制图位置。 The cartographic positions to update with sampled heights.
objectsToExclude Array.<object> 可选 optional 不从中采样高度的图元、实体或 3D Tiles 功能的列表。 A list of primitives, entities, or 3D Tiles features to not sample height from.
width number 0.1 可选 optional 交叉口体积的宽度(以米为单位)。 Width of the intersection volume in meters.
返回: Returns:
查询完成后解析为提供的职位列表的承诺。 Positions may become A promise that resolves to the provided list of positions when the query has completed. Positions may become undefined 如果无法确定高度。 if the height cannot be determined.
抛出: Throws:
  • DeveloperError :sampleHeightMostDetailed 仅在 3D 模式下受支持。 : sampleHeightMostDetailed is only supported in 3D mode.
  • DeveloperError :sampleHeightMostDetailed 需要深度纹理支持。检查示例高度支持。 : sampleHeightMostDetailed requires depth texture support. Check sampleHeightSupported.
示例: Example:
const positions = [
    new Cesium.Cartographic(-1.31968, 0.69887),
    new Cesium.Cartographic(-1.10489, 0.83923)
];
const promise = viewer.scene.sampleHeightMostDetailed(positions);
promise.then(function(updatedPosition) {
    // positions[0].height and positions[1].height have been updated.
    // updatedPositions is just a reference to positions.
}
另见: See:

setTerrain(terrain)Terrain

更新地形,为地球提供表面几何形状。 Update the terrain providing surface geometry for the globe.
名称 Name 类型 Type 说明 Description
terrain Terrain 地形提供者异步助手 The terrain provider async helper
返回: Returns:
terrain 地形提供者异步助手 terrain The terrain provider async helper
示例: Examples:
// Use Cesium World Terrain
scene.setTerrain(Cesium.Terrain.fromWorldTerrain());
// Use a custom terrain provider
const terrain = new Cesium.Terrain(Cesium.CesiumTerrainProvider.fromUrl("https://myTestTerrain.com"));
scene.setTerrain(terrain);

terrain.errorEvent.addEventListener(error => {
  alert(`Encountered an error while creating terrain! ${error}`);
});
需要帮助吗?获得答案的最快方法是从社区和团队那里获得答案 Need help? The fastest way to get answers is from the community and team on the Cesium Forum.