Query Elevation (lines)

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

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 statistiscs about the route, including total ascent and decent along the path.

How it works

This sample requires a proxy page to handle communications with the routing service. You can either remove it and log in once prompted, or you can set up your own proxy.

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:

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

var 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(function(result) {
  var path = result.geometry.paths[0];
  var ascent = 0;
  var descent = 0;

  for (var i = 1; i < path.length; i++) {
    var 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.

Sample search results

TitleSample

There were no match results from your search criteria.