Get started
Examples

Elevation profile

Elevation profile

ItineraryProfile draws an itinerary's elevation curve from its id, with a stat row and a tooltip. It needs no map.

src/Profile.tsx
/// <reference types="vite/client" />
import { Mountaya } from "@mountaya/client/browser";
import { ItineraryProfile } from "@mountaya/elements-react/elements";
import { MountayaElementsProvider } from "@mountaya/elements-react/headless";
import "@mountaya/elements-react/styles.css";

const client = new Mountaya({
  credential: { publishableKey: import.meta.env.VITE_MOUNTAYA_PUBLISHABLE_KEY },
});

// One of your published itineraries.
const ITINERARY_ID = "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21";

export const Profile = () => (
  <MountayaElementsProvider client={client}>
    <ItineraryProfile itineraryId={ITINERARY_ID} stats={["distance", "ascent"]} tooltip />
  </MountayaElementsProvider>
);

With a map

Put the map on the provider and the two follow each other: scrub the chart and a marker travels the route.

src/ProfileWithMap.tsx
/// <reference types="vite/client" />
import { Mountaya } from "@mountaya/client/browser";
import type { MountayaMap } from "@mountaya/elements";
import { MapView, MountayaElementsProvider } from "@mountaya/elements-react";
import { ItineraryProfile } from "@mountaya/elements-react/elements";
import "@mountaya/elements-react/styles.css";
import { useState } from "react";

const client = new Mountaya({
  credential: { publishableKey: import.meta.env.VITE_MOUNTAYA_PUBLISHABLE_KEY },
});

const ITINERARY_ID = "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21";

export const ProfileWithMap = () => {
  const [map, setMap] = useState<MountayaMap | null>(null);

  return (
    <MountayaElementsProvider client={client} map={map}>
      <div style={{ height: 320 }}>
        <MapView
          client={client}
          onReady={(ready) => {
            setMap(ready);
            void ready.setItinerary(ITINERARY_ID, { fit: true });
          }}
          terrain="topo"
        />
      </div>
      <ItineraryProfile axis itineraryId={ITINERARY_ID} sections tooltip />
    </MountayaElementsProvider>
  );
};

Next steps

Last updated