# Show an elevation profile

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

Draw an itinerary's elevation in Flutter with ItineraryProfile, turn on its axes, sections and tooltip, show services and cut-offs, and link it to a map.

`ItineraryProfile` draws an itinerary's elevation from one request. It needs no map.

## Draw the curve

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

```dart
import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';
import 'package:mountaya_geo/mountaya_geo.dart';

class TourProfile extends StatefulWidget {
  const TourProfile({super.key, required this.mountaya});

  final Mountaya mountaya;

  @override
  State<TourProfile> createState() => _TourProfileState();
}

class _TourProfileState extends State<TourProfile> {
  // Every element over an itinerary reads it once through this cache.
  late final ItineraryResourceCache itineraries = ItineraryResourceCache(
    (id, surface) async => (await widget.mountaya.studio.itineraries.getItinerary(
      itinerary_id: id,
      query: rest_schema.GetItineraryQuery(surface: surface),
    )).data,
  );

  @override
  Widget build(BuildContext context) => SizedBox(
    height: 220,
    child: ItineraryProfile(
      cache: itineraries,
      itineraryId: '0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21',
      stats: const [
        StatStripStat.distance,
        StatStripStat.ascent,
        StatStripStat.descent,
      ],
    ),
  );
}
```

The stat strip over the curve states the length, the climb and the descent.

- `ItineraryResourceCache(Future<ItineraryWithDetails> Function(String id, ReadSurface? surface))` keeps the 16 answers read last (`ItineraryResourceCache.capacity`), joins a question already asked, drops a failure at once so the next question asks again, and holds the engines watching it weakly. `invalidate([id])` makes every element over the itinerary read it again, after your app saved it. The elements never call the network themselves.
- An element reads its itinerary one of two ways, each a constructor of its own: `ItineraryProfile(cache:, itineraryId:)` reads through your cache with an engine of its own, which it closes as it goes; `ItineraryProfile.engine(engine:)` renders an `ItineraryResourceEngine` you made and close yourself. An element handed neither or both does not compile.
- The geometry may be a `LineString`, a `MultiLineString`, a `GeometryCollection`, a `Feature` or a `FeatureCollection`; every line shares one distance axis. Elevation is the third coordinate of a position; a 2D itinerary states its length beside an empty chart.
- `stats:` (default `defaultStatStripStats`: `distance`, `ascent`, `descent`, `elevation`) picks the strip's cells among `StatStripStat.distance`, `duration`, `ascent`, `descent`, `elevation`, `grade`, `difficulty`. `units:` states figures in the reader's `UnitPreferences`.
- The chart is painted in layers: the curve is kept for its series and repainted only as it changes, and the cursor repaints over it on the scrub alone.
- `onError` is handed a failed read while the element draws its empty state.

## Turn on the axis, sections and tooltip

Everything past the curve and its services is opt-in, through `parts`. The parts you list replace the services:

```dart
import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';
import 'package:mountaya_geo/mountaya_geo.dart';

class TourProfile extends StatefulWidget {
  const TourProfile({super.key, required this.mountaya});

  final Mountaya mountaya;

  @override
  State<TourProfile> createState() => _TourProfileState();
}

class _TourProfileState extends State<TourProfile> {
  // Every element over an itinerary reads it once through this cache.
  late final ItineraryResourceCache itineraries = ItineraryResourceCache(
    (id, surface) async => (await widget.mountaya.studio.itineraries.getItinerary(
      itinerary_id: id,
      query: rest_schema.GetItineraryQuery(surface: surface),
    )).data,
  );

  @override
  Widget build(BuildContext context) => ItineraryProfile(
    cache: itineraries,
    itineraryId: '0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21',
    parts: const {
      ProfilePart.elevationAxis,
      ProfilePart.distanceAxis,
      ProfilePart.sections,
      ProfilePart.tooltip,
      ProfilePart.navigator,
    },
    // Colours the curve by its gradient.
    coloring: const ProfileColoring.slope(),
  );
}
```

- `ProfilePart`: `amenities` (the services above each place, the one part of `ProfilePart.standard`), `elevationAxis`, `distanceAxis` (place names thinned until each label clears its neighbours), `sections` (a chip per leg), `tooltip` (the card at the cursor), `navigator` (a window over the range shown, its controlled form `window:` and `onWindowChanged`).
- `coloring:` is `ProfileColoring.plain()` (the default), `.slope([buckets])` by gradient, `.classes(classes)` for a taxonomy of your own, or `.stretches(stretches)` for coloured spans you pass; `bands:` adds a band strip of `ProfileClass` values.
- `anchor:` (`ProfileAnchor.route` by default) picks the elevation domain. `highlighted:` names the leg to tint.
- `onSegmentTap` is handed a leg's id (`group:<id>` for a group shown as one leg) and writes nothing to the map; a leg's chip is pressed only where you hand it. `enabled: false` presses nothing.
- The distance scale and the chips grow with the reader's text scale.

## Show services and cut-offs

Where waypoints declare services, the profile stacks them above each pin. Pass `formatCutoffAt` to write each place's cut-off time, in the device's time zone:

```dart
import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';
import 'package:mountaya_geo/mountaya_geo.dart';

class TourProfile extends StatefulWidget {
  const TourProfile({super.key, required this.mountaya});

  final Mountaya mountaya;

  @override
  State<TourProfile> createState() => _TourProfileState();
}

class _TourProfileState extends State<TourProfile> {
  // Every element over an itinerary reads it once through this cache.
  late final ItineraryResourceCache itineraries = ItineraryResourceCache(
    (id, surface) async => (await widget.mountaya.studio.itineraries.getItinerary(
      itinerary_id: id,
      query: rest_schema.GetItineraryQuery(surface: surface),
    )).data,
  );

  // The device's IANA zone, such as Europe/Paris, or null where it names none.
  String? _zone;

  @override
  void initState() {
    super.initState();
    unawaited(
      deviceTimeZone().then((zone) {
        if (mounted) setState(() => _zone = zone);
      }),
    );
  }

  @override
  Widget build(BuildContext context) => ItineraryProfile(
    cache: itineraries,
    itineraryId: '0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21',
    formatCutoffAt: switch (_zone) {
      final zone? => (cutoff) =>
          formatDateTime(cutoff, 'fr', zone, timeLength: .short) ?? '',
      null => null,
    },
  );
}
```

- The data is the switch for badges: a profile whose places declare no service draws no badge layer.
- A place that publishes a cut-off gets a dashed vertical and a time above the chart, only once you pass `formatCutoffAt`: a Dart `DateTime` knows UTC and an offset, never a zone's name, so the device's zone comes from `deviceTimeZone()` over the elements package's own channel. Read it again as the app comes back to the foreground.
- Where `deviceTimeZone()` answers `null`, or names a zone `formatDateTime` holds none of (it answers `null` for the name whatever the moment), hand no writer: no cut-off is written, never one in UTC. A test states the zone with `withDeviceTimeZone(zone, body)`.
- `formatDateTime(instant, locale, timeZone, {dateLength, timeLength})` writes in the IANA zone named, from `package:timezone`'s full data set, through 2037. Its data (about 431 KB) is compiled only into an app that calls it; call `prepareFormatDateTime()` once the first frame is drawn so it decodes on another isolate (the elements do).
- `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:

```dart
import 'package:flutter/widgets.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;
import 'package:mountaya_elements_flutter/mountaya_elements_flutter.dart';
import 'package:mountaya_geo/mountaya_geo.dart';

class TourProfile extends StatefulWidget {
  const TourProfile({super.key, required this.mountaya});

  final Mountaya mountaya;

  @override
  State<TourProfile> createState() => _TourProfileState();
}

class _TourProfileState extends State<TourProfile> {
  late final MapEngine map = MapEngine(widget.mountaya);
  // Every element over an itinerary reads it once through this cache.
  late final ItineraryResourceCache itineraries = ItineraryResourceCache(
    (id, surface) async => (await widget.mountaya.studio.itineraries.getItinerary(
      itinerary_id: id,
      query: rest_schema.GetItineraryQuery(surface: surface),
    )).data,
  );

  @override
  void dispose() {
    map.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => Column(
    children: [
      Expanded(child: MapView(engine: map)),
      SizedBox(
        height: 220,
        child: ItineraryProfile(
          cache: itineraries,
          itineraryId: '0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21',
          map: map,
          parts: const {
            ProfilePart.elevationAxis,
            ProfilePart.sections,
            ProfilePart.tooltip,
          },
        ),
      ),
    ],
  );
}
```

- With `map:`, a scrub pins the cursor marker at the sample (`markerId`, default `profileCursorMarkerId`) and lights the leg under it, the later leg at a meter two share. It moves the marker at most once a frame and never sends the itinerary's geometry again.
- `onHover` hands you the `ElevationPoint` under the cursor, and `null` as it is let go, in place of the map's marker and lit leg, for an app that shows the cursor its own way.
- A profile and the two 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.
- Draw the itinerary itself with `map.setItinerary(id)`; a profile and a table naming one itinerary share the cache, so they cost one request.

## Next steps

- [List segments and waypoints](https://docs.mountaya.com/en/sdks/dart/tables.md): The same itinerary read as rows.
- [Geo without a map](https://docs.mountaya.com/en/sdks/dart/geo.md): The figures behind the chart, in pure Dart.
