2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Number} width
|
|
|
|
* @param {Number} height
|
|
|
|
* @param {Number} tileSize
|
|
|
|
* @param {Number} tileOverlap
|
|
|
|
* @param {Number} minLevel
|
|
|
|
* @param {Number} maxLevel
|
|
|
|
* @property {Number} aspectRatio
|
|
|
|
* @property {Number} dimensions
|
|
|
|
* @property {Number} tileSize
|
|
|
|
* @property {Number} tileOverlap
|
|
|
|
* @property {Number} minLevel
|
|
|
|
* @property {Number} maxLevel
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
$.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
this.aspectRatio = width / height;
|
2012-01-24 07:48:45 +04:00
|
|
|
this.dimensions = new $.Point( width, height );
|
|
|
|
this.tileSize = tileSize ? tileSize : 0;
|
|
|
|
this.tileOverlap = tileOverlap ? tileOverlap : 0;
|
|
|
|
this.minLevel = minLevel ? minLevel : 0;
|
|
|
|
this.maxLevel = maxLevel ? maxLevel :
|
2012-01-18 03:30:41 +04:00
|
|
|
Math.ceil(
|
|
|
|
Math.log( Math.max( width, height ) ) /
|
|
|
|
Math.log( 2 )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.TileSource.prototype = {
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getLevelScale: function( level ) {
|
|
|
|
return 1 / ( 1 << ( this.maxLevel - level ) );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getNumTiles: function( level ) {
|
|
|
|
var scale = this.getLevelScale( level ),
|
|
|
|
x = Math.ceil( scale * this.dimensions.x / this.tileSize ),
|
|
|
|
y = Math.ceil( scale * this.dimensions.y / this.tileSize );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
return new $.Point( x, y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getPixelRatio: function( level ) {
|
|
|
|
var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
|
|
|
rx = 1.0 / imageSizeScaled.x,
|
|
|
|
ry = 1.0 / imageSizeScaled.y;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
return new $.Point(rx, ry);
|
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {OpenSeadragon.Point} point
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getTileAtPoint: function( level, point ) {
|
|
|
|
var pixel = point.times( this.dimensions.x ).times( this.getLevelScale(level ) ),
|
|
|
|
tx = Math.floor( pixel.x / this.tileSize ),
|
|
|
|
ty = Math.floor( pixel.y / this.tileSize );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
return new $.Point( tx, ty );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getTileBounds: function( level, x, y ) {
|
|
|
|
var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
|
|
|
px = ( x === 0 ) ? 0 : this.tileSize * x - this.tileOverlap,
|
|
|
|
py = ( y === 0 ) ? 0 : this.tileSize * y - this.tileOverlap,
|
|
|
|
sx = this.tileSize + ( x === 0 ? 1 : 2 ) * this.tileOverlap,
|
|
|
|
sy = this.tileSize + ( y === 0 ? 1 : 2 ) * this.tileOverlap,
|
|
|
|
scale = 1.0 / dimensionsScaled.x;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
sx = Math.min( sx, dimensionsScaled.x - px );
|
|
|
|
sy = Math.min( sy, dimensionsScaled.y - py );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
return new $.Rect( px * scale, py * scale, sx * scale, sy * scale );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* This method is not implemented by this class other than to throw an Error
|
|
|
|
* announcing you have to implement it. Because of the variety of tile
|
|
|
|
* server technologies, and various specifications for building image
|
|
|
|
* pyramids, this method is here to allow easy integration.
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
2011-12-13 16:24:34 +04:00
|
|
|
getTileUrl: function( level, x, y ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
throw new Error( "Method not implemented." );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2011-12-13 16:24:34 +04:00
|
|
|
tileExists: function( level, x, y ) {
|
|
|
|
var numTiles = this.getNumTiles( level );
|
|
|
|
return level >= this.minLevel &&
|
|
|
|
level <= this.maxLevel &&
|
|
|
|
x >= 0 &&
|
|
|
|
y >= 0 &&
|
|
|
|
x < numTiles.x &&
|
|
|
|
y < numTiles.y;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|