Event Handing
The Floorplan SDK emits global events for interactions inside the embedded plan. Each event delivers a unified payload describing the targeted entity (space, room, wall perimeter, or area/background) and its position.
Event names
export type FloorPlanEvents =
| "click"
| "right-click"
| "double-click"
| "hover"
| "blur"
| "plan-right-click"
| "outside-click";click / double-click / right-click — Interaction on an entity.
hover / blur — Pointer enters/leaves an entity.
plan-right-click — Context menu on the plan canvas (not on a specific entity).
outside-click — Click detected outside interactive entities (background).
Payload shape
export type FloorPlanEntityType = "SPACE" | "WALL_PERIMETER" | "ROOM" | "AREA";
export type Center = {
x: number; // absolute pixels in canvas coords
y: number;
relativeX?: number; // 0..1 within canvas
relativeY?: number; // 0..1 within canvas
};
export interface FloorPlanEntity<T extends Record<string, any> = {}> {
id: string;
type: FloorPlanEntityType; // "SPACE" | "ROOM" | "WALL_PERIMETER" | "AREA"
center?: Center;
properties?: T & { locationId: string; layerId: string };
}
export type SpaceMetadata = any;
export type RoomMetadata = any;
export type WallPerimeterMetadata = any;
export type FloorPlanEntityMetadata =
| SpaceMetadata
| RoomMetadata
| WallPerimeterMetadata;
interface FloorPlanEvent {
event: FloorPlanEvents;
id: string; // mirrors metadata.id
metadata: FloorPlanEntity<FloorPlanEntityMetadata>;
}metadata.typeidentifies the target: SPACE, ROOM, WALL_PERIMETER, or AREA (background).properties.locationIdandproperties.layerIdhelp you route events per site/floor.centerprovides both pixel and relative coordinates for precise UI placement (e.g., tooltips, context menus).
Subscribing & unsubscribing
Vanilla JS example
Filtering & patterns
By entity type
Coordinate‑based UI
Debounce high‑frequency events
Security
Events are delivered from the embedded iframe via postMessage. The SDK validates the origin internally. If you attach your own window.message listeners, verify event.origin === "https://floorplan.gospace.app" before using payloads.
Last updated
Was this helpful?