Terrain

new Cesium.Terrain(terrainProviderPromise)

A helper to manage async operations of a terrain provider.
Name Type Description
terrainProviderPromise Promise.<TerrainProvider> A promise which resolves to a terrain provider
Examples:
// 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}`);
});
See:

Members

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.

Methods

static Cesium.Terrain.fromWorldBathymetry(options)Terrain

Creates a Terrain instance for Cesium World Bathymetry.
Name Type Description
options Object optional Object with the following properties:
Name Type Default Description
requestVertexNormals Boolean false optional Flag that indicates if the client should request additional lighting information from the server if available.
Returns:
An asynchronous helper object for a CesiumTerrainProvider
Examples:
// 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}`);
});
See:

static Cesium.Terrain.fromWorldTerrain(options)Terrain

Creates a Terrain instance for Cesium World Terrain.
Name Type Description
options Object optional Object with the following properties:
Name Type Default Description
requestVertexNormals Boolean false optional Flag that indicates if the client should request additional lighting information from the server if available.
requestWaterMask Boolean false optional Flag that indicates if the client should request per tile water masks from the server if available.
Returns:
An asynchronous helper object for a CesiumTerrainProvider
Examples:
// 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}`);
});
See:

Type Definitions

Cesium.Terrain.ErrorEventCallback(err)

A function that is called when an error occurs.
This:
Name Type Description
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:
Name Type Description
provider TerrainProvider The created terrain provider.
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.