Scene

new Cesium.Scene(options)

The 3D scene class, which is the container of all 3D graphics objects and states, usually does not directly create the scene, but implicitly created by CesiumWidget.

contextOptionsParameter details:

The default value is: { webgl : { alpha : false, depth : true, stencil : false, antialias : true, premultipliedAlpha : true, preserveDrawingBuffer : false, failIfMajorPerformanceCaveat : false }, allowTextureFilterAnisotropic : true }

The webgl attribute corresponds to the WebGLContextAttributes object used to create the WebGL environment.

webgl.alpha defaults to false, which can improve performance compared to the standard WebGL default value of true.

The other webgl properties match WebGLContextAttributes.'s WebGL default values.

allowTextureFilterAnisotropic is true by default, which allows anisotropic texture filtering when WebGL extensions are supported. Setting it to false can improve performance, but it will impair visual quality, especially for horizontal views.

Name Type Description
options Object optional The object has the following properties:
Name Type Default Description
canvas Canvas The HTML cancas element used to create the scene.
contextOptions Object optional Environment and WebGL creation properties, see above for details.
creditContainer Element optional HTML elements used to display service description information.
mapProjection MapProjection new GeographicProjection() optional Map projection used in 2D and Columbus view modes.
orderIndependentTranslucency Boolean true optional If this item is set to true and device support is used, translucency regardless of order will be used.
scene3DOnly Boolean false optional If this item is set to true, the memory usage and performance of 3D mode will be optimized, but the use of 2D or Columbus view functions is prohibited.
terrainExaggeration Number 1.0 optional Scalar used to exaggerate the terrain. Please note that setting the terrain exaggeration will not modify any other data.
shadows Boolean false optional Determine whether the shadow is cast by the sun.
mapMode2D MapMode2D MapMode2D.INFINITE_SCROLL optional Make sure that the 2D map is rotatable or can be scrolled infinitely in the horizontal direction.
Throws:
Example:
//Create a scene.
var viewer=new new Cesium.Viewer('Container');
var scene = viewer.scene;
See:

Members

bloomEffect : BloomEffect

Get the floodlight effect of the scene, including floodlight intensity value, floodlight brightness threshold, etc.

readonlycamera : Camera

Get the camera object of the current scene.

readonlycanvas : Element

Get the canvas element bound to the scene.

colorCorrection

Create color correction objects

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 attribute is only used for debugging, not for production. When true, draw contour lines to show the range of the camera platform.
Default Value: false

readonlydrawingBufferHeight : Number

The height of the GL drawing buffer.
See:

readonlydrawingBufferWidth : Number

GL drawing buffer width.
See:

enableCompositor : Boolean

Get or set whether to draw the scene as a picture. When closed, draw directly to the color buffer, the picture effect is better, but some analysis functions are not available. The default value is true.

enableOcclude

Whether to enable occlusion culling in the current scene.
Default Value: true

eyeSeparation : Number

The eye separation distance in meters for use with cardboard or WebVR.

focalLength : Number

The focal length for use when with cardboard or WebVR.

globe : Globe

Get the earth object.

globeSplitPosition : Cartesian2

Set or get the shutter position of the current scene, the effective value is 0.0~1.0 Gets or sets the position of the globe splitter within the viewport. Valid values are between 0.0 and 1.0.

readonlygroundPrimitives : PrimitiveCollection

Get the collection of all the stickers.

hdrEnabled

Whether to enable hdr in the current scene.
Default Value: false

readonlyid : String

Get the id of the current scene.

readonlyimageryLayers : ImageryLayerCollection

Get the current scene image layer collection.

imagerySplitPosition : Number

Set or get the position of the image divider of the current scene.

invertClassification : Boolean

When false, 3D Tiles will render normally. When true, 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

The highlight color of unclassified 3D Tile geometry when Scene#invertClassification is true.

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.

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

readonlylayers : Layers

Get the 3D oblique photogrammetric cache layer collection of the current scene.

lightSource

Get the light source in the current scene.

logarithmicDepthBuffer : Boolean

Gets or sets whether to use the logarithmic depth buffer. When set to true, fewer truncated cones will be used in the hybrid multi-truncated cone. For details, please refer to the instructions on the Cesium official website.

readonlymapProjection : MapProjection

Get the map projection object, used in 2D or Columbus View mode, the default is latitude and longitude projection.
Default Value: new GeographicProjection()

minimumDisableDepthTestDistance : Number

Disable the depth test of billboards, labels and point objects by setting the camera viewing distance. For example, in order to prevent the terrain data from being cut, the depth test is always valid if the distance is set to 0, and the depth test is invalid if the distance is set to less than 0. Modify the distance value by setting the disableDepthTestDistance property of the billboard, label and point object.
Default Value: 0.0

mode : SceneMode

Get the mode of the current scene.
Default Value: SceneMode.SCENE3D

multiViewportMode : Number

Get or set the multi-viewport mode of the current scene, the default is single-viewport.
Default Value: 0
See:

overlapDisplayOptions : Object

Set the avoidance parameters of the layer. The parameter that can be set is: allowIconWithTextDisplay, set whether to enable the icon layer to follow the text layer to avoid. The default is true.

pickPointEnabled : Boolean

Turn on the vertex capture function, the default is false, set to true, then the capture is turned on.

pickPointInterval : Number

Set the time interval for point cloud capture
Default Value: 200

pickTranslucentDepth : Boolean

When true, supports using the depth buffer to pick up semi-transparent geometry. Scene#useDepthPicking must also be true to support picking up the depth buffer. The performance is reduced during use. For semi-transparent geometric figures, additional drawing commands will be called to write depth.
Default Value: false

readonlypostRender : Event

Get the event at the end of each frame of the current scene, and monitor the event to be triggered at the end of each frame.

readonlypreRender : Event

Get the event before each frame of the current scene is rendered, and listen for the event to be triggered before each frame is rendered.

readonlyprimitives : PrimitiveCollection

Get all primitive collections.

rasterVectorCollection : Object

Get real-time rasterized objects.

readonlyscreenSpaceCameraController : ScreenSpaceCameraController

Get the camera operation object of the current scene.

shadowMap : ShadowMap

The shadow map in the scene. When enabled, the model, primitives, and earth can cast and receive shadows. By default, the light source of the shadow map is the sun.

skyBox : SkyBox

The SkyBox used to draw the stars.
Default Value: undefined
See:
  • Scene#backgroundColor

specularEnvironmentMaps : String

The url to the KTX file containing the specular environment map and convoluted mipmaps for image-based lighting of PBR models.

sphericalHarmonicCoefficients : Array.<Cartesian3>

The spherical harmonic coefficients for image-based lighting of PBR models.

sun : Sun

The Sun.
Default Value: undefined

terrainProvider : TerrainProvider

Gets or sets the terrain service provider object of the current scene.

readonlyterrainProviderChanged : Event

Get the current scene terrain service provider change event.

toneMappingEnabled

Whether to enable toneMapping in the current scene.

readonlyunderGlobe : UnderGlobe

Get the ground ball.

undergroundDepth : Number

Get or set the depth of the underground scene, the default is 1000 meters (unit: meter).

undergroundMode : Boolean

Get or set whether to open the underground scene.
Default Value: false

walkingMode : Number

Get or set the camera mode
Default Value: WalkingMode.NONE
See:

Methods

addFieldLayer(url)Promise

Add field data layer according to url path.
Name Type Description
url String The URL path of the field data.
Returns:
Return the field data layer FieldLayer3D, and create the field layer object asynchronously.
Example:
var promise =  viewer.scene.addFieldLayer("../data.nc");
 Cesium.when(promise,function(fieldLayer){
       fieldLayer.particleVelocityFieldEffect.velocityScale = 100.0;
       fieldLayer.particleVelocityFieldEffect.particleSize = 2;
       fieldLayer.particleVelocityFieldEffect.paricleCountPerDegree = 1.5;
       scene.primitives.add(fieldLayer);
       fieldLayer.particleVelocityFieldEffect.colorTable = colorTable;
       var options = {
        longitude:'lon',
        latitude:'lat',
        uwnd:'uwnd',
        vwnd:'uwnd'
     }
      fieldLayer.NetCDFData = options;
	})

