Show an elevation profile
ItineraryProfile draws an itinerary's elevation from one request. It needs no map.
Make one ItineraryResourceCache per client, and name the itinerary:
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.
Everything past the curve and its services is opt-in, through parts. The parts you list replace the services:
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(),
);
}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:
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,
},
);
}Hand the profile your map. A scrub over the curve pins a marker on the map and lights the leg under it:
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,
},
),
),
],
);
}