openseadragon / html-overlay

An OpenSeadragon plugin that adds HTML overlay capability.
BSD 3-Clause "New" or "Revised" License
13 stars 4 forks source link

HTML Overlay for OpenSeadragon

An OpenSeadragon plugin that adds scaling HTML overlay capability. This is different from OpenSeadragon's built-in overlay functionality; while those overlays update their location as the user zooms and pans, they don't scale their contents to match the zoom of the OSD viewer. Possible uses for this include overlaying video or animated GIF elements to have them properly scale while playing.

Compatible with OpenSeadragon 2.0.0 or greater.

Documentation

To use, include the openseadragon-html-overlay.js file after openseadragon.js on your web page.

To add HTML overlay capability to your OpenSeadragon Viewer, call htmlOverlay() or htmlOverlay(options) on it. This will return a new object you can use to add overlays to.

Options

Currently there's just a single option: scale. By default the scale is set to 1, meaning that the HTML coordinates match the viewport coordinates of the viewer. Since the default viewport coordinates range from 0 to 1, this means you'd need to set your overlay's font-size to something tiny like 0.025px. Unfortunately browsers don't behave well with such sizes. One solution is to change your viewport coordinates to a bigger range, by setting your image size to something like 1000 when you load it into your viewer. Another solution is to use the scale option and set it similarly, like so: htmlOverlay({ scale: 1000 }). See the demo for examples of both approaches.

Methods

The object returned by htmlOverlay has these methods you can call:

See demo.html for an example of it in use. You can see it in action at http://openseadragon.github.io/html-overlay/demo.html.