Get started
Get started

Install and set up

Install and set up

Install the packages

This line gives you a map in React:

npm install @mountaya/elements-react @mountaya/elements @mountaya/client maplibre-gl@6.18.0 react

Add or drop packages for what you build:

You are buildingPackages
A server, a worker, or a script@mountaya/client
A React app with no map@mountaya/client-react, @mountaya/client, @tanstack/react-query
A map without React@mountaya/elements, @mountaya/client, maplibre-gl
A map in Reactthe line above
An itinerary editor in React@mountaya/studio-react, on top of the line above

Import the stylesheet

Import one stylesheet once, at your app's entry point:

import "@mountaya/elements-react/styles.css";

It holds MapLibre's rules too, so there is nothing else to import. With the studio, import @mountaya/studio-react/styles.css instead.

Mount the provider

Put controls inside MapView and they find the map with nothing else to wire:

import { Mountaya } from "@mountaya/client/browser";
import { MapControls, MapView } from "@mountaya/elements-react";

const client = new Mountaya({ credential: { publishableKey: "pk_your_publishable_key" } });

export const Map = () => (
  <div style={{ height: 480 }}>
    <MapView center={[6.8712, 45.9231]} client={client} zoom={12}>
      <MapControls compass geolocate layers preferences zoom />
    </MapView>
  </div>
);

For anything placed outside the map, a sidebar or a toolbar, mount MountayaElementsProvider yourself and hand it the map onReady returns:

import { useState } from "react";
import { Mountaya } from "@mountaya/client/browser";
import type { MountayaMap } from "@mountaya/elements";
import { MapControls, MapView, MountayaElementsProvider } from "@mountaya/elements-react";

const client = new Mountaya({ credential: { publishableKey: "pk_your_publishable_key" } });

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

  return (
    <MountayaElementsProvider client={client} map={map}>
      <div style={{ height: 480, position: "relative" }}>
        <MapView center={[6.8712, 45.9231]} client={client} onReady={setMap} zoom={12} />
        <MapControls compass geolocate layers preferences zoom />
      </div>
    </MountayaElementsProvider>
  );
};

MapView fills its container, so give the container a height. Import the client from @mountaya/client/browser in any code that reaches a browser.

Import from the right entry point

Import fromFor
@mountaya/clientThe client, on a server
@mountaya/client/browserThe client, in a browser or a worker
@mountaya/client-reactReact provider and hooks
@mountaya/client-react/queryQuery options for a Server Component
@mountaya/elementsThe map without React
@mountaya/elements-reactThe React map and its controls
@mountaya/elements-react/elementsThe profile and tables, no map
@mountaya/elements-react/headlessThe provider, no renderer
@mountaya/studio-reactThe Embedded Studio

Reach for the narrowest entry that serves you: only the map entries bring MapLibre.

Next steps

Last updated