Class: ImageTileSource

OpenSeadragon.ImageTileSource

The ImageTileSource allows a simple image to be loaded into an OpenSeadragon Viewer. There are 2 ways to open an ImageTileSource: 1. viewer.open({type: 'image', url: fooUrl}); 2. viewer.open(new OpenSeadragon.ImageTileSource({url: fooUrl})); With the first syntax, the crossOriginPolicy, ajaxWithCredentials and useCanvas options are inherited from the viewer if they are not specified directly in the options object.

Constructor

new ImageTileSource(options)

Parameters:
Name Type Description
options Object Options object.
Properties
Name Type Attributes Default Description
url String URL of the image
buildPyramid Boolean <optional>
true If set to true (default), a pyramid will be built internally to provide a better downsampling.
crossOriginPolicy String | Boolean <optional>
false Valid values are 'Anonymous', 'use-credentials', and false. If false, image requests will not use CORS preventing internal pyramid building for images from other domains.
ajaxWithCredentials String | Boolean <optional>
false Whether to set the withCredentials XHR flag for AJAX requests (when loading tile sources).
useCanvas Boolean <optional>
true Set to false to prevent any use of the canvas API.
Source:

Extends

Members

aspectRatio :Number

Ratio of width to height
Type:
  • Number
Inherited From:
Source:

dimensions :OpenSeadragon.Point

Vector storing x and y dimensions ( width and height respectively ).
Type:
Inherited From:
Source:

maxLevel :Number

The maximum pyramid level this tile source supports or should attempt to load.
Type:
  • Number
Inherited From:
Source:

minLevel :Number

The minimum pyramid level this tile source supports or should attempt to load.
Type:
  • Number
Inherited From:
Source:

ready :Boolean

Type:
  • Boolean
Inherited From:
Source:

tileOverlap :Number

The overlap in pixels each tile shares with its adjacent neighbors.
Type:
  • Number
Inherited From:
Source:

Methods

_freeupCanvasMemory()

Free up canvas memory (iOS 12 or higher on 2GB RAM device has only 224MB canvas memory, and Safari keeps canvas until its height and width will be set to 0).
Source:

addHandler(eventName, handler, userDataopt)

Add an event handler for a given event.
Parameters:
Name Type Attributes Default Description
eventName String Name of event to register.
handler OpenSeadragon.EventHandler Function to call when event is triggered.
userData Object <optional>
null Arbitrary object to be passed unchanged to the handler.
Inherited From:
Source:

addOnceHandler(eventName, handler, userDataopt, timesopt)

Add an event handler to be triggered only once (or a given number of times) for a given event.
Parameters:
Name Type Attributes Default Description
eventName String Name of event to register.
handler OpenSeadragon.EventHandler Function to call when event is triggered.
userData Object <optional>
null Arbitrary object to be passed unchanged to the handler.
times Number <optional>
1 The number of times to handle the event before removing it.
Inherited From:
Source:

configure(options, dataUrl, postData) → {Object}

Parameters:
Name Type Description
options Object the options
dataUrl String the url the image was retrieved from, if any.
postData String HTTP POST data in k=v&k2=v2... form or null
Overrides:
Source:
Returns:
options - A dictionary of keyword arguments sufficient to configure this tile sources constructor.
Type
Object

createTileCache(cacheObject, data, tile)

Create cache object from the result of the download process. The cacheObject parameter should be used to attach the data to, there are no conventions on how it should be stored - all the logic is implemented within *TileCache() functions. Note that if you override any of *TileCache() functions, you should override all of them.
Parameters:
Name Type Description
cacheObject object context cache object
data * image data, the data sent to ImageJob.prototype.finish(), by default an Image object
tile Tile instance the cache was created with
Inherited From:
Source:

destroy()

Destroys ImageTileSource
Source:

destroyTileCache(cacheObject)

Cache object destructor, unset all properties you created to allow GC collection. Note that if you override any of *TileCache() functions, you should override all of them.
Parameters:
Name Type Description
cacheObject object context cache object
Inherited From:
Source:

downloadTileAbort(context)

Provide means of aborting the execution. Note that if you override this function, you should override also downloadTileStart().
Parameters:
Name Type Description
context ImageJob job, the same object as with downloadTileStart(..)
Properties
Name Type Attributes Description
userData * <optional>
Empty object to attach (and mainly read) your own data.
Inherited From:
Source:

downloadTileStart(context)

Download tile data. Note that if you override this function, you should override also downloadTileAbort().
Parameters:
Name Type Description
context ImageJob job context that you have to call finish(...) on.
Properties
Name Type Attributes Description
src String <optional>
URL of image to download.
loadWithAjax String <optional>
Whether to load this image with AJAX.
ajaxHeaders String <optional>
Headers to add to the image request if using AJAX.
ajaxWithCredentials Boolean <optional>
Whether to set withCredentials on AJAX requests.
crossOriginPolicy String <optional>
CORS policy to use for downloads
postData String <optional>
HTTP POST data (usually but not necessarily in k=v&k2=v2... form, see TileSource::getPostData) or null
userData * <optional>
Empty object to attach your own data and helper variables to.
finish function <optional>
Should be called unless abort() was executed, e.g. on all occasions, be it successful or unsuccessful request. Usage: context.finish(data, request, errMessage). Pass the downloaded data object or null upon failure. Add also reference to an ajax request if used. Provide error message in case of failure.
abort function <optional>
Called automatically when the job times out. Usage: context.abort().
callback function <optional>
@private - Called automatically once image has been downloaded (triggered by finish).
timeout Number <optional>
@private - The max number of milliseconds that this image job may take to complete.
errorMsg string <optional>
@private - The final error message, default null (set by finish).
Inherited From:
Source:

getClosestLevel() → {Number}

Inherited From:
Source:
Returns:
The highest level in this tile source that can be contained in a single tile.
Type
Number

getContext2D(level, x, y)

Retrieves a tile context 2D
Parameters:
Name Type Description
level Number Level of the tile
x Number x coordinate of the tile
y Number y coordinate of the tile
Source:

getHandler(eventName)

Get a function which iterates the list of all handlers registered for a given event, calling the handler for each.
Parameters:
Name Type Description
eventName String Name of event to get handlers for.
Inherited From:
Source:

getImageInfo(url)

Responsible for retrieving, and caching the image metadata pertinent to this TileSources implementation.
Parameters:
Name Type Description
url String
Overrides:
Source:
Throws:
Error

getLevelScale(level)

Parameters:
Name Type Description
level Number
Overrides:
Source:

getNumTiles(level)

Parameters:
Name Type Description
level Number
Overrides:
Source:

getPixelRatio(level)

Parameters:
Name Type Description
level Number
Inherited From:
Source:

getTileAjaxHeaders(level, x, y) → {Object}

Responsible for retrieving the headers which will be attached to the image request for the region specified by the given x, y, and level components. This option is only relevant if OpenSeadragon.Options.loadTilesWithAjax is set to true. The headers returned here will override headers specified at the Viewer or TiledImage level. Specifying a falsy value for a header will clear its existing value set at the Viewer or TiledImage level (if any).
Parameters:
Name Type Description
level Number
x Number
y Number
Inherited From:
Source:
Returns:
Type
Object

getTileAtPoint(level, point)

Parameters:
Name Type Description
level Number
point OpenSeadragon.Point
Inherited From:
Source:

getTileBounds(level, x, y, isSourceopt) → {OpenSeadragon.Rect}

Parameters:
Name Type Attributes Default Description
level Number
x Number
y Number
isSource Boolean <optional>
false Whether to return the source bounds of the tile.
Inherited From:
Source:
Returns:
Either where this tile fits (in normalized coordinates) or the portion of the tile to use as the source of the drawing operation (in pixels), depending on the isSource parameter.
Type
OpenSeadragon.Rect

getTileCacheData(cacheObject) → {*}

Raw data getter Note that if you override any of *TileCache() functions, you should override all of them.
Parameters:
Name Type Description
cacheObject object context cache object
Inherited From:
Source:
Returns:
cache data
Type
*

getTileCacheDataAsContext2D(cacheObject) → {CanvasRenderingContext2D}

Compatibility context 2D getter - most heavily used rendering method is a canvas-based approach, convert the data to a canvas and return it's 2D context Note that if you override any of *TileCache() functions, you should override all of them.
Parameters:
Name Type Description
cacheObject object context cache object
Inherited From:
Source:
Returns:
context of the canvas representation of the cache data
Type
CanvasRenderingContext2D

getTileCacheDataAsImage(cacheObject) → {Image}

Compatibility image element getter - plugins might need image representation of the data - div HTML rendering relies on image element presence Note that if you override any of *TileCache() functions, you should override all of them.
Parameters:
Name Type Description
cacheObject object context cache object
Inherited From:
Source:
Returns:
cache data as an Image
Type
Image

getTileHashKey(level, x, y, url, ajaxHeaders, postData)

The tile cache object is uniquely determined by this key and used to lookup the image data in cache: keys should be different if images are different. In case a tile has context2D property defined (TileSource.prototype.getContext2D) or its context2D is set manually; the cache is not used and this function is irrelevant. Note: default behaviour does not take into account post data.
Parameters:
Name Type Description
level Number tile level it was fetched with
x Number x-coordinate in the pyramid level
y Number y-coordinate in the pyramid level
url String the tile was fetched with
ajaxHeaders Object the tile was fetched with
postData * data the tile was fetched with (type depends on getTilePostData(..) return type)
Inherited From:
Source:

getTileHeight(level)

Return the tileHeight for a given level. Subclasses should override this if tileHeight can be different at different levels such as in IIIFTileSource. Code should use this function rather than reading from ._tileHeight directly.
Parameters:
Name Type Description
level Number
Inherited From:
Source:

getTilePostData(level, x, y) → {*|null}

Must use AJAX in order to work, i.e. loadTilesWithAjax = true is set. If a value is returned, ajax issues POST request to the tile url. If null is returned, ajax issues GET request. The return value must comply to the header 'content type'. Examples (USED HEADER --> getTilePostData CODE): 'Content-type': 'application/x-www-form-urlencoded' --> return "key1=value=1&key2=value2"; 'Content-type': 'application/x-www-form-urlencoded' --> return JSON.stringify({key: "value", number: 5}); 'Content-type': 'multipart/form-data' --> let result = new FormData(); result.append("data", myData); return result; IMPORTANT: in case you move all the logic on image fetching to post data, you must re-define 'getTileHashKey(...)' to stay unique for different tile images.
Parameters:
Name Type Description
level Number
x Number
y Number
Inherited From:
Source:
Returns:
post data to send with tile configuration request
Type
* | null

getTileUrl(level, x, y)

Retrieves a tile url
Parameters:
Name Type Description
level Number Level of the tile
x Number x coordinate of the tile
y Number y coordinate of the tile
Overrides:
Source:

getTileWidth(level)

Return the tileWidth for a given level. Subclasses should override this if tileWidth can be different at different levels such as in IIIFTileSource. Code should use this function rather than reading from ._tileWidth directly.
Parameters:
Name Type Description
level Number
Inherited From:
Source:

hasTransparency() → {boolean}

Decide whether tiles have transparency: this is crucial for correct images blending.
Inherited From:
Source:
Returns:
true if the image has transparency
Type
boolean

numberOfHandlers(eventName) → {number}

Get the amount of handlers registered for a given event.
Parameters:
Name Type Description
eventName String Name of event to inspect.
Inherited From:
Source:
Returns:
amount of events
Type
number

raiseEvent(eventName, eventArgs)

Trigger an event, optionally passing additional information.
Parameters:
Name Type Description
eventName String Name of event to register.
eventArgs Object Event-specific data.
Inherited From:
Source:

removeAllHandlers(eventName)

Remove all event handlers for a given event type. If no type is given all event handlers for every event type are removed.
Parameters:
Name Type Description
eventName String Name of event for which all handlers are to be removed.
Inherited From:
Source:

removeHandler(eventName, handler)

Remove a specific event handler for a given event.
Parameters:
Name Type Description
eventName String Name of event for which the handler is to be removed.
handler OpenSeadragon.EventHandler Function to be removed.
Inherited From:
Source:

setMaxLevel(level)

Set the maxLevel to the given level, and perform the memoization of getLevelScale with the new maxLevel. This function can be useful if the memoization is required before the first call of getLevelScale, or both memoized getLevelScale and maxLevel should be changed accordingly.
Parameters:
Name Type Description
level Number
Inherited From:
Source:

supports(data, optional)

Determine if the data and/or url imply the image service is supported by this tile source.
Parameters:
Name Type Description
data Object | Array
optional String url
Overrides:
Source:

tileExists(level, x, y)

Parameters:
Name Type Description
level Number
x Number
y Number
Inherited From:
Source: