Scene

new SuperMap3D.Scene(options)

三维场景类,它是所有三维图形对象和状态的容器,通常不直接创建场景,而是由Widget隐式创建。

contextOptions参数详细信息:

默认值为: { webgl : { alpha : false, depth : true, stencil : false, antialias : true, premultipliedAlpha : true, preserveDrawingBuffer : false, failIfMajorPerformanceCaveat : false }, allowTextureFilterAnisotropic : true }

webgl属性对应用于创建WebGL环境的WebGLContextAttributes对象。

webgl.alpha默认为false,与标准WebGL默认值为true相比,这可以提高性能。

其他webgl属性与WebGLContextAttributes.的WebGL默认值匹配。

allowTextureFilterAnisotropic默认为true,这允许在支持WebGL扩展时进行各向异性纹理过滤。设置为false可以提高性能,但会损害视觉质量,特别是对于水平视图。

Name Type Description
options Object optional 对象具有以下属性:
Name Type Default Description
canvas Canvas 用于创建场景的HTML canvas元素。
contextOptions Object optional 环境和WebGL创建属性,详见上述。
creditContainer Element optional 用于显示服务描述信息的HTML元素。
mapProjection MapProjection new GeographicProjection() optional 在二维和Columbus 视图模式下使用的地图投影。
orderIndependentTranslucency Boolean true optional 如果此项设置为true,并且使用设备支持,将使用与顺序无关的半透明。
scene3DOnly Boolean false optional 如果此项设置为true,将优化三维模式的内存使用和性能,但禁止使用二维或Columbus视图功能。
terrainExaggeration Number 1.0 optional 用于夸大地形的标量。请注意,设置地形夸张不会修改其它任何数据。
shadows Boolean false optional 确定阴影是否由太阳投射形成。
mapMode2D MapMode2D MapMode2D.INFINITE_SCROLL optional 确定二维地图是可旋转的或是可以在在水平方向上无限滚动。
Throws:
Example:
//创建一个场景。
var viewer=new new SuperMap3D.Viewer('Container');
var scene = viewer.scene;
See:

Members

bloomEffect : BloomEffect

获取场景的泛光效果,包括泛光强度值,泛光亮度阈值等。

readonlycamera : Camera

获取当前场景的相机对象。

readonlycanvas : Element

获取scene绑定的canvas元素。

colorCorrection

创建颜色校正对象

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

该属性仅用于调试,不用于生产。当为true时,绘制轮廓线展示相机平台的范围。
Default Value: false

depthOfFieldEffect : DepthOfFieldEffect

获取场景的景深效果。

readonlydrawingBufferHeight : Number

GL绘制缓冲区高度。
See:

readonlydrawingBufferWidth : Number

GL绘制缓冲区宽度。
See:

enableCompositor : Boolean

获取或者设置是否将场景绘制成图片。当关闭时,直接绘制到颜色缓冲区,画面效果更佳,但一些分析功能不可用。默认值为true。

enableOcclude

当前场景是否开启遮挡剔除。
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.

frustumTolerance : Number

设置视锥体容限值,默认值为0.0,最大值为0.5
Default Value: 0.0

globe : Globe

获取地球对象。

globeSplitPosition : Cartesian2

设置或获取当前场景的卷帘位置,有效值为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

获取所有贴地图元集合。

hdrEnabled

当前场景是否开启hdr。
Default Value: false

readonlyid : String

获取当前场景的id。

readonlyimageryLayers : ImageryLayerCollection

获取当前场景影像图层集合。

imagerySplitPosition : Number

设置或获取当前场景的影像分隔条位置。

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

获取当前场景的三维切片缓存图层集合。

lightSource : LightSource

获取当前场景中的光源。

logarithmicDepthBuffer : Boolean

获取或者设置是否使用对数深度缓冲区。当设置为true时,将会在混合多截锥中使用较少的截锥,详情可参见Cesium官网的说明。

readonlymapProjection : MapProjection

获取地图投影对象,用于2D或者Columbus View模式,默认为经纬度投影。
Default Value: new GeographicProjection()

minimumDisableDepthTestDistance : Number

通过设置相机视角距离禁止布告板、标签和点对象的深度测试。例如,为了防止剪切地形数据,将距离设置为0则深度测试一直有效,将距离设置为小于0则深度测试失效。通过设置布告板、标签和点对象的disableDepthTestDistance属性修改距离值。
Default Value: 0.0

mode : SceneMode

获取当前场景的模式。
Default Value: SceneMode.SCENE3D

MultiViewportMode : Number

获取或者设置当前场景的多视口模式,默认单视口。
Default Value: 0
See:

originOffset : Cartesian2

设置度带偏移,加载有度带偏移的地图

overlapDisplayOptions : Object

设置图层的避让参数。 可设置的参数为:allowIconWithTextDisplay,设置是否开启图标图层跟随文字图层避让。默认为true.

pickPointEnabled : Boolean

开启顶点捕捉功能,默认false,设置为true,则开启捕捉。

pickPointInterval : Number

设置点云捕捉的时间间隔
Default Value: 200

pickTranslucentDepth : Boolean

当为true时,支持使用深度缓冲区拾取半透明的几何图形。Scene#useDepthPicking也必须为true,支持拾取深度缓冲区。使用时性能有所下降,对于半透明的几何图形,将调用额外的绘图命令写入深度。
Default Value: false

readonlypostRender : Event

获取当前场景每帧渲染结束时的事件,监听该事件在每帧渲染结束时触发。

readonlypreRender : Event

获取当前场景每帧渲染前的事件,监听该事件在每帧渲染之前触发。

readonlyprimitives : PrimitiveCollection

获取所有图元集合。

rasterVectorCollection : Object

获取实时栅格化对象。

scanEffect : ScanEffect

获取场景的扫描线效果。

readonlyscreenSpaceCameraController : ScreenSpaceCameraController

获取当前场景的相机操作对象。

shadowMap : ShadowMap

场景中的阴影贴图。启用时,模型、图元和地球可以投射和接收阴影。默认情况下,阴影贴图的光源是太阳。

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

获取或者设置当前场景的地形服务provider对象。

readonlyterrainProviderChanged : Event

获取当前场景地形服务provider改变事件。

toneMappingEnabled

当前场景是否开启toneMapping。

readonlytoneMappingExposure : Number

获取或设置PBR材质模型整体亮度。
Default Value: 1.0

readonlyunderGlobe : UnderGlobe

获取地下球。

undergroundDepth : Number

获取或者设置地下场景深度,默认1000米(单位:米)。

undergroundMode : Boolean

获取或者设置是否开启地下场景。
Default Value: false

walkingMode : Number

获取或者设置相机模式
Default Value: WalkingMode.NONE
See:

readonlywaterReflectionDistinctQuality : Number

获取或设置水面反射倒影清晰度,值越小越反射倒影模糊。
Default Value: 5.0

Methods

addFieldLayer(url)Promise

根据url路径添加场数据图层。
Name Type Description
url String 场数据的url路径。
Returns:
返回场数据图层FieldLayer3D,异步创建场图层对象。
Example:
var promise =  viewer.scene.addFieldLayer("../data.nc");
 SuperMap3D.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)

添加场景图层服务。
Name Type Description
url String 图层服务的url路径。
sceneName String 场景名称。
layerName String 图层名称。

addLightSource(lightSource)Scene

添加光源。
Name Type Description
lightSource LightSource 光源。
Returns:
添加点光源后后的场景。

addS3MGroupLayer(url, options, index)Promise

添加S3M分组图层。
Name Type Description
url String iserver中发布的配置文件地址。
options Object 图层所需属性对象。
index Number 索引。
Returns:
返回promise异步加载对象

addS3MTilesLayerByScp(url, options, index)Promise

添加三维切片缓存图层(S3M、S3MB)。
Name Type Description
url String iserver中发布的配置文件地址。
options Object optional 对象具有以下属性:
Name Type Default Description
subdomains Array 用于子域,例如:['t1','t2']。
name String 指定图层名称。
cullEnabled Boolean false optional 是否剔除背面,默认为不剔除,即双面渲染。
index Number 索引。
Returns:
返回promise异步加载对象
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;
});

//子域用法
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)

添加矢量瓦片图层服务。为了保证版本的稳定性,采用该接口创建的MVT图层依然保持原来的使用和实现方式,但不支持VectorTileMap中新增的接口,推荐使用新的实现方式addVectorTilesMap。
Name Type Description
options Object 参数对象包含以下属性:
Name Type Default Description
url String 适用于通过SuperMap桌面软件生成mvt数据,经iServer发布为rest风格的地图服务,只需提供服务地址。
url String 服务地址,适用于第三方发布的WMTS服务。
layer String 图层名称,适用于第三方发布的WMTS服务。
canvasWidth Number optional 用来绘制矢量的纹理边长。默认是512,越大越精细,越小性能越高。
tileWidth String 瓦片宽度,适用于第三方发布的WMTS服务。
tileHeight String 瓦片高度,适用于第三方发布的WMTS服务。
format String 'mvt' optional 适用于第三方发布的WMTS服务。
tilematrxset String 切片矩阵集名称,适用于第三方发布的WMTS服务。
maximumLevel Number optional 数据的最大层级。适用于第三方发布的WMTS服务,默认根据服务参数计算。
minimumLevel Number optional 数据的最小层级。适用于第三方发布的WMTS服务,默认根据服务参数计算。
mapboxStyle Object optional 使用的mapBox风格。
maximumTerrainLevel Number optional 允许加载MVT图层的最大地形层号(如果未定义则所有层都加载)。
minimumTerrainLevel Number optional 允许加载MVT图层的最小地形层号(如果未定义则所有层都加载)。
simplifyTolerance Number optional 进行几何简化的坐标容限,单位为切片坐标系,值域为0-4096。值越大简化得越厉害,默认是0,不简化。
viewer Object optional 设置将要添加到的地球
Example:
var layer = scene.addVectorTilesLayer({
    url:"http://localhost:8090/iserver/services/map-mvt-test/....../maps/test"//地图服务
});
See:

addVectorTilesMap(options)

新建一个矢量瓦片地图。
Name Type Description
options 新建地图包含以下参数:
Name Type Default Description
url String 适用于通过SuperMap桌面软件生成mvt数据,经iServer发布为rest风格的地图服务,只需提供服务地址。
layer String 图层名称,适用于第三方发布的WMTS服务。
canvasWidth Number optional 用来绘制矢量的纹理边长。默认是512,越大越精细,越小性能越高。
tileWidth String 瓦片宽度,适用于第三方发布的WMTS服务。
tileHeight String 瓦片高度,适用于第三方发布的WMTS服务。
format String 'mvt' optional 适用于第三方发布的WMTS服务。
tilematrxset String 切片矩阵集名称,适用于第三方发布的WMTS服务。
maximumLevel Number optional 数据的最大层级。适用于第三方发布的WMTS服务,默认根据服务参数计算。
minimumLevel Number optional 数据的最小层级。适用于第三方发布的WMTS服务,默认根据服务参数计算。
mapboxStyle Object optional 使用的mapBox风格。
maximumTerrainLevel Number optional 允许加载MVT图层的最大地形层号(如果未定义则所有层都加载)。
minimumTerrainLevel Number optional 允许加载MVT图层的最小地形层号(如果未定义则所有层都加载)。
labelScaleByDistance Number optional 设置文字随距离缩放。
customRequestHeaders Object optional 设置自定义请求头。
realtime Boolean optional 设置是否实时栅格化。
swipeEnabled Boolean optional 设置是否卷帘。
swipeRegion Object optional 设置卷帘区域。
billboardMode BillboardMode optional 设置文字标签样式。
labelDepthTestEnabled Boolean optional 用于控制MVT文字/图标是否做深度检测。默认为true,开启深度检测,反之则关闭深度检测。
viewer Object optional 设置将要添加到的地球
See:

cartesianToCanvasCoordinates(position, result)Cartesian2

转换三维空间坐标到canvas坐标(窗口坐标)。
Name Type Description
position Cartesian3 三维空间坐标。
result Cartesian2 optional 窗口坐标,用于保存结果。
Returns:
窗口坐标。
Example:
//随着鼠标移动输出经纬度为(0,0)的窗口坐标。
var scene = widget.scene;
var ellipsoid = scene.globe.ellipsoid;
var position = SuperMap3D.Cartesian3.fromDegrees(0.0, 0.0);
var handler = new SuperMap3D.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
    console.log(scene.cartesianToCanvasCoordinates(position));
}, SuperMap3D.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(SuperMap3D.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(SuperMap3D.JulianDate.now()),
    entities[1].position.getValue(SuperMap3D.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

当前场景是否支持纹理压缩格式。
Name Type Description
format String 纹理格式。格式名称或WebGL扩展名。例如:s3tc 或 WEBGL_compressed_texture_s3tc。
Returns:
该格式是否被支持。

getHeight(lon, lat)Number

根据经纬度坐标获取对应高度。
Name Type Description
lon Number 经度坐标。
lat Number 纬度坐标。
Returns:
高度值,单位:米。

getPickRectIDs()Array

获取选中ID。返回的是对象数组,每个对象包含图层ID(layerID)和选中对象ID(ids)
Returns:
id数组

getPickRectIDsAsync()Array

异步获取选中ID。返回的是对象数组,每个对象包含图层ID(layerID)和选中对象ID(ids)
Returns:
id数组

getVectorTilesMap(name)Layer

根据指定名称获取矢量瓦片地图。
Name Type Description
name String 矢量瓦片地图的名称
Returns:
获取的地图

getViewport(windowPosition)BoundingRectangle

根据窗口坐标,获取当前场景视口。
Name Type Description
windowPosition Cartesian2 窗口坐标。
Returns:
视口。

open(url, sceneName, options)Promise

打开iserver场景服务下所有图层
Name Type Description
url String 服务url
sceneName String 工作空间中有多个场景,需要指定场景名称;设置为undefined,默认打开第一个
options Object optional 对象具有以下属性:
Name Type Default Description
subdomains Array 用于子域,例如:['t1','t2']。
autoSetView Boolean true optional 是否自动定位到场景
Returns:
返回promise异步加载对象
Example:
var promise = scene.open('http://localhost:8090/iserver/services/3D-BIM3/rest/realspace');
promise.then(function(layers){});

//子域和不自动定位用法
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

将当前场景输出Base64编码。
Returns:
持有Base64编码的异步对象。
Example:
var promise =  scene.outputSceneToFile();
  SuperMap3D.when(promise,function(base64data){
     $("#ID").css("background","url(" + base64data +")");
   })

parsePBRFromJson()

解析PBR材质参数。
Example:
scene.parsePBRFromJson(urls);
var conditions=[
['${id}<=80',0],
['${id}<=90',1],
['${id}<=100',2],
];

pick(windowPosition, width, height)Object

场景拾取,返回在场景中该窗口位置对应的第一个图元对象,如果该位置没有任何物体则返回undefined。
Name Type Default Description
windowPosition Cartesian2 窗口坐标。
width Number 3 optional 拾取矩形宽度。
height Number 3 optional 拾取矩形高度。
Returns:
拾取的图元对象。
Throws:

pickNormal(windowPosition)Cartesian3

用于拾取法线,传入屏幕坐标,返回法线。结合选中偏移可以实现沿法线方向偏移的效果。
Name Type Description
windowPosition Cartesian2 Window coordinates to perform picking on.拾取的屏幕坐标。
Returns:
Normal.拾取到的法线向量;如果拾取到的不是S3M模型,则返回undefined。 //

pickPosition(windowPosition, result)Cartesian3

位置拾取,根据窗口坐标,从场景的深度缓冲区中拾取相应的位置,返回笛卡尔坐标,需要支持深度纹理。
Name Type Description
windowPosition Cartesian2 窗口坐标。
result Cartesian3 optional 笛卡尔坐标,保存返回结果。
Returns:
返回相应的笛卡尔坐标(三维世界坐标)。
Throws:
  • DeveloperError : 不支持从深度纹理中拾取,请检查 pickPositionSupported。不支持2D。正交投影矩阵不可逆。

pickRect(startPoint, endPoint)

框选
Name Type Description
startPoint Object 框选起始点。
endPoint Object 框选终止点。

removeLightSource(lightSource)Scene

删除光源。
Name Type Description
lightSource LightSource 光源。
Returns:
添加光源后后的场景。

removeVectorTilesMap(name)Boolean

按指定名称移除矢量瓦片地图。
Name Type Description
name String 指定拟移除的矢量瓦片地图的名称。
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 SuperMap3D.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 SuperMap3D.Cartographic(-1.31968, 0.69887),
    new SuperMap3D.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)

设置MVT的显示层级控制。
Name Type Description
control Boolean 是否对MVT的显示层级进行控制。
level Number 从当前视角由近及远,总共显示的层级数。例如设置为3,则只显示距离相机最近的前三层,第4层及以后的不会显示。