addLayerService(url, sceneName, layerName)

Add scene layer service.
Name Type Description
url String The URL path of the layer service.
sceneName String Scene name.
layerName String The layer name.

addLightSource(lightSource)Scene

Add a light source.
Name Type Description
lightSource LightSource light source.
Returns:
The scene after adding a point light source.

addS3MGroupLayer(url, options, index)Promise

Add S3M grouping layer.
Name Type Description
url String The address of the configuration file published in the iserver.
options Object The attribute object required by the layer.
index Number Index.
Returns:
Return promise asynchronous loading object

addS3MTilesLayerByScp(url, options, index)Promise

Add 3D oblique photogrammetric cache layer (S3M, S3MB).
Name Type Description
url String The address of the configuration file published in the iserver.
options Object optional The object has the following properties:
Name Type Default Description
subdomains Array Used for subdomains, for example: ['t1','t2'].
autoSetView Boolean true optional Whether to automatically locate the scene
name String Specify the layer name.
cullEnabled Boolean false optional Whether to cull the back side, the default is not cull, that is, double-sided rendering.
index Number Index.
Returns:
Return promise asynchronous loading object
Example:
var promise = scene.addS3MTilesLayerByScp('http://localhost:8090/iserver/services/3D-zj/rest/realspace/datas/zj/config', {name : 'base'});
promise.then(function(layer){
    layer.visible = false;
});

//Subdomain usage
var config = {
      subdomainConfig: {
         urlScheme: "http://{s}.supermap.com:8090/iserver/services/3D-BIM/rest/realspace",
         subdomains: ['t1', 't2']
     },
     name: "BIM"
 };
var promise = scene.addS3MTilesLayerByScp('http://localhost:8090/iserver/services/3D-BIM/rest/realspace/datas/BIM/config', config);

addVectorTilesLayer(options)

Add vector tile layer service. In order to ensure the stability of the version, the MVT layer created with this interface still maintains the original use and implementation method, but does not support the new interface in VectorTileMap. It is recommended to use the new implementation method addVectorTilesMap.
Name Type Description
options Object The parameter object contains the following properties:
Name Type Default Description
url String It is suitable for generating mvt data through SuperMap desktop software, which is published as rest style map service by iServer, only the service address is required.
url String The service address is applicable to WMTS services published by third parties.
layer String The layer name is applicable to WMTS services published by third parties.
canvasWidth Number optional The side length of the texture used to draw the vector. The default is 512, the larger the finer, the smaller the higher the performance.
tileWidth String The tile width is suitable for WMTS services released by third parties.
tileHeight String The tile height is suitable for WMTS services released by third parties.
format String 'mvt' optional Applicable to WMTS services published by third parties.
tilematrxset String The name of the slicing matrix set is applicable to WMTS services published by third parties.
maximumLevel Number optional The maximum level of data. It is applicable to WMTS services published by third parties, and is calculated based on service parameters by default.
minimumLevel Number optional The smallest level of data. It is applicable to WMTS services published by third parties, and is calculated based on service parameters by default.
mapboxStyle Object optional The mapBox style used.
maximumTerrainLevel Number optional The maximum terrain layer number that is allowed to load MVT layers (if not defined, all layers are loaded).
minimumTerrainLevel Number optional The minimum terrain layer number allowed to load MVT layers (if not defined, all layers are loaded).
simplifyTolerance Number optional The coordinate tolerance for geometric simplification, the unit is the slice coordinate system, and the value range is 0-4096. The larger the value, the more simplification is. The default is 0, no simplification.
Example:
var layer = scene.addVectorTilesLayer({
    url:"http://localhost:8090/iserver/services/map-mvt-test/....../maps/test"//地图服务
});
See:

addVectorTilesMap(options)

