Get started
Swift SDK

Show itinerary data

Show an elevation profile

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:

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.

Turn on the axis, sections and tooltip

Everything past the curve is a part you ask for:

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.

Show services and cut-offs

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

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.

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:

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)
    }
  }
}

Next steps

Last updated