Scene using the elevation service to drape the topographic basemap layer

What is terrain rendering?

Terrain rendering is the process of displaying elevation in a 3D scene. The starting point for rendering terrain in a scene is a digital elevation model. Publish this dataset as an elevation service and then load it in your application as an elevation layer. If you don’t have your own elevation model, you can use Esri’s World Elevation Service.

The elevation layer is not visible in a 3D scene, but you can render a basemap layer draped on top of the elevation layer. Data layers can be draped on the elevation layer and placed at an absolute height or a relative one. When a 3D scene doesn’t have an elevation layer, the terrain is rendered as a plane displayed at zero height (sea level).

How to render terrain and align data layers to terrain

You can render terrain by adding an elevation layer and a basemap layer to your scene.

48 collapsed lines
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Terrain rendering - elevation and layer alignment</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.2/"></script>
<style>
html,
body {
height: 100%;
margin: 0;
}
</style>
</head>
<body>
<arcgis-scene>
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-expand slot="top-right" expanded>
<arcgis-legend></arcgis-legend>
</arcgis-expand>
</arcgis-scene>
<script type="module">
const [Map, FeatureLayer, ElevationLayer, LabelClass, Basemap, TileLayer] = await $arcgis.import([
"@arcgis/core/Map.js",
"@arcgis/core/layers/FeatureLayer.js",
"@arcgis/core/layers/ElevationLayer.js",
"@arcgis/core/layers/support/LabelClass.js",
"@arcgis/core/Basemap.js",
"@arcgis/core/layers/TileLayer.js",
]);
const viewElement = document.querySelector("arcgis-scene");
const basemap = new Basemap({
baseLayers: [
new TileLayer({
url: "https://wtb.maptiles.arcgis.com/arcgis/rest/services/World_Topo_Base/MapServer",
}),
],
});
const map = new Map({
ground: {
layers: [
new ElevationLayer({
url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer",
}),
],
},
basemap: basemap,
});
92 collapsed lines
viewElement.map = map;
viewElement.camera = {
position: [-118.80714, 33.961442, 1574.65501],
heading: 0.51,
tilt: 78.99,
};
const trails = new FeatureLayer({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",
elevationInfo: {
mode: "relative-to-ground",
offset: 3,
},
renderer: {
type: "simple",
symbol: {
type: "line-3d",
symbolLayers: [
{
type: "line",
material: { color: "#FF5500" },
size: "2px",
},
],
},
},
});
const trailHeads = new FeatureLayer({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",
elevationInfo: {
mode: "relative-to-ground",
},
renderer: {
type: "simple",
symbol: {
type: "point-3d",
symbolLayers: [
{
type: "icon",
resource: { primitive: "circle" },
material: { color: "#FF5500" },
outline: { color: "#FFFFFF", size: 1 },
size: "10px",
},
],
verticalOffset: {
screenLength: 20,
maxWorldLength: 200,
minWorldLength: 20,
},
callout: {
type: "line",
size: 1,
color: "#FFFFFF",
},
},
},
labelingInfo: [
new LabelClass({
labelExpressionInfo: { expression: "$feature.TRL_NAME" },
symbol: {
type: "label-3d",
symbolLayers: [
{
type: "text",
material: {
color: "#FFFFFF",
},
halo: {
size: 1,
color: [0, 0, 0, 0.5],
},
font: {
size: 11,
family: "sans-serif",
},
},
],
},
}),
],
});
map.addMany([trails, trailHeads]);
</script>
</body>
</html>

In most applications, there are additional data layers to add to your scene. The following image shows several options for vertically aligning data layers:

Options for vertically aligning data layers

The hiking trails in the above example are rendered relative to the terrain with an offset of 3 meters:

68 collapsed lines
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Terrain rendering - elevation and layer alignment</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.2/"></script>
<style>
html,
body {
height: 100%;
margin: 0;
}
</style>
</head>
<body>
<arcgis-scene>
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-expand slot="top-right" expanded>
<arcgis-legend></arcgis-legend>
</arcgis-expand>
</arcgis-scene>
<script type="module">
const [Map, FeatureLayer, ElevationLayer, LabelClass, Basemap, TileLayer] = await $arcgis.import([
"@arcgis/core/Map.js",
"@arcgis/core/layers/FeatureLayer.js",
"@arcgis/core/layers/ElevationLayer.js",
"@arcgis/core/layers/support/LabelClass.js",
"@arcgis/core/Basemap.js",
"@arcgis/core/layers/TileLayer.js",
]);
const viewElement = document.querySelector("arcgis-scene");
const basemap = new Basemap({
baseLayers: [
new TileLayer({
url: "https://wtb.maptiles.arcgis.com/arcgis/rest/services/World_Topo_Base/MapServer",
}),
],
});
const map = new Map({
ground: {
layers: [
new ElevationLayer({
url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer",
}),
],
},
basemap: basemap,
});
viewElement.map = map;
viewElement.camera = {
position: [-118.80714, 33.961442, 1574.65501],
heading: 0.51,
tilt: 78.99,
};
const trails = new FeatureLayer({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",
elevationInfo: {
mode: "relative-to-ground",
offset: 3,
},
76 collapsed lines
renderer: {
type: "simple",
symbol: {
type: "line-3d",
symbolLayers: [
{
type: "line",
material: { color: "#FF5500" },
size: "2px",
},
],
},
},
});
const trailHeads = new FeatureLayer({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0",
elevationInfo: {
mode: "relative-to-ground",
},
renderer: {
type: "simple",
symbol: {
type: "point-3d",
symbolLayers: [
{
type: "icon",
resource: { primitive: "circle" },
material: { color: "#FF5500" },
outline: { color: "#FFFFFF", size: 1 },
size: "10px",
},
],
verticalOffset: {
screenLength: 20,
maxWorldLength: 200,
minWorldLength: 20,
},
callout: {
type: "line",
size: 1,
color: "#FFFFFF",
},
},
},
labelingInfo: [
new LabelClass({
labelExpressionInfo: { expression: "$feature.TRL_NAME" },
symbol: {
type: "label-3d",
symbolLayers: [
{
type: "text",
material: {
color: "#FFFFFF",
},
halo: {
size: 1,
color: [0, 0, 0, 0.5],
},
font: {
size: 11,
family: "sans-serif",
},
},
],
},
}),
],
});
map.addMany([trails, trailHeads]);
</script>
</body>
</html>

Examples

Display a scene with elevation

You can display a simple scene using an elevation layer An elevation layer is a layer that defines the ground height or the surface for a scene. Learn more and a basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more . The basemap layer is draped on the elevation layer to create a 3D view. If you would like to display additional data, you can add data layers A data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more or graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more , and render features with 2D or 3D symbols.

Steps

  1. Create a scene and add an elevation layer An elevation layer is a layer that defines the ground height or the surface for a scene. Learn more and a basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more .
  2. Set the scene to scene view.
  3. Set the camera position.
Render terrain and a basemap
33 collapsed lines
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Terrain rendering - scene with elevation</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.2/"></script>
<style>
html,
body {
height: 100%;
margin: 0;
}
</style>
</head>
<body>
<arcgis-scene>
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-expand slot="top-right" expanded>
<arcgis-legend></arcgis-legend>
</arcgis-expand>
</arcgis-scene>
<script type="module">
const Map = await $arcgis.import("@arcgis/core/Map.js");
const viewElement = document.querySelector("arcgis-scene");
const map = new Map({
ground: "world-elevation",
basemap: "topo-vector",
});
viewElement.map = map;
viewElement.camera = {
position: [-118.80714, 33.961442, 1574.65501],
heading: 0.51,
tilt: 78.99,
};
4 collapsed lines
</script>
</body>
</html>

Display terrain with exaggeration

To emphasize the terrain, you might sometimes find it useful to display the terrain with exaggerated elevation values. In this example, you will show the highest mountain ranges and the lowest ocean regions on the globe. Because the Earth’s radius is so big, mountain range elevation isn’t visually noticeable. Here you will exaggerate 70 times these elevation values using Esri’s TopoBathy elevation service as the data source.