Create a new vector tile map.
Name Type Description
options The new map contains the following parameters:
Name Type Default Description
url String It is suitable for generating mvt data through SuperMap desktop software, which is published as rest style map service by iServer, only the service address is required.
layer String The layer name is applicable to WMTS services published by third parties.
canvasWidth Number optional The side length of the texture used to draw the vector. The default is 512, the larger the finer, the smaller the higher the performance.
tileWidth String The tile width is suitable for WMTS services released by third parties.
tileHeight String The tile height is suitable for WMTS services released by third parties.
format String 'mvt' optional Applicable to WMTS services published by third parties.
tilematrxset String The name of the slicing matrix set is applicable to WMTS services published by third parties.
maximumLevel Number optional The maximum level of data. It is applicable to WMTS services published by third parties, and is calculated based on service parameters by default.
minimumLevel Number optional The smallest level of data. It is applicable to WMTS services published by third parties, and is calculated based on service parameters by default.
mapboxStyle Object optional The mapBox style used.
maximumTerrainLevel Number optional The maximum terrain layer number that is allowed to load MVT layers (if not defined, all layers are loaded).
minimumTerrainLevel Number optional The minimum terrain layer number allowed to load MVT layers (if not defined, all layers are loaded).
labelScaleByDistance Number optional Set the text to scale with the distance.
See:

cartesianToCanvasCoordinates(position, result)Cartesian2

Convert 3D space coordinates to canvas coordinates (window coordinates).
Name Type Description
position Cartesian3 3D spatial coordinates.
result Cartesian2 optional Window coordinates, used to save the results.
Returns:
Window coordinates.
Example:
//The window coordinates with latitude and longitude (0,0) are output as the mouse moves.
var scene = widget.scene;
var ellipsoid = scene.globe.ellipsoid;
var position = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
var 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

Clamps the given cartesian position to the scene geometry along the geodetic surface normal. Returns the clamped position or undefined 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.

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 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:
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 is only supported in 3D mode.
  • DeveloperError : clampToHeight requires depth texture support. Check clampToHeightSupported.
Example:
// Clamp an entity to the underlying scene geometry
var position = entity.position.getValue(Cesium.JulianDate.now());
entity.position = viewer.scene.clampToHeight(position);
See:

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

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.
Name Type Default Description
cartesians Array.<Cartesian3> The cartesian positions to update with clamped positions.
objectsToExclude Array.<Object> optional 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:
A promise that resolves to the provided list of positions when the query has completed.
Throws:
  • DeveloperError : clampToHeightMostDetailed is only supported in 3D mode.
  • DeveloperError : clampToHeightMostDetailed requires depth texture support. Check clampToHeightSupported.
