Query Elevation (lines)

Explore in the sandboxView live

This sample demonstrates how to combine an Elevation Query on the ground with a Route Task. It queries the elevation along a route specified by the user and uses this data to extract statistics about the route, including total ascent and decent along the path.

How it works

This sample requires a proxy to handle communications with the routing service. This example uses an ArcGIS Online hosted proxy. You can either remove it and log in once prompted, or you can use another authentication method.

For details about the routing functionality please see the Simple Routing - RouteTask example, which serves as a basis for this example.We use the output from the RouteTask to do an elevation query on the ground surface of our map:

const route = data.routeResults[0].route;
const geometry = route.geometry;

const elevationPromise = map.ground.queryElevation(
  new Polyline({
    paths: geometry.paths,
    spatialReference: geometry.spatialReference

This call returns a promise which resolves to a ElevationQueryResult object containing a new geometry with updated elevation data.We extract the first path from it and iterate over its stops, each of them represented as a [x,y,z] coordinate triplet.

elevationPromise.then((result) => {
  const path = result.geometry.paths[0];
  let ascent = 0;
  let descent = 0;

  for (let i = 1; i < path.length; i++) {
    const d = path[i][2] - path[i - 1][2];
    if (d > 0) {
      ascent += d;
    } else {
      descent -= d;

  // update the text fields, etc ...

For our use case we are interested in the difference in elevation (stored in the z coordinate) between consecutive stops in the path. We sum up the respective deltas, and display them as total ascent and descent to the user.