Get started
Examples

Map controls

Map controls

A map with every built-in control. The Panels tab of the preview opens the terrain picker, the points-of-interest filter and the unit preferences.

src/TrailMap.tsx
/// <reference types="vite/client" />
import { Mountaya } from "@mountaya/client/browser";
import { defaultUnits } from "@mountaya/elements/profile";
import { MapControls, MapView } from "@mountaya/elements-react";
import "@mountaya/elements-react/styles.css";
import { useState } from "react";

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

export const TrailMap = () => {
  const [preferences, setPreferences] = useState(defaultUnits);

  return (
    <div style={{ height: 480 }}>
      <MapView center={[6.8712, 45.9231]} client={client} terrain="topo" zoom={12}>
        <MapControls
          compass
          geolocate
          layers
          pois
          preferences
          preferencesPanel={{ onPreferencesChange: setPreferences, preferences }}
          zoom
        />
      </MapView>
    </div>
  );
};

Store preferences wherever your app keeps a reader's settings, and hand the same value to the profile and the tables.

Next steps

Last updated