Skip to content

Map Events

The Mapsted Maps JavaScript API emits events when the user interacts with the map or when the map state changes. Subscribe with on(name, handler) and detach with off(name, handler) or by calling the returned unsubscribe function.

Prerequisites

  • A working map embed — complete Embed your first map first.
  • All on() calls should be placed inside the onload callback so the API is ready to route events.

Available events

The Mapsted Maps JavaScript API defines 20 canonical events. All 20 are listed below.

EventFires when
mapMountedThe map iframe is mounted in the DOM
loadThe map is fully loaded and ready
selectThe user taps a room or POI
coordsSelectThe user taps a WGS84 coordinate (no entity)
floorChangeThe active floor changes
idleChangeThe map enters or exits idle state
mapOverlayMarkerSelectThe user taps a map-overlay marker
zoomLevelChangeThe zoom level crosses a threshold
mapCenterChangeThe map viewport center moves
promotionClickThe user clicks a promotion surface (covers the analyst-list poi_offer_clicked)
navigationStartA route overlay is drawn (covers the analyst-list navigation_started)
searchTextThe built-in search bar text changes (covers the analyst-list search_initiated and search_query_entered)
detailsViewThe entity details panel opens (covers the analyst-list poi_detail_viewed)
promotionDetailsThe promotion details panel opens
accessibilityChangeAccessibility routing mode is toggled
themeChangeThe map theme (light/dark) switches
boostCompleteAn applyBoost action has completed
allWildcard — fires for every event (payload includes type field)
protocolErrorA protocol error occurs between the API and the iframe
buildingChangeThe user navigates to a different building inside a multi-building property (payload: buildingId, previousBuildingId)

For typed payload shapes for each event, see the Events reference.

Steps

1. Listen for the select event

The select payload contains the entity that was tapped. Use it to drive a sidebar, fetch extra data, or open a custom panel.

javascript
mapsted.maps.on("select", function (payload) {
  console.log("Entity selected:", payload.entityId);
  console.log("Floor ID:", payload.floorId);
  console.log("Building ID:", payload.buildingId);
});

2. Inspect the full event payload

Log the raw payload object to discover every available field for your property.

javascript
mapsted.maps.on("select", function (payload) {
  console.log(JSON.stringify(payload, null, 2));
});

The select payload is an EntityData object with exactly buildingId, floorId, and entityId.

3. Subscribe to all events

Register a wildcard listener with on('all', fn) to deliver every API event to a single handler — useful for logging or analytics pipelines. The handler receives a single payload object with a type field identifying the event name, plus all the event-specific fields.

javascript
mapsted.maps.on('all', function (payload) {
  console.log("[mapsted]", payload.type, payload);
});

4. Read custom data attributes from an event

If you attached extra data to an entity using setEntityData, it comes back on the select event under payload.data.

javascript
mapsted.maps.setEntityData([
  {
    id: 302,    // Information 192 on property 603
    data: { department: "Information Services", capacity: 30 }
  }
]);

mapsted.maps.on("select", function (payload) {
  if (payload.data && payload.data.department) {
    console.log(payload.data.department + " — capacity: " + payload.data.capacity);
  }
});

5. Listen for a single event (fire once)

Use the built-in once() helper to subscribe to an event that fires at most once. It returns an unsubscribe function and automatically detaches the handler after the first invocation.

javascript
mapsted.maps.once("select", function (payload) {
  console.log("You selected entity:", payload.entityId);
});

6. Remove a listener

Always remove listeners when the map is destroyed or when your component unmounts (React, Vue, etc.) to prevent memory leaks. Pass the same function reference you gave to on(), or call the unsubscribe function returned by on().

javascript
function handleSelect(payload) {
  console.log("selected", payload.entityId);
}

// attach — returns an unsubscribe function
const unsub = mapsted.maps.on("select", handleSelect);

// detach via returned function
unsub();

// OR detach via off() with the original reference
mapsted.maps.off("select", handleSelect);

V2/V3 event API deprecated

mapsted.maps.addEventListener() and mapsted.maps.removeEventListener() are deprecated V2/V3 compatibility shims. They emit a console.warn and throw MAPSTED-1093 in strict mode. Migrate to the emitter API:

V2/V3 shimCanonical
addEventListener(name, fn)on(name, fn)
removeEventListener(name, fn)off(name, fn)
(manual once pattern)once(name, fn)

The on() handler receives the unwrapped payload directly (not a CustomEvent), so remove any event.detail access — use payload.entityId instead of event.detail.entityId.

Expected output

Opening the browser console and tapping a room in the University of Windsor demo (property 603) prints a JSON object containing the entity ID, floor ID, and building ID. The wildcard 'all' handler prints one line per interaction.

Next steps