Skip to content

Instantly share code, notes, and snippets.

@aeschylus
Last active June 5, 2017 07:36
Show Gist options
  • Save aeschylus/b2653ba5edc1280c0002933d3e9afde7 to your computer and use it in GitHub Desktop.
Save aeschylus/b2653ba5edc1280c0002933d3e9afde7 to your computer and use it in GitHub Desktop.
Some descriptions of common API operations in Mirador.

Common Mirador API Task Examples

Mirador exposes a fairly powerful set of events as its primary API, and it is possible to introspect the state of Mirador with a number of convenience methods to react to changes and export and import data and viewer state. In the following examples, we'll go through some common tasks that can be accomplished programmatically, and answer any questions for improving our documentation. To follow along, simply visit projectMirador.org/demo and open the javascript console. We will work through these examples by manipulating Mirador programmatically in the console.

The projectMirador.org/demo page exposes an instance of Mirador called myMiradorInstance. All methods, events, and state can be accessed here. Let's start by retrieving different pieces of information about the current viewer state.

Getting State Information

The saveController is the central state manager of Mirador. Though it is not fully implemented, most state of interest can be accessed through it. Type myMiradorInstance.saveController to access it and explore its API through the developer tools' autocomplete feature.

Getting the Current State

You can get a complete description of the serialisable configuration of mirador by typing: myMiradorInstance.saveController.currentConfig and pressing enter.

Getting the Information for a Window

Mirador's current windows can be retrieved by id, or from the workspace. Try: myMiradorInstance.saveController.currentConfig.windowObjects This will return an array of currently displayed windows, with their IDs and addresses. You can then obtain the live window instance (In the non-serialised form) using the saveController convenience function.

Getting a Window from its Slot Address

Mirador's windows are kept in "slots" in the windowing system. By knowing the address of the slot, it is possible to retrieve the window occupying a certain position in the layout.

Getting the Currently Loaded Manifests

The manifests currently in the viewer are available by typing myMiradorInstance.saveController.currentConfig.data. Notice that this is the same as the configuration that was initially passed in to begin with.

Listening for Events

Because of the highly asynchronous nature of what Mirador does (requesting, managing, and rendering hundreds of remote resources through multiple layers of linked data), Mirador uses a node.js style eventEmitter. Mirador exposes its event system to the programmer through myMiradorInstance.viewer.eventEmitter. The eventEmitter has a .subscribe() and a .publish() method, which can be used to receive and fire events. This can be a powerful tool for building software that reacts to Mirador's event stream.

Listening for the Main Interface to Initialise

Listening for Manifests to Load

Listening for Annotations

Firing Actions and Modifying State

Loading a New Manifest Programmatically

Opening a New Slot Programmatically

Opening a New Window Programmatically

Changing the Page Programmatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment