Events

Events control an embedded Mountaya map at runtime: switch content, change terrains, toggle overlays, and override display controls without reloading the iframe. The iframe also emits events back to the parent window to signal readiness.

Two flows run side by side:

  • Inbound (parent → iframe): your page sends structured payloads via iframe.contentWindow.postMessage() to control the map.
  • Outbound (iframe → parent): the iframe posts back lifecycle events like mountaya:ready so your page can sync UI state.

Every inbound message must include a type field that identifies the action.

Inbound messages

Messages sent from the parent window to the iframe.

iframe.contentWindow.postMessage({
  type: "mountaya:setItinerary",
  itineraryId: "bb908a79-dcc1-4db2-aba8-7238dd8f15fc",
}, "https://app.mountaya.com");

Every field besides type and the content identifier (itineraryId or routeId) is optional. Omitted fields are left unchanged from the previous state.

Required fields

Optional fields

Map's default state

Custom user experience

Outbound messages

Messages sent from the iframe to the parent window. Attach a message listener on window to react to them.

Full example

A complete example showing tabs that switch between itineraries with different display configurations.

const EMBED_ORIGIN = "https://app.mountaya.com";
const iframe = document.querySelector("iframe");

const examples = [
  {
    itineraryId: "bb908a79-dcc1-4db2-aba8-7238dd8f15fc",
    terrain: "topo",
    withOverlays: ["hillshade", "avalanche", "aspectslope", "wind"],
    withStreetviewControl: false,
    withTerrains: ["topo", "satellite"],
  },
  {
    itineraryId: "1b2a36f4-2ef4-49bc-89db-814ee7de3ebc",
    terrain: "topo",
    withOverlays: ["temperature-actual", "humidity", "wind", "pois"],
    withStreetviewControl: true,
    withTerrains: ["topo", "satellite"],
  },
  {
    itineraryId: "fbb1f6c2-345b-4f10-8387-6e60617ef894",
    terrain: "winter",
    withOverlays: ["*"],
    withStreetviewControl: false,
    withTerrains: ["winter"],
  },
];

function switchTab(index) {
  const example = examples[index];
  iframe.contentWindow.postMessage({
    type: "mountaya:setItinerary",
    ...example,
  }, EMBED_ORIGIN);
}