Get started
Examples

Segment table

Segment table

ItinerarySegmentTable prints one row per leg of an itinerary: distance, climb, time and the kind of path.

src/Segments.tsx
/// <reference types="vite/client" />
import { Mountaya } from "@mountaya/client/browser";
import { ItinerarySegmentTable } 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 Segments = () => (
  <MountayaElementsProvider client={client}>
    <ItinerarySegmentTable itineraryId={ITINERARY_ID} />
  </MountayaElementsProvider>
);

With a map

Put the map on the provider. Hover a row to light that leg, or hover the route to highlight its row.

src/SegmentsWithMap.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 { ItinerarySegmentTable } 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 SegmentsWithMap = () => {
  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>
      <ItinerarySegmentTable itineraryId={ITINERARY_ID} />
    </MountayaElementsProvider>
  );
};

Stack the map above the table: below 44 rem of width, the table turns into a column of cards.

Next steps

Last updated