Example:
var cartesians = [
    entities[0].position.getValue(Cesium.JulianDate.now()),
    entities[1].position.getValue(Cesium.JulianDate.now())
];
var promise = viewer.scene.clampToHeightMostDetailed(cartesians);
promise.then(function(updatedCartesians) {
    entities[0].position = updatedCartesians[0];
    entities[1].position = updatedCartesians[1];
}
See:

getCompressedTextureFormatSupported(format)boolean

Whether the current scene supports texture compression format.
Name Type Description
format String Texture format. Format name or WebGL extension. For example: s3tc or WEBGL_compressed_texture_s3tc.
Returns:
Whether the format is supported.

getHeight(lon, lat)Number

Obtain the corresponding height according to the latitude and longitude coordinates.
Name Type Description
lon Number Longitude coordinates.
lat Number Latitude coordinates.
Returns:
Height value, unit: meter.

getPickRectIDs()Array

Get the selected ID. What is returned is an array of objects, each object contains layer ID (layerID) and selected object ID (ids)
Returns:
id array

getVectorTilesMap(name)Layer

Get the vector tile map according to the specified name.
Name Type Description
name String The name of the vector tile map
Returns:
Map obtained

getViewport(windowPosition)BoundingRectangle

According to the window coordinates, get the current scene viewport.
Name Type Description
windowPosition Cartesian2 Window coordinates.
Returns:
Viewport.

open(url, sceneName, options)Promise

Open all layers under iserver scene service
Name Type Description
url String Service url
sceneName String There are multiple scenes in the workspace, you need to specify the scene name; set to undefined, the first one is opened by default
options Object optional The object has the following properties:
Name Type Default Description
subdomains Array Used for subdomains, for example: ['t1','t2'].
autoSetView Boolean true optional Whether to automatically locate the scene
Returns:
Return promise asynchronous loading object
Example:
var promise = scene.open('http://localhost:8090/iserver/services/3D-BIM3/rest/realspace');
promise.then(function(layers){});

//Subdomain and non-automatic positioning usage
var promise = scene.open('http://{s}.supermap.com:8090/iserver/services/3D-BIM3/rest/realspace',undefined,{
    subdomains: ['t1', 't2'],//子域
    autoSetView : false      //不自动定位
});
promise.then(function(layers){});

outputSceneToFile()Promise

Output the current scene to Base64 encoding.
Returns:
Holds a Base64-encoded asynchronous object.
Example:
var promise =  scene.outputSceneToFile();
  Cesium.when(promise,function(base64data){
     $("#ID").css("background","url(" + base64data +")");
   })

parsePBRFromJson()

Analyze PBR material parameters.
Example:
scene.parsePBRFromJson(urls);
var conditions=[
['${id}<=80',0],
['${id}<=90',1],
['${id}<=100',2],
];

pick(windowPosition, width, height)Object

Scene picking, returns the first primitive object corresponding to the window position in the scene, and returns undefined if there is no object at that position.
Name Type Default Description
windowPosition Cartesian2 Window coordinates.
width Number 3 optional Pick the rectangle width.
height Number 3 optional Pick the height of the rectangle.
Returns:
The picked primitive object.
Throws:

pickNormal(windowPosition)Cartesian3

Used to pick up the normal, pass in the screen coordinates, and return to the normal. Combine the selected offset to achieve the effect of offset along the normal direction.
Name Type Description
windowPosition Cartesian2 Window coordinates to perform picking on. Picked screen coordinates.
Returns:
Normal. The normal vector picked up; if the picked up is not an S3M model, it returns undefined. //

pickPosition(windowPosition, result)Cartesian3

Position picking, according to the window coordinates, pick the corresponding position from the depth buffer of the scene, and return to Cartesian coordinates. It needs to support depth texture.
Name Type Description
windowPosition Cartesian2 Window coordinates.
result Cartesian3 optional Cartesian coordinates, save and return the result.
Returns:
Returns the corresponding Cartesian coordinates (three-dimensional world coordinates).
Throws:
  • DeveloperError : Picking from depth texture is not supported, please check pickPositionSupported. 2D is not supported. The orthogonal projection matrix is not invertible.

pickRect(startPoint, endPoint)Number

Window selection
Name Type Description
startPoint Object Box start point
endPoint Object Box end point
Returns:

removeLightSource(lightSource)Scene

Delete the light source.
Name Type Description
lightSource LightSource light source.
Returns:
The scene after adding the light source.

removeVectorTilesMap(name)boolean

Remove the vector tile map with the specified name.
Name Type Description
name String Specify the name of the vector tile map to be removed.
Returns:

sampleHeight(position, objectsToExclude, width)Number

Returns the height of scene geometry at the given cartographic position or undefined 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.

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 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 is only supported in 3D mode.
  • DeveloperError : sampleHeight requires depth texture support. Check sampleHeightSupported.
Example:
var position = new Cesium.Cartographic(-1.31968, 0.698874);
var height = viewer.scene.sampleHeight(position);
console.log(height);
See:

sampleHeightMostDetailed(positions, objectsToExclude, width)Promise.<Array.<Number>>

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 undefined.
Name Type Default Description
positions Array.<Cartographic> The cartographic positions to update with sampled heights.
objectsToExclude Array.<Object> optional 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:
A promise that resolves to the provided list of positions when the query has completed.
Throws:
  • DeveloperError : sampleHeightMostDetailed is only supported in 3D mode.
  • DeveloperError : sampleHeightMostDetailed requires depth texture support. Check sampleHeightSupported.
Example:
var positions = [
    new Cesium.Cartographic(-1.31968, 0.69887),
    new Cesium.Cartographic(-1.10489, 0.83923)
];
var 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:

setVectorTilesLayersControl(control, level)

Set the display level control of MVT.
Name Type Description
control Boolean Whether to control the display level of MVT.
level Number From the current perspective from near to far, the total number of levels displayed. For example, if it is set to 3, only the first three layers closest to the camera will be displayed, and the fourth and subsequent layers will not be displayed.