Turn exaggeration on and off using the button.
69 collapsed lines
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Terrain rendering - exaggerated elevation</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.2/"></script>
<style>
html,
body {
height: 100%;
margin: 0;
}
body {
background: radial-gradient(#12bff2, #0269a1);
}
arcgis-scene {
filter: saturate(1.2) drop-shadow(0 0 20px white);
}
.buttons {
text-align: center;
}
.esri-button {
display: inline;
max-width: 200px;
}
</style>
</head>
<body>
<arcgis-scene>
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-expand slot="bottom-right" expanded>
<arcgis-legend></arcgis-legend>
</arcgis-expand>
<div class="buttons" slot="bottom-left">
<button id="exaggerate" class="esri-button">Disable exaggeration</button>
</div>
</arcgis-scene>
<script type="module">
const [Map, ElevationLayer, BaseElevationLayer, Basemap, TileLayer] = await $arcgis.import([
"@arcgis/core/Map.js",
"@arcgis/core/layers/ElevationLayer.js",
"@arcgis/core/layers/BaseElevationLayer.js",
"@arcgis/core/Basemap.js",
"@arcgis/core/layers/TileLayer.js",
]);
const viewElement = document.querySelector("arcgis-scene");
const basemap = new Basemap({
baseLayers: [
new TileLayer({
url: "https://tiles.arcgis.com/tiles/nGt4QxSblgDfeJn9/arcgis/rest/services/terrain_with_heavy_bathymetry/MapServer",
copyright:
'Bathymetry, topography and satellite imagery from <a href="https://visibleearth.nasa.gov/view_cat.php?categoryID=1484" target="_blank">NASA Visible Earth</a> | <a href="http://www.aag.org/global_ecosystems" target="_blank">World Ecological Land Units, AAG</a> | Oceans, glaciers and water bodies from <a href="https://www.naturalearthdata.com/" target="_blank">Natural Earth</a>',
}),
],
});
const ExaggeratedElevationLayer = BaseElevationLayer.createSubclass({
properties: {
exaggeration: null,
},
// The load() method is called when the layer is added to the map
// prior to it being rendered in the view.
load: function () {
this._elevation = new ElevationLayer({
url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/TopoBathy3D/ImageServer",
});
// wait for the elevation layer to load before resolving load()
this.addResolvingPromise(this._elevation.load());
return Promise.resolve(this);
},
// Fetches the tile(s) visible in the view
fetchTile: function (level, row, col, options) {
// calls fetchTile() on the elevationlayer for the tiles
// visible in the view
return this._elevation.fetchTile(level, row, col, options).then(
function (data) {
var exaggeration = this.exaggeration;
// `data` is an object that contains the
// the width and the height of the tile in pixels,
// and the values of each pixel
for (var i = 0; i < data.values.length; i++) {
// Multiply the given pixel value
// by the exaggeration value
data.values[i] = data.values[i] * exaggeration;
}
return data;
}.bind(this),
);
},
});
const elevationLayer = new ExaggeratedElevationLayer({ exaggeration: 70 });
const map = new Map({
basemap: basemap,
ground: {
layers: [elevationLayer],
},
});
57 collapsed lines
viewElement.map = map;
viewElement.alphaCompositingEnabled = true;
viewElement.camera = {
position: [-55.039758, 14.948264, 19921223.30821],
heading: 2.03,
tilt: 0.13,
};
viewElement.environment = {
background: {
type: "color",
color: [255, 252, 244, 0],
},
starsEnabled: false,
atmosphereEnabled: false,
lighting: {
directShadowsEnabled: false,
date: "Sun Jun 23 2019 19:19:18 GMT+0200 (Central European Summer Time)",
},
};
viewElement.constraints = {
altitude: {
min: 10000000,
max: 25000000,
},
};
viewElement.popup = {
dockEnabled: true,
dockOptions: {
position: "top-right",
breakpoint: false,
buttonEnabled: false,
},
visibleElements: {
collapseButton: false,
},
};
let exaggerated = true;
document.getElementById("exaggerate").addEventListener("click", function () {
if (exaggerated) {
map.ground = "world-elevation";
this.innerHTML = "Enable exaggeration";
exaggerated = false;
} else {
map.ground = {
layers: [elevationLayer],
};
this.innerHTML = "Disable exaggeration";
exaggerated = true;
}
});
</script>
</body>
</html>