Terrain

new Cesium.Terrain(terrainProviderPromise)

A helper to manage async operations of a terrain provider.
参数名称 类型 描述信息
terrainProviderPromise Promise.<TerrainProvider> A promise which resolves to a terrain provider
使用示例s:
// Create
const viewer = new Cesium.Viewer("cesiumContainer", {
  terrain: new Cesium.Terrain(Cesium.CesiumTerrainProvider.fromUrl("https://myTestTerrain.com"));
});
// Handle loading events
const terrain = new Cesium.Terrain(Cesium.CesiumTerrainProvider.fromUrl("https://myTestTerrain.com"));

scene.setTerrain(terrain);

terrain.readyEvent.addEventListener(provider => {
  scene.globe.enableLighting = true;

  terrain.provider.errorEvent.addEventListener(error => {
    alert(`Encountered an error while loading terrain tiles! ${error}`);
  });
});

terrain.errorEvent.addEventListener(error => {
  alert(`Encountered an error while creating terrain! ${error}`);
});
参考:

成员(属性)

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 the thrown error.
Gets an event that is raised when the terrain provider has been successfully created. Event listeners are passed the created instance of TerrainProvider.

方法

static Cesium.Terrain.fromWorldBathymetry(options)Terrain

Creates a Terrain instance for Cesium World Bathymetry.
参数名称 类型 描述信息
options Object 可选 Object with the following properties:
参数名称 类型 默认值 描述信息
requestVertexNormals Boolean false 可选 Flag that indicates if the client should request additional lighting information from the server if available.
返回值:
An asynchronous helper object for a CesiumTerrainProvider
使用示例s:
// Create Cesium World Bathymetry with default settings
const viewer = new Cesium.Viewer("cesiumContainer", {
  terrain: Cesium.Terrain.fromWorldBathymetry)
});
// Create Cesium World Terrain with normals.
const viewer1 = new Cesium.Viewer("cesiumContainer", {
  terrain: Cesium.Terrain.fromWorldBathymetry({
     requestVertexNormals: true
   });
});
// Handle loading events
const bathymetry = Cesium.Terrain.fromWorldBathymetry();

scene.setTerrain(bathymetry);

bathymetry.readyEvent.addEventListener(provider => {
  scene.globe.enableLighting = true;

  bathymetry.provider.errorEvent.addEventListener(error => {
    alert(`Encountered an error while loading bathymetric terrain tiles! ${error}`);
  });
});

bathymetry.errorEvent.addEventListener(error => {
  alert(`Encountered an error while creating bathymetric terrain! ${error}`);
});
参考:

static Cesium.Terrain.fromWorldTerrain(options)Terrain

Creates a Terrain instance for Cesium World Terrain.
参数名称 类型 描述信息
options Object 可选 Object with the following properties:
参数名称 类型 默认值 描述信息
requestVertexNormals Boolean false 可选 Flag that indicates if the client should request additional lighting information from the server if available.
requestWaterMask Boolean false 可选 Flag that indicates if the client should request per tile water masks from the server if available.
返回值:
An asynchronous helper object for a CesiumTerrainProvider
使用示例s:
// Create Cesium World Terrain with default settings
const viewer = new Cesium.Viewer("cesiumContainer", {
  terrain: Cesium.Terrain.fromWorldTerrain()
});
// Create Cesium World Terrain with water and normals.
const viewer1 = new Cesium.Viewer("cesiumContainer", {
  terrain: Cesium.Terrain.fromWorldTerrain({
     requestWaterMask: true,
     requestVertexNormals: true
   });
});
// Handle loading events
const terrain = Cesium.Terrain.fromWorldTerrain();

scene.setTerrain(terrain);

terrain.readyEvent.addEventListener(provider => {
  scene.globe.enableLighting = true;

  terrain.provider.errorEvent.addEventListener(error => {
    alert(`Encountered an error while loading terrain tiles! ${error}`);
  });
});

terrain.errorEvent.addEventListener(error => {
  alert(`Encountered an error while creating terrain! ${error}`);
});
参考:

定义的类型

Cesium.Terrain.ErrorEventCallback(err)

A function that is called when an error occurs.
This:
参数名称 类型 描述信息
err Error An object holding details about the error that occurred.

Cesium.Terrain.ReadyEventCallback(provider)

A function that is called when the provider has been created
This:
参数名称 类型 描述信息
provider TerrainProvider The created terrain provider.