Appearance
KBE3D / KBCore / Cesium / Scene
类: Scene
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.
示例
ts
// Create scene without anisotropic texture filtering
const scene = new Cesium.Scene({
canvas : canvas,
contextOptions : {
allowTextureFilterAnisotropic : false
}
});参数
Object with the following properties:
参数
The HTML canvas element to create the scene for.
参数
Context and WebGL creation properties.
参数
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.
参数
The HTML element in which to display the credit popup. If not specified, the viewport will be added as a sibling of the canvas.
参数
The default ellipsoid. If not specified, the default ellipsoid is used.
参数
The map projection to use in 2D and Columbus View modes.
参数
If true and the configuration supports it, use order independent translucency.
参数
If true, optimizes memory use and performance for 3D mode but disables the ability to use 2D or Columbus View.
参数
Determines if shadows are cast by light sources.
参数
Determines if the 2D map is rotatable or can be scrolled infinitely in the horizontal direction.
参数
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 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.
参数
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.
参数
Adjust the DepthPlane to address rendering artefacts below ellipsoid zero elevation.
参数
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.
属性
defaultLogDepthBuffer
staticdefaultLogDepthBuffer:any
Use this to set the default value for Scene#logarithmicDepthBuffer in newly constructed Scenes This property relies on fragmentDepth being supported.
rethrowRenderErrors
rethrowRenderErrors:
boolean
Exceptions occurring in <code>render</code> are always caught in order to raise the <code>renderError</code> event. If this property is true, the error is rethrown after the event is raised. If this property is false, the <code>render</code> function returns normally after raising the event.
completeMorphOnUserInput
completeMorphOnUserInput:
boolean
Determines whether or not to instantly complete the scene transition animation on user input.
morphStart
morphStart:
Event
The event fired at the beginning of a scene transition.
morphComplete
morphComplete:
Event
The event fired at the completion of a scene transition.
skyBox
skyBox:
SkyBox|undefined
The SkyBox used to draw the stars.
skyAtmosphere
skyAtmosphere:
SkyAtmosphere|undefined
The sky atmosphere drawn around the globe.
sun
sun:
Sun|undefined
The Sun.
sunBloom
sunBloom:
boolean
Uses a bloom filter on the sun when enabled.
moon
moon:
Moon|undefined
The Moon
backgroundColor
backgroundColor:
Color
The background color, which is only visible if there is no sky box, i.e., Scene#skyBox is <code>undefined</code>.
morphTime
morphTime:
number
The current morph transition time between 2D/Columbus View and 3D, with 0.0 being 2D or Columbus View and 1.0 being 3D.
farToNearRatio
farToNearRatio:
number
The far-to-near ratio of the multi-frustum when using a normal depth buffer. <p> 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 <code>false</code>. When <code>logarithmicDepthBuffer</code> is <code>true</code>, use Scene#logarithmicDepthFarToNearRatio. </p>
logarithmicDepthFarToNearRatio
logarithmicDepthFarToNearRatio:
number
The far-to-near ratio of the multi-frustum when using a logarithmic depth buffer. <p> 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 <code>true</code>. When <code>logarithmicDepthBuffer</code> is <code>false</code>, use Scene#farToNearRatio. </p>
nearToFarDistance2D
nearToFarDistance2D:
number
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.
verticalExaggeration
verticalExaggeration:
number
The vertical exaggeration of the scene. When set to 1.0, no exaggeration is applied.
verticalExaggerationRelativeHeight
verticalExaggerationRelativeHeight:
number
The reference height for vertical exaggeration of the scene. When set to 0.0, the exaggeration is applied relative to the ellipsoid surface.
debugCommandFilter
debugCommandFilter: (...
params:any[]) =>any|undefined
This property is for debugging only; it is not for production use. <p> A function that determines what commands are executed. As shown in the examples below, the function receives the command's <code>owner</code> as an argument, and returns a boolean indicating if the command should be executed. </p> <p> The default is <code>undefined</code>, indicating that all commands are executed. </p>
示例
ts
// 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;
};debugShowCommands
debugShowCommands:
boolean
This property is for debugging only; it is not for production use. <p> When <code>true</code>, 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. </p>
debugShowFrustums
debugShowFrustums:
boolean
This property is for debugging only; it is not for production use. <p> When <code>true</code>, 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. </p>
debugShowFramesPerSecond
debugShowFramesPerSecond:
boolean
This property is for debugging only; it is not for production use. <p> Displays frames per second and time between frames. </p>
debugShowDepthFrustum
debugShowDepthFrustum:
number
This property is for debugging only; it is not for production use. <p> Indicates which frustum will have depth information displayed. </p>
debugShowFrustumPlanes
debugShowFrustumPlanes:
boolean
This property is for debugging only; it is not for production use. <p> When <code>true</code>, draws outlines to show the boundaries of the camera frustums </p>
useDepthPicking
useDepthPicking:
boolean
When <code>true</code>, enables picking using the depth buffer.
pickTranslucentDepth
pickTranslucentDepth:
boolean
When <code>true</code>, enables picking translucent geometry using the depth buffer. Note that Scene#useDepthPicking must also be true for enabling this to work.
<p> There is a decrease in performance when enabled. There are extra draw calls to write depth for translucent geometry. </p>
示例
ts
// 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);atmosphere
atmosphere:
Atmosphere
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.
fog
fog:
Fog
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.
shadowMap
shadowMap:
ShadowMap
The shadow map for the scene's light source. When enabled, models, primitives, and the globe may cast and receive shadows.
invertClassification
invertClassification:
boolean
When <code>false</code>, 3D Tiles will render normally. When <code>true</code>, classified 3D Tile geometry will render normally and unclassified 3D Tile geometry will render with the color multiplied by Scene#invertClassificationColor.
invertClassificationColor
invertClassificationColor:
Color
The highlight color of unclassified 3D Tile geometry when Scene#invertClassification is <code>true</code>. <p>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.</p> <p>Also, when the color's alpha is less than 1.0, the WEBGL_depth_texture and EXT_frag_depth WebGL extensions must be supported.</p>
focalLength
focalLength:
number
The focal length for use when with cardboard or WebVR.
eyeSeparation
eyeSeparation:
number
The eye separation distance in meters for use with cardboard or WebVR.
postProcessStages
postProcessStages:
PostProcessStageCollection
Post processing effects applied to the final render.
requestRenderMode
requestRenderMode:
boolean
When <code>true</code>, 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 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.
maximumRenderTimeChange
maximumRenderTimeChange:
number
If Scene#requestRenderMode is <code>true</code>, 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 <code>undefined</code>, 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.
sphericalHarmonicCoefficients
sphericalHarmonicCoefficients:
Cartesian3[]
The spherical harmonic coefficients for image-based lighting of PBR models.
specularEnvironmentMaps
specularEnvironmentMaps:
string
The url to the KTX2 file containing the specular environment map and convoluted mipmaps for image-based lighting of PBR models.
light
light:
Light
The light source for shading. Defaults to a directional light from the Sun.
_enableEdgeVisibility
_enableEdgeVisibility:
boolean
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.
canvas
readonlycanvas:HTMLCanvasElement
Gets the canvas element to which this scene is bound.
drawingBufferHeight
readonlydrawingBufferHeight:number
The drawingBufferHeight of the underlying GL context.
drawingBufferWidth
readonlydrawingBufferWidth:number
The drawingBufferWidth of the underlying GL context.
maximumAliasedLineWidth
readonlymaximumAliasedLineWidth:number
The maximum aliased line width, in pixels, supported by this WebGL implementation. It will be at least one.
maximumCubeMapSize
readonlymaximumCubeMapSize:number
The maximum length in pixels of one edge of a cube map, supported by this WebGL implementation. It will be at least 16.
pickPositionSupported
readonlypickPositionSupported:boolean
Returns <code>true</code> if the Scene#pickPosition function is supported.
sampleHeightSupported
readonlysampleHeightSupported:boolean
Returns <code>true</code> if the Scene#sampleHeight and Scene#sampleHeightMostDetailed functions are supported.
clampToHeightSupported
readonlyclampToHeightSupported:boolean
Returns <code>true</code> if the Scene#clampToHeight and Scene#clampToHeightMostDetailed functions are supported.
invertClassificationSupported
readonlyinvertClassificationSupported:boolean
Returns <code>true</code> if the Scene#invertClassification is supported.
specularEnvironmentMapsSupported
readonlyspecularEnvironmentMapsSupported:boolean
Returns <code>true</code> if specular environment maps are supported.
ellipsoid
readonlyellipsoid:Ellipsoid
The ellipsoid. If not specified, the default ellipsoid is used.
globe
globe:
Globe
Gets or sets the depth-test ellipsoid.
primitives
readonlyprimitives:PrimitiveCollection
Gets the collection of primitives.
groundPrimitives
readonlygroundPrimitives:PrimitiveCollection
Gets the collection of ground primitives.
camera
readonlycamera:Camera
Gets or sets the camera.
screenSpaceCameraController
readonlyscreenSpaceCameraController:ScreenSpaceCameraController
Gets the controller for camera input handling.
mapProjection
readonlymapProjection:MapProjection
Get the map projection to use in 2D and Columbus View modes.
imageryLayers
readonlyimageryLayers:ImageryLayerCollection
Gets the collection of image layers that will be rendered on the globe.
terrainProvider
terrainProvider:
TerrainProvider
The terrain provider providing surface geometry for the globe.
terrainProviderChanged
readonlyterrainProviderChanged:Event
Gets an event that's raised when the terrain provider is changed
preUpdate
readonlypreUpdate:Event
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.
postUpdate
readonlypostUpdate:Event
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.
renderError
readonlyrenderError:Event
Gets the event that will be raised when an error is thrown inside the <code>render</code> 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 <code>rethrowRenderErrors</code> property.
preRender
readonlypreRender:Event
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.
postRender
readonlypostRender:Event
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.
lastRenderTime
readonlylastRenderTime:JulianDate|undefined
Gets the simulation time when the scene was last rendered. Returns <code>undefined</code> if the scene has not yet been rendered.
debugFrustumStatistics
readonlydebugFrustumStatistics:any
This property is for debugging only; it is not for production use. <p> When Scene.debugShowFrustums is <code>true</code>, this contains properties with statistics about the number of command execute per frustum. <code>totalCommands</code> is the total number of commands executed, ignoring overlap. <code>commandsInFrustums</code> is an array with the number of times commands are executed redundantly, e.g., how many commands overlap two or three frustums. </p>
scene3DOnly
readonlyscene3DOnly:boolean
Gets whether or not the scene is optimized for 3D only viewing.
orderIndependentTranslucency
readonlyorderIndependentTranslucency:boolean
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.
id
readonlyid:string
Gets the unique identifier for this scene.
mode
mode:
SceneMode
Gets or sets the current mode of the scene.
useWebVR
useWebVR:
boolean
When <code>true</code>, splits the scene into two viewports with steroscopic views for the left and right eyes. Used for cardboard and WebVR.
mapMode2D
readonlymapMode2D:MapMode2D
Determines if the 2D map is rotatable or can be scrolled infinitely in the horizontal direction.
splitPosition
splitPosition:
number
Gets or sets the position of the splitter within the viewport. Valid values are between 0.0 and 1.0.
minimumDisableDepthTestDistance
minimumDisableDepthTestDistance:
number
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.
logarithmicDepthBuffer
logarithmicDepthBuffer:
boolean
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.
gamma
gamma:
number
The value used for gamma correction. This is only used when rendering with high dynamic range.
highDynamicRange
highDynamicRange:
boolean
Whether or not to use high dynamic range rendering.
highDynamicRangeSupported
readonlyhighDynamicRangeSupported:boolean
Whether or not high dynamic range rendering is supported.
cameraUnderground
readonlycameraUnderground:boolean
Whether or not the camera is underneath the globe.
msaaSamples
msaaSamples:
number
The sample rate of multisample antialiasing (values greater than 1 enable MSAA).
msaaSupported
readonlymsaaSupported:boolean
Returns <code>true</code> if the Scene's context supports MSAA.
方法
getCompressedTextureFormatSupported()
getCompressedTextureFormatSupported(
format:string):boolean
Determines if a compressed texture format is supported.
参数
format
string
The texture format. May be the name of the format or the WebGL extension name, e.g. s3tc or WEBGL_compressed_texture_s3tc.
返回
boolean
Whether or not the format is supported.
render()
render(
time?:JulianDate):void
Update and render the scene. It is usually not necessary to call this function directly because CesiumWidget will do it automatically.
参数
time?
The simulation time at which to render.
返回
void
requestRender()
requestRender():
void
Requests a new rendered frame when Scene#requestRenderMode is set to <code>true</code>. The render rate will not exceed the CesiumWidget#targetFrameRate.
返回
void
pick()
pick(
windowPosition:Cartesian2,width?:number,height?:number):any
Returns an object with a <code>primitive</code> property that contains the first (top) primitive in the scene at a particular window coordinate or <code>undefined</code> 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. <p> When a feature of a 3D Tiles tileset is picked, <code>pick</code> returns a Cesium3DTileFeature object. </p>
参数
windowPosition
Window coordinates to perform picking on.
width?
number
Width of the pick rectangle.
height?
number
Height of the pick rectangle.
返回
any
Object containing the picked primitive or undefined if nothing is at the location.
示例
ts
// 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()
pickAsync(
windowPosition:Cartesian2,width?:number,height?:number):Promise<object|undefined>
Performs the same operation as Scene.pick but asynchonosly without blocking the main render thread. Requires WebGL2 else using fallback.
参数
windowPosition
Window coordinates to perform picking on.
width?
number
Width of the pick rectangle.
height?
number
Height of the pick rectangle.
返回
Promise<object | undefined>
Object containing the picked primitive or undefined if nothing is at the location.
示例
ts
// 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);pickVoxel()
pickVoxel(
windowPosition:Cartesian2,width?:number,height?:number):VoxelCell|undefined
Returns a VoxelCell for the voxel sample rendered at a particular window coordinate, or <code>undefined</code> if no voxel is rendered at that position.
参数
windowPosition
Window coordinates to perform picking on.
width?
number
Width of the pick rectangle.
height?
number
Height of the pick rectangle.
返回
VoxelCell | undefined
Information about the voxel cell rendered at the picked position or undefined if no voxel is rendered at that position.
示例
ts
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);pickMetadata()
pickMetadata(
windowPosition:Cartesian2,schemaId:string|undefined,className:string,propertyName:string):MetadataValue|undefined
Pick a metadata value at the given window position.
参数
windowPosition
Window coordinates to perform picking on.
schemaId
The ID of the metadata schema to pick values from. If this is <code>undefined</code>, then it will pick the values from the object that match the given class- and property name, regardless of the schema ID.
string | undefined
className
string
The name of the metadata class to pick values from
propertyName
string
The name of the metadata property to pick values from
返回
MetadataValue | undefined
The metadata value, or undefined when no matching metadata was found at the given position
pickMetadataSchema()
pickMetadataSchema(
windowPosition:Cartesian2):MetadataSchema|undefined
Pick the schema of the metadata of the object at the given position
参数
windowPosition
Window coordinates to perform picking on.
返回
MetadataSchema | undefined
The metadata schema, or undefined if there is no object with associated metadata at the given position.
pickPosition()
pickPosition(
windowPosition:Cartesian2,result?:Cartesian3):Cartesian3
Returns the cartesian position reconstructed from the depth buffer and window position. <p> 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. </p> <p> Set Scene#pickTranslucentDepth to <code>true</code> to include the depth of translucent primitives; otherwise, this essentially picks through translucent primitives. </p>
参数
windowPosition
Window coordinates to perform picking on.
result?
The object on which to restore the result.
返回
The cartesian position.
drillPick()
drillPick(
windowPosition:Cartesian2,limit?:number,width?:number,height?:number):any[]
Returns a list of objects, each containing a <code>primitive</code> 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).
参数
windowPosition
Window coordinates to perform picking on.
limit?
number
If supplied, stop drilling after collecting this many picks.
width?
number
Width of the pick rectangle.
height?
number
Height of the pick rectangle.
返回
any[]
Array of objects, each containing 1 picked primitives.
示例
ts
const pickedObjects = scene.drillPick(new Cesium.Cartesian2(100.0, 200.0));sampleHeight()
sampleHeight(
position:Cartographic,objectsToExclude?:object[],width?:number):number|undefined
Returns the height of scene geometry at the given cartographic position or <code>undefined</code> 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. <p> 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. </p>
参数
position
The cartographic position to sample height from.
objectsToExclude?
object[]
A list of primitives, entities, or 3D Tiles features to not sample height from.
width?
number
Width of the intersection volume in meters.
返回
number | undefined
The height. This may be undefined if there was no scene geometry to sample height from.
示例
ts
const position = new Cesium.Cartographic(-1.31968, 0.698874);
const height = viewer.scene.sampleHeight(position);
console.log(height);clampToHeight()
clampToHeight(
cartesian:Cartesian3,objectsToExclude?:object[],width?:number,result?:Cartesian3):Cartesian3|undefined
Clamps the given cartesian position to the scene geometry along the geodetic surface normal. Returns the clamped position or <code>undefined</code> 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. <p> 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. </p>
参数
cartesian
The cartesian position.
objectsToExclude?
object[]
A list of primitives, entities, or 3D Tiles features to not clamp to.
width?
number
Width of the intersection volume in meters.
result?
An optional object to return the clamped position.
返回
Cartesian3 | undefined
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.
示例
ts
// Clamp an entity to the underlying scene geometry
const position = entity.position.getValue(Cesium.JulianDate.now());
entity.position = viewer.scene.clampToHeight(position);sampleHeightMostDetailed()
sampleHeightMostDetailed(
positions:Cartographic[],objectsToExclude?:object[],width?:number):Promise<(Cartographic|undefined)[]>
Initiates an asynchronous Scene#sampleHeight query for an array of Cartographic 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 <code>undefined</code>.
参数
positions
The cartographic positions to update with sampled heights.
objectsToExclude?
object[]
A list of primitives, entities, or 3D Tiles features to not sample height from.
width?
number
Width of the intersection volume in meters.
返回
Promise<(Cartographic | undefined)[]>
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.
示例
ts
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.
}clampToHeightMostDetailed()
clampToHeightMostDetailed(
cartesians:Cartesian3[],objectsToExclude?:object[],width?:number):Promise<(Cartesian3|undefined)[]>
Initiates an asynchronous Scene#clampToHeight query for an array of Cartesian3 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.
参数
cartesians
The cartesian positions to update with clamped positions.
objectsToExclude?
object[]
A list of primitives, entities, or 3D Tiles features to not clamp to.
width?
number
Width of the intersection volume in meters.
返回
Promise<(Cartesian3 | undefined)[]>
A promise that resolves to the provided list of positions when the query has completed. Positions may become undefined if they cannot be clamped.
示例
ts
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];
}cartesianToCanvasCoordinates()
cartesianToCanvasCoordinates(
position:Cartesian3,result?:Cartesian2):Cartesian2|undefined
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.
参数
position
The position in cartesian coordinates.
result?
An optional object to return the input position transformed to canvas coordinates.
返回
Cartesian2 | undefined
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.
示例
ts
// 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);completeMorph()
completeMorph():
void
Instantly completes an active transition.
返回
void
morphTo2D()
morphTo2D(
duration?:number):void
Asynchronously transitions the scene to 2D.
参数
duration?
number
The amount of time, in seconds, for transition animations to complete.
返回
void
morphToColumbusView()
morphToColumbusView(
duration?:number):void
Asynchronously transitions the scene to Columbus View.
参数
duration?
number
The amount of time, in seconds, for transition animations to complete.
返回
void
morphTo3D()
morphTo3D(
duration?:number):void
Asynchronously transitions the scene to 3D.
参数
duration?
number
The amount of time, in seconds, for transition animations to complete.
返回
void
setTerrain()
Update the terrain providing surface geometry for the globe.
参数
terrain
The terrain provider async helper
返回
terrain The terrain provider async helper
Examples
ts
// Use Cesium World Terrain
scene.setTerrain(Cesium.Terrain.fromWorldTerrain());ts
// 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}`);
});isDestroyed()
isDestroyed():
boolean
Returns true if this object was destroyed; otherwise, false. <br /><br /> If this object was destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception.
返回
boolean
true if this object was destroyed; otherwise, false.
destroy()
destroy():
void
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. <br /><br /> Once an object is destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception. Therefore, assign the return value (<code>undefined</code>) to the object as done in the example.
返回
void
示例
ts
scene = scene && scene.destroy();构造函数
构造函数
new Scene(
options: {canvas:HTMLCanvasElement;contextOptions?:ContextOptions;creditContainer?:Element;creditViewport?:Element;ellipsoid?:Ellipsoid;mapProjection?:MapProjection;orderIndependentTranslucency?:boolean;scene3DOnly?:boolean;shadows?:boolean;mapMode2D?:MapMode2D;requestRenderMode?:boolean;maximumRenderTimeChange?:number;depthPlaneEllipsoidOffset?:number;msaaSamples?:number; }):Scene
参数
options
canvas
HTMLCanvasElement
contextOptions?
creditContainer?
Element
creditViewport?
Element
ellipsoid?
mapProjection?
orderIndependentTranslucency?
boolean
scene3DOnly?
boolean
shadows?
boolean
mapMode2D?
requestRenderMode?
boolean
maximumRenderTimeChange?
number
depthPlaneEllipsoidOffset?
number
msaaSamples?
number
返回
Scene
