Skip to content

Global Context

The globalContext shares a Context interface with the localContext. Here is the full GlobalContext interface:

typescript
interface Context {
  readonly hub: EventHandler;

  registerShortcut(shortcut: Shortcut, context: GlobalContext | LocalContext): boolean;
  unregisterShortcut(name: string, context: GlobalContext | LocalContext): boolean;

  readonly loading: boolean;
  loadingProcessStart(): void;
  loadingProcessEnd(): void;
  spinner: { component: Object, props: Object }; // a custom spinner replacing the default BIMDataSpinner

  modals: {
    pushModal(component: any, props?: any, options?: any): void;
    clearModal(): void;
  };

  el: HTMLElement;
}
typescript
interface GlobalContext extends Context {
  resizable: boolean;
  open({
    ratio: number;
    direction?: "column" | "row"; // defaults to "row"
    insertAfter?: boolean;        // defaults to true
    windowName?: string;
    windowState?: { modelIds: number[]; viewpoint: Object; storey: string; };
    localContextId?: number;
  }): Promise<number>;
  close(localContextId: number): Promise<boolean>;
  swap(localContextIdA: number, localContextIdB: number): Promise<void>;

  header: ViewerHeader;

  readonly activeLocalContext?: LocalContext;
  readonly localContexts: LocalContext[];
  getLocalContexts(windowName: string): LocalContext[];

  readonly pluginInstances: Map<string, PluginInstance[]>;
  readonly plugins: Map<string, PluginComponentInstance[]>;

  getViewers(): ModelViewerInstance[];

  readonly loadedModels: StateModel[];
  readonly loadedModelIds: number[];
  readonly loadingModelIds: number[];
}

Global Context API

NameDescription
properties
resizableIf true, the user can resize the windows by dragging the window separators.
activeLocalContextThe currently active local context (the one associated to the window that is currently hovered by the cursor).
localContextsList of all local contexts.
pluginInstancesA map of all plugin instances, map keys are plugin names and values are list of instances.
pluginsA map of all plugin component instances.
loadedModelsList of currently loaded models (in all windows).
loadedModelIdsList of currently loaded model ids (in all windows).
loadingModelIdsList of currently loading model ids (in all windows).
methods
open(options: any)(async) Split the given context with the specified options (ratio, direction, window, etc...).
close(id: number)(async) Close the given context.
swap(id1: number, id2: number)(async) Swap the given contexts.
getLocalContexts(name: string)Returns local contexts that are associated with a given window.
getViewers()Returns all viewer plugins instances.

Events

The table below describe global context specific events:

NamePayloadDescription
window-openthe opened window objectSent when a window is selected on the window selector.
window-closethe closed window objectSent when a window is closed.

Additionally a set of local context events are also emitted on global context.