Get started
Map Publishing

Iframe events

Iframe events

Your page talks to the embed with postMessage. It sends commands in, and the embed posts events back. Every message is an object whose type starts with mountaya:.

Messages

MessageDirectionPayloadDoes
mountaya:setItineraryPage to embeditineraryId, display overridesSwitches the content
mountaya:readyEmbed to pageerror, bounds, itineraryId, terrainSays the map has settled
mountaya:requestSessionTokenEmbed to pageNoneAsks for a session token
mountaya:setSessionTokenPage to embedtoken, expiresAtHands the embed a session token

These four messages are the whole public protocol.

Switch the content

Post mountaya:setItinerary to the iframe's window, targeting the embed's origin. The iframe does not reload.

const iframe = document.querySelector<HTMLIFrameElement>("#mountaya");

iframe?.contentWindow?.postMessage(
  { type: "mountaya:setItinerary", itineraryId: "3e8a5f21-9c47-4d6b-b0e3-6a1f7d2c9b54" },
  "https://app.mountaya.com",
);

The same message can change the display. Fields you leave out keep their current value:

{
  "type": "mountaya:setItinerary",
  "itineraryId": "3e8a5f21-9c47-4d6b-b0e3-6a1f7d2c9b54",
  "terrain": "satellite",
  "withOverlays": ["hillshade", "steepness"]
}

Send your first command after the embed's first mountaya:ready event, or it may arrive too early.

Listen for the ready event

The embed posts mountaya:ready when the map has loaded, and again after each switch. Check the sender's origin first.

window.addEventListener("message", (event: MessageEvent) => {
  if (event.origin !== "https://app.mountaya.com" || event.data?.type !== "mountaya:ready") {
    return;
  }

  if (event.data.error) {
    console.error("Mountaya embed failed:", event.data.error);
    return;
  }

  console.log("Map ready, bounds:", event.data.bounds);
});
Event
{
  "type": "mountaya:ready",
  "error": null,
  "bounds": [6.7991, 45.8915, 6.9459, 46.0027],
  "itineraryId": "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  "terrain": "topo"
}
FieldTypeMeaning
errorstring or nullnull on success, otherwise timeout or not_found
boundsfour numbers or nullThe content's extent as west, south, east, north
itineraryIdstring or nullThe itinerary on the map
terrainstringThe base map on the map

Next steps

Last updated