Get started
Kotlin SDK

Show itinerary data

Show an elevation profile

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

Draw the curve

Make one cache per client, and name the itinerary:

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.mountaya.client.Mountaya
import com.mountaya.elements.ItineraryProfile
import com.mountaya.geo.ItineraryResourceCache
import com.mountaya.geo.StatStripStat

@Composable
fun TourProfile(mountaya: Mountaya) {
    val scope = rememberCoroutineScope()
    // Every element reading through one cache shares its reads.
    val itineraries =
        remember {
            ItineraryResourceCache(scope) { id, surface ->
                mountaya.studio.itineraries.getItinerary(id) { if (surface != null) this.surface = surface }.data
            }
        }
    ItineraryProfile(
        itineraryId = "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
        cache = itineraries,
        modifier = Modifier.fillMaxWidth().height(220.dp),
        stats = listOf(StatStripStat.Distance, StatStripStat.Ascent, StatStripStat.Descent),
    )
}

The cache reads through your client, so the profile never calls the network itself.

Turn on the axis, sections and tooltip

Everything past the curve and its services is opt-in, through parts:

import androidx.compose.runtime.Composable
import com.mountaya.elements.ItineraryProfile
import com.mountaya.elements.ProfileColoring
import com.mountaya.elements.ProfilePart
import com.mountaya.geo.ItineraryResourceCache
import com.mountaya.geo.slopeBuckets

@Composable
fun DetailedProfile(itineraries: ItineraryResourceCache) {
    ItineraryProfile(
        itineraryId = "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
        cache = itineraries,
        parts =
            setOf(
                ProfilePart.Amenities,
                ProfilePart.ElevationAxis,
                ProfilePart.DistanceAxis,
                ProfilePart.Navigator,
                ProfilePart.Sections,
                ProfilePart.Tooltip,
            ),
        // Colour the curve by gradient.
        coloring = ProfileColoring.Slope(slopeBuckets),
    )
}

Show services and cut-offs

Places that declare services show them as badges above their pins. Hand formatCutoffAt to write each place's cut-off time:

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.mountaya.elements.ItineraryProfile
import com.mountaya.geo.ItineraryResourceCache
import com.mountaya.geo.TimeLength
import com.mountaya.geo.formatDateTime
import kotlin.time.Instant

@Composable
fun ProfileWithCutoffs(itineraries: ItineraryResourceCache) {
    // Each cut-off in French, on the Alps' clock.
    val writeCutoff = remember { cutoffWriter("fr-FR", "Europe/Paris") }
    ItineraryProfile(
        itineraryId = "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
        cache = itineraries,
        formatCutoffAt = writeCutoff,
    )
}

// Null where the platform knows no zone of that name, so no cut-off is written.
fun cutoffWriter(language: String, zone: String): ((Instant) -> String)? {
    formatDateTime(Instant.fromEpochSeconds(0), language, zone) ?: return null
    return { cutoff ->
        formatDateTime(cutoff, language, zone, timeLength = TimeLength.Short) ?: error("$zone was known when the writer was made.")
    }
}

Link the curve to a map

Hand the profile the map's engine. Scrubbing the curve pins a marker on the map and lights the leg under it:

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.mountaya.elements.ItineraryProfile
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapView
import com.mountaya.elements.ProfilePart
import com.mountaya.geo.ItineraryResourceCache

@Composable
fun MapAndProfile(map: MapEngine, itineraries: ItineraryResourceCache) {
    Column {
        MapView(map, Modifier.fillMaxWidth().height(320.dp))
        ItineraryProfile(
            itineraryId = "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
            cache = itineraries,
            modifier = Modifier.fillMaxWidth().height(220.dp),
            map = map,
            parts = setOf(ProfilePart.Amenities, ProfilePart.ElevationAxis, ProfilePart.Sections, ProfilePart.Tooltip),
        )
    }
}

Next steps

Last updated