Skip to content

Build a route elevation profile with Node

Sample your route's waypoints with the Elevation API and draw a distance-based SVG profile that preserves unknown heights.

Working example

ParseAPI
Node

Set up ParseAPI

Set PARSEAPI_KEY in your server environment. Use Node.js 22 or later.

Terminal
export PARSEAPI_KEY='YOUR_SECRET_API_KEY'
Get an API key ↗

Show the ground beneath a route

Add an elevation profile to a route your application already has. The Node app lets someone choose a set of sample waypoints, then draws their ground elevation with a distance axis and the lowest and highest known samples.

The server keeps the secret key and calls the Elevation API. The browser receives the profile it needs to draw the chart.

1. Supply the waypoints

Keep each vertex as a [latitude, longitude] pair. The app's ROUTES object contains two short waypoint sketches near Denver:

JavaScript
export const ROUTES = {
  denver: { name: 'Denver sample', path: [[39.7392, -104.9903], [39.7508, -104.9766], [39.77, -104.9]] },
  foothills: { name: 'Foothills sample', path: [[39.7328, -105.2385], [39.739, -105.224], [39.747, -105.214]] }
};

Use your application's route data in this object.

These coordinates describe the path to sample. The API connects each adjacent pair by its shortest great-circle arc. It does not find a road or trail between them. Include the turns your actual route needs.

2. Sample the path with one request

Choose 64 evenly spaced samples for this chart:

JavaScript
const profile = await parse.elevation.path(route.path, 64, { signal });

profile.points contains the ordered samples, including both endpoints. Each point has latitude, longitude, elevation in meters, and resolution in meters when known. elevation: null means the height is unavailable. Zero and negative heights are valid.

The API accepts 2-512 vertices and 2-512 samples. Locations in a batch must be within 25 km of one another, and the request must fit the terrain coverage limit described in the Elevation reference. Keep a longer route in appropriately bounded sections rather than presenting a failed request as an empty profile.

3. Put each sample on the chart

Because the API spaces samples uniformly along the supplied path, each sample's index gives its horizontal position. Its elevation gives the vertical position. The app calculates the path's great-circle distance from the original waypoints for the axis.

Start a new SVG segment after every unknown elevation:

JavaScript
for (const [index, point] of points.entries()) {
  if (point.elevation === null) { connected = false; continue; }
  const x = 20 + index / (points.length - 1) * 760;
  const y = 220 - (point.elevation - low) / (high - low) * 200;
  path += `${connected ? 'L' : 'M'}${x.toFixed(2)},${y.toFixed(2)} `;
  dots.push({ x, y });
  connected = true;
}

M starts a segment and L continues it. A null sample breaks the line instead of being plotted at zero or joined across. Small circles keep isolated known samples visible. The chart scales to the known minimum and maximum, including a flat profile.

4. Render the selected route

The browser applies the generated path to its SVG:

JavaScript
document.querySelector('#line').setAttribute('d', result.chart.path);

The app also shows the route distance, known elevation range, and number of available samples. An all-null result shows unknown heights and an unavailable message. A failed lookup shows a retry state.

Changing the selected route clears the old profile and cancels its request. Late answers cannot replace the new choice. The server allows only the route IDs your app supplies, with an eight-second timeout and no automatic retries, so a chart request stays bounded.

Heights describe ground terrain. They do not measure bridge decks or buildings, and this sampling is not a precise ascent calculation or a navigation plan.

Complete example

Use the complete implementation as a reference when adding this feature to your app. It includes the validation and failure handling around the calls above.

View and copy the complete source
Try the complete example on your computer

After completing the setup above, save the source in your application folder and start the app:

Terminal
node route-elevation-profile.node.mjs

Open 127.0.0.1:8000 to use the form. The server keeps your secret key out of the page.

For every field and parameter, see Elevation API reference.