# Show an elevation profile

> Canonical URL: https://docs.mountaya.com/en/sdks/swift/elevation-profile/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Draw an itinerary's elevation profile in SwiftUI with ItineraryProfile, with or without a map.

`ItineraryProfile` draws an itinerary's elevation from one request. It needs no map, and links to one when you hand it yours.

## Draw the curve

Make one `ItineraryResourceCache` per client, and name the itinerary:

```swift
import MountayaClient
import MountayaElements
import MountayaGeo
import SwiftUI

struct TourProfile: View {
  let itineraries: ItineraryResourceCache

  init(mountaya: Mountaya) {
    itineraries = ItineraryResourceCache { id, surface in
      try await mountaya.studio.itineraries.getItinerary(
        itinerary_id: id, query: .init { $0.surface = surface }
      ).data
    }
  }

  var body: some View {
    ItineraryProfile(
      itineraryId: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21", cache: itineraries,
      stats: [.distance, .ascent, .descent]
    )
    .frame(height: 220)
  }
}
```

The cache reads through your client, so every element over one itinerary costs one request.

- `ItineraryResourceCache(source:)` takes an `ItinerarySource`, `@Sendable (String, RestSchema.ReadSurface?) async throws -> RestSchema.ItineraryWithDetails`: the elements never call the network themselves. Make it once per client and hand it to every element; `invalidate(itineraryId:)` makes every element over that itinerary read it again, after your app saved it.
- `ItineraryProfile` has two initializers: `(itineraryId:cache:surface:…)`, and `(engine:…)` for an `ItineraryResourceEngine` you hold yourself, which the element reads and never closes.
- The profile draws the stat strip over the curve (`stats:`, `defaultStatStripStats`, from `StatStripStat`: `.distance`, `.ascent`, `.descent`, `.elevation`, `.duration`, `.grade`, `.difficulty`) and the places pinned on the curve.
- Elevation is the third coordinate of each position; a vertex without one advances the distance but draws no point.
- `onError` hears a read that failed while the element draws its empty state. `units:` sets the units for this element; words and colours come from SwiftUI's environment (`\.mountayaScope`, `\.mountayaTokens`).
- Every figure is a Geo rule (`buildElevationSeries`, `profileTotals`, `formatElevation`), so a screen of your own states the same numbers ([geo](https://docs.mountaya.com/en/sdks/swift/geo.md#elevation)).

## Turn on the axis, sections and tooltip

Everything past the curve is a part you ask for:

```swift
import MountayaElements
import MountayaGeo
import SwiftUI

struct DetailedProfile: View {
  let itineraries: ItineraryResourceCache

  var body: some View {
    ItineraryProfile(
      itineraryId: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21", cache: itineraries,
      coloring: .slope(),
      parts: [.elevationAxis, .distanceAxis, .navigator, .sections, .tooltip])
  }
}
```

`coloring` colours the curve by gradient, by your own classes, or by spans you pass.

- `ProfileParts` is an option set: `.amenities` (the default, `.standard`), `.tooltip` (the card at the cursor), `.sections` (a chip per leg), `.navigator` (a window over the range shown, bound with `window:`), `.elevationAxis`, `.distanceAxis` (place names thinned until each clears its neighbours).
- `ProfileColoring`: `.plain` (default), `.slope()` (by gradient, `slopeBuckets` unless you pass your own), `.classes([ProfileClass])` (a taxonomy of yours), `.stretches([CurveColor])` (your own spans, distances in meters).
- `bands:` draws a band strip of `ProfileClass` ranges. `anchor:` (`ProfileAnchor`: `.route`, the default, or `.window`) is what the elevation scale is measured from: the whole route, or the window shown.
- A profile's distance axis and its chips grow with Dynamic Type.

## Show services and cut-offs

Places that declare services show them above their pin. Pass `formatCutoffAt` to write each place's cut-off time:

```swift
import Foundation
import MountayaElements
import MountayaGeo
import SwiftUI

struct CutoffProfile: View {
  let itineraries: ItineraryResourceCache

  var body: some View {
    ItineraryProfile(
      itineraryId: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21", cache: itineraries,
      formatCutoffAt: { cutoff in
        formatDateTime(cutoff, locale: "fr-FR", timeZone: "Europe/Paris", timeLength: .short) ?? ""
      })
  }
}
```

A cut-off is written only by your function, because its time zone is your app's.

- The places' services are the `.amenities` part, on by default. A profile whose places declare no service draws no badge. Swift has no cap on a deep stack of badges (the TypeScript SDK's `amenities={{ max: 3 }}`): the stack shows every service.
- A place that publishes a cut-off gets a dashed line and a time above the chart only once you pass `formatCutoffAt`. The sample app writes each with `formatDateTime(cutoff, locale: language, timeZone: TimeZone.current.identifier, dateLength: .medium, timeLength: .short)`, which answers nil for a zone the locale services do not know: hand no `formatCutoffAt` there rather than write a time in another zone.
- `onWaypointTap` hears a tap on a place; `onSegmentTap` turns the leg chips into buttons, each press handing the leg's id (or a collapsed group's `group:` id).
- `ItineraryWaypointTable` and `WaypointCard` take the same `formatCutoffAt`.

## Link the curve to a map

Hand the profile your map. A scrub over the curve pins a marker on the map and lights the leg under it:

```swift
import MountayaElements
import MountayaGeo
import SwiftUI

struct ProfileUnderMap: View {
  let map: MapEngine
  let itineraries: ItineraryResourceCache

  var body: some View {
    VStack(spacing: 0) {
      MapView(map)
      ItineraryProfile(
        itineraryId: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21", cache: itineraries, map: map,
        parts: [.elevationAxis, .distanceAxis, .sections, .tooltip]
      )
      .frame(height: 220)
    }
  }
}
```

- Linked both ways: a scrub pins the cursor marker (`profileCursorMarkerId`) at the sample and lights the leg under it, the later leg at a meter two legs share; a leg the map's cursor is over is lit on the chart. `onHover` takes the map over, handed the sample; `highlighted` names the leg to light and stops listening.
- A profile and the tables over one map never move or take down each other's marker, each pinning under an id of its own, and each takes down what it wrote as it leaves. `markerColor:` and `emphasisColor:` restyle them.
- `.disabled(true)` draws the element and drives nothing.

## Next steps

- [List segments and waypoints](https://docs.mountaya.com/en/sdks/swift/tables.md): The same itinerary read as rows.
- [Show a map](https://docs.mountaya.com/en/sdks/swift/map.md): Draw the itinerary the profile reads.
