openseadragon/src/tmstilesource.js

98 lines
2.9 KiB
JavaScript

(function( $ ){
/**
* A tilesource implementation for Tiled Map Services (TMS). Adopted from Rainer Simon
* project http://github.com/rsimon/seajax-utils. TMS tile
* scheme ( [ as supported by OpenLayers ] is described here
* ( http://openlayers.org/dev/examples/tms.html ) )
*
* @class
* @extends OpenSeadragon.TileSource
* @param {Number|Object} width - the pixel width of the image or the idiomatic
* options object which is used instead of positional arguments.
* @param {Number} height
* @param {Number} tileSize
* @param {Number} tileOverlap
* @param {String} tilesUrl
*/
$.TmsTileSource = function( width, height, tileSize, tileOverlap, tilesUrl ) {
var options;
if( $.isPlainObject( width ) ){
options = width;
}else{
options = {
width: arguments[0],
height: arguments[1],
tileSize: arguments[2],
tileOverlap: arguments[3],
tilesUrl: arguments[4]
};
}
// TMS has integer multiples of 256 for width/height and adds buffer
// if necessary -> account for this!
var bufferedWidth = Math.ceil(options.width / 256) * 256,
bufferedHeight = Math.ceil(options.height / 256) * 256,
max;
// Compute number of zoomlevels in this tileset
if (bufferedWidth > bufferedHeight) {
max = bufferedWidth / 256;
} else {
max = bufferedHeight / 256;
}
options.maxLevel = Math.ceil(Math.log(max)/Math.log(2)) - 1;
options.tileSize = 256;
options.width = bufferedWidth;
options.height = bufferedHeight;
$.TileSource.apply( this, [ options ] );
};
$.extend( $.TmsTileSource.prototype, $.TileSource.prototype, {
/**
* Determine if the data and/or url imply the image service is supported by
* this tile source.
* @function
* @name OpenSeadragon.TmsTileSource.prototype.supports
* @param {Object|Array} data
* @param {String} optional - url
*/
supports: function( data, url ){
return ( data.type && "tiledmapservice" == data.type );
},
/**
*
* @function
* @name OpenSeadragon.TmsTileSource.prototype.configure
* @param {Object} data - the raw configuration
* @param {String} url - the url the data was retreived from if any.
* @return {Object} options - A dictionary of keyword arguments sufficient
* to configure this tile sources constructor.
*/
configure: function( data, url ){
return data;
},
/**
* @function
* @name OpenSeadragon.TmsTileSource.prototype.getTileUrl
* @param {Number} level
* @param {Number} x
* @param {Number} y
*/
getTileUrl: function( level, x, y ) {
// Convert from Deep Zoom definition to TMS zoom definition
var yTiles = this.getNumTiles( level ).y - 1;
return this.tilesUrl + level + "/" + x + "/" + (yTiles - y) + ".png";
}
});
}( OpenSeadragon ));