Get started
Show a map

Use the map without React

Use the map without React

MountayaMap is the map the React elements are drawn on, reached directly. The quickstart mounts one in Vue, Svelte or plain TypeScript. This page covers what you do with it next.

Draw your content

await map.whenReady();
await map.setItinerary(itineraryId, { fit: true });
map.setOverlay("aspectslope");
map.addEnrichment("hillshade");

set replaces one value and add appends. Each method places what it draws at the right height in the layer order.

AreaMethods
ContentsetItinerary, setCollection, setPreview, setHighlight
Base mapsetTerrain, setStyle, setOverlay, setSpecification
AnalysisaddDirections, addSuggestions, addIsochrones, addMatrix, addPlaces, setPointsOfInterest
CameraflyTo, jumpTo, fitBounds, zoomIn, zoomOut, resetNorth, easeIntoZoomRange
ReadingfeaturesAt, poisAt, zonesAt, itinerariesAt, elevationAt, project, unproject
Your own layersaddLayer, addMarker, setLayerVisibility, setKeyVisibility
LifecyclewhenReady, on, destroy

Draw a specification you already hold

setItinerary fetches. If your cache already holds the specification, draw it with setSpecification, with no second request:

const { data: specification } = await client.tiles.getItinerarySpecification({
  itinerary_id: itineraryId,
});
if (specification === undefined) {
  return; // no body, nothing to draw
}

await map.setSpecification("preview", specification);
map.easeIntoZoomRange(specification);

Add your own layers

Add a layer at a Mountaya rank, so it sorts correctly against the map's own:

import { LayerRank } from "@mountaya/elements/layers";

map.addLayer({ id: "corridor", source: "my-source", type: "line" }, LayerRank.STREETVIEW_CORRIDOR);
map.removeLayer("corridor");

To swap the base style and keep what you drew, use setStyle:

await map.setStyle("https://example.com/style.json", {
  transformStyle: (previous, next) => ({ ...next, sources: { ...next.sources, dem } }),
});

Listen for events

on returns its own unsubscribe, so a framework's unmount hook calls what its mount hook returned:

const off = map.on("featureclick", ({ features }) => showFeatures(features));

map.on("accessrequired", ({ status, url }) => {
  console.warn(`The API refused ${url} with a ${status}.`);
});
map.on("error", ({ error }) => console.error(error));

Authenticate a MapLibre map of your own

If you construct MapLibre yourself, attach the credential with createTransformRequest. Without it, tiles answer 401.

import * as maplibregl from "maplibre-gl";
import { applySpecification, createTransformRequest } from "@mountaya/elements";

const map = new maplibregl.Map({
  container,
  style: "https://demotiles.maplibre.org/style.json",
  transformRequest: createTransformRequest({ publishableKey }),
});

map.on("load", () => applySpecification(map, specification));

Use the maths without a map

These entries pull in no renderer, so a server or a worker can use them:

Import fromFor
@mountaya/elements/geoFlattening, bounds, corridor distance
@mountaya/elements/profileElevation series and per-segment rows
@mountaya/elements/unitsUnit conversions
@mountaya/elements/searchSearch results as list rows
@mountaya/elements/dataOne itinerary's geometry, figures and waypoints
import { boundsOf, extractLineStrings } from "@mountaya/elements/geo";
import { convertLength } from "@mountaya/elements/units";

const lines = extractLineStrings(itinerary.geojson);
const bounds = boundsOf([itinerary.geojson]); // null when there was nothing to bound
const kilometers = convertLength(12_430, "meter", "kilometer"); // 12.43

Next steps

Last updated