[CesiumJS]Cesium Getting Started 7 - Adding Terrain

Cesium supports streaming, visualizable global elevation terrain data, including oceans, lakes, rivers, mountains, canyons, and other terrain data that can be rendered in 3D with better results than 2D. Like imagery data, the Cesium engine requests streaming terrain data from a server, only requesting data for the layers that need to be rendered based on the current camera view.

Cesium provides some terrain dataset examples and how to configure these parameters:

Supported terrain data formats

  • Quantized-mesh, an open-source format developed by the Cesium team
  • Heightmap
  • Google Earth Enterprise

To add terrain data, we need to create a CesiumTerrainProvider, provide a URL and some configuration options, and then assign this provider to viewer.terrainProvider.

Here, we use Cesium World Terrain, which is provided by Cesium ion and is available by default in “My Assets”. We can create a Cesium World Terrain served by Cesium ion using the createWorldTerrain helper function.

1
2
3
4
5
// Load Cesium World Terrain
viewer.terrainProvider = Cesium.createWorldTerrain({
    requestWaterMask : true, // required for water effects
    requestVertexNormals : true // required for terrain lighting
});

requestWaterMask and requestVertexNormals are optional configuration items that tell Cesium whether to request additional water and lighting data. Both options are set to false by default.

Finally, since we now have terrain data, we need more lines to ensure that objects behind the terrain are displayed correctly – only the frontmost, topmost objects should be visible.

1
2
// Enable depth testing so things behind the terrain disappear.
viewer.scene.globe.depthTestAgainstTerrain = true;

We now have terrain data and moving water. New York is very flat, so you can freely explore the terrain data above. For a more obvious example, you can navigate to more rugged areas like the Grand Canyon or San Francisco.

For more information about terrain data, please visit the Terrain Tutorial

Cesium Chinese Community QQ Group: 807482793

Original link: http://cesiumcn.org/topic/157.html | China fast access: http://cesium.coinidea.com/topic/157.html