一个简单的 A simple
TerrainProvider 从回调函数获取高度值。它可用于程序生成的地形或作为加载自定义高度图数据的方法,而无需创建 that gets height values from a callback function. It can be used for procedurally generated terrain or as a way to load custom heightmap data without creating a subclass of TerrainProvider。有一些限制,例如没有水掩模,没有顶点法线,并且没有可用性,所以一个成熟的 . There are some limitations such as no water mask, no vertex normals, and no availability, so a full-fledged TerrainProvider 子类更适合这些更复杂的用例。 subclass is better suited for these more sophisticated use cases.
| 名称 Name | 类型 Type | 说明 Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象: Object with the following properties:
|
示例: Example:
const viewer = new Cesium.Viewer("cesiumContainer", {
terrainProvider: new Cesium.CustomHeightmapTerrainProvider({
width: 32,
height: 32,
callback: function (x, y, level) {
return new Float32Array(32 * 32); // all zeros
},
}),
});
另见: See:
成员 Members
readonly availability : TileAvailability
获取一个对象,该对象可用于确定此提供者提供的地形的可用性,例如点和矩形中的地形。如果可用性信息不可用,则此属性可能未定义。 Gets an object that can be used to determine availability of terrain from this provider, such as at points and in rectangles. This property may be undefined if availability information is not available.
readonly credit : Credit
获取此地形提供程序处于活动状态时要显示的积分。通常,这用于证明地形的来源。 Gets the credit to display when this terrain provider is active. Typically this is used to credit the source of the terrain.
readonly errorEvent : Event
获取当地形提供程序遇到异步错误时引发的事件。通过订阅该事件,您将收到错误通知,并有可能从中恢复。事件监听器传递一个实例 Gets an event that is raised when the terrain provider encounters an asynchronous error. By subscribing to the event, you will be notified of the error and can potentially recover from it. Event listeners are passed an instance of
TileProviderError.
获取一个值,该值指示请求的切片是否包含顶点法线。不支持顶点法线 Gets a value indicating whether or not the requested tiles include vertex normals. Vertex normals are not supported by
CustomHeightmapTerrainProvider,因此返回值将始终为 false。 , so the return value will always be false.
获取一个值,该值指示提供程序是否包含水罩。水掩模指示地球的哪些区域是水而不是陆地,因此可以将它们渲染为带有动画波浪的反射表面。水面膜不支持 Gets a value indicating whether or not the provider includes a water mask. The water mask indicates which areas of the globe are water rather than land, so they can be rendered as a reflective surface with animated waves. Water mask is not supported by
CustomHeightmapTerrainProvider,因此返回值将始终为 false。 , so the return value will always be false.
获取每个高度图图块的行数。 Gets the number of rows per heightmap tile.
readonly tilingScheme : TilingScheme
获取此提供程序使用的切片方案。 Gets the tiling scheme used by this provider.
获取每个高度图图块的列数。 Gets the number of columns per heightmap tile.
方法 Methods
获取给定级别的图块中允许的最大几何误差。 Gets the maximum geometric error allowed in a tile at a given level.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
level |
number | 获得最大几何误差的图块级别。 The tile level for which to get the maximum geometric error. |
返回: Returns:
最大几何误差。 The maximum geometric error.
确定图块的数据是否可供加载。 Determines whether data for a tile is available to be loaded.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
x |
number | 请求几何图形的图块的 X 坐标。 The X coordinate of the tile for which to request geometry. |
y |
number | 请求几何图形的图块的 Y 坐标。 The Y coordinate of the tile for which to request geometry. |
level |
number | 请求几何图形的图块的级别。 The level of the tile for which to request geometry. |
返回: Returns:
如果不支持则未定义,否则 true 或 false。 Undefined if not supported, otherwise true or false.
确保我们加载图块的可用性数据 Makes sure we load availability data for a tile
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
x |
number | 请求几何图形的图块的 X 坐标。 The X coordinate of the tile for which to request geometry. |
y |
number | 请求几何图形的图块的 Y 坐标。 The Y coordinate of the tile for which to request geometry. |
level |
number | 请求几何图形的图块的级别。 The level of the tile for which to request geometry. |
返回: Returns:
如果不需要加载任何内容,或者在加载所有必需的图块时解析的 Promise,则为未定义 Undefined if nothing need to be loaded or a Promise that resolves when all required tiles are loaded
requestTileGeometry(x, y, level, request) → Promise.<TerrainData>|undefined
请求给定图块的几何形状。结果包括地形数据并指示所有子图块均可用。 Requests the geometry for a given tile. The result includes terrain data and indicates that all child tiles are available.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
x |
number | 请求几何图形的图块的 X 坐标。 The X coordinate of the tile for which to request geometry. |
y |
number | 请求几何图形的图块的 Y 坐标。 The Y coordinate of the tile for which to request geometry. |
level |
number | 请求几何图形的图块的级别。 The level of the tile for which to request geometry. |
request |
Request | 可选 optional 请求对象。仅供内部使用。 The request object. Intended for internal use only. |
返回: Returns:
对所要求的几何形状的承诺。如果此方法返回未定义而不是承诺,则表明已有太多请求处于待处理状态,稍后将重试该请求。 A promise for the requested geometry. If this method returns undefined instead of a promise, it is an indication that too many requests are already pending and the request will be retried later.
类型定义 Type Definitions
Cesium.CustomHeightmapTerrainProvider.GeometryCallback(x, y, level) → Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|Array.<number>|Promise.<(Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|Array.<number>)>|undefined
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
x |
number | 请求几何图形的图块的 X 坐标。 The X coordinate of the tile for which to request geometry. |
y |
number | 请求几何图形的图块的 Y 坐标。 The Y coordinate of the tile for which to request geometry. |
level |
number | 请求几何图形的图块的级别。 The level of the tile for which to request geometry. |
返回: Returns:
一个数组或对按行优先顺序排列的高度数组的承诺。如果未定义,地球将渲染父图块。 An array or a promise to an array of heights in row-major order. If undefined, the globe will render the parent tile.
