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
|
|
|
* @extends OpenSeadragon.TileSource
|
|
|
|
* @param {Number} width
|
|
|
|
* @param {Number} height
|
|
|
|
* @param {Number} tileSize
|
|
|
|
* @param {Number} tileOverlap
|
|
|
|
* @param {String} tilesUrl
|
|
|
|
* @param {String} fileFormat
|
|
|
|
* @param {OpenSeadragon.DisplayRect[]} displayRects
|
|
|
|
* @property {String} tilesUrl
|
|
|
|
* @property {String} fileFormat
|
|
|
|
* @property {OpenSeadragon.DisplayRect[]} displayRects
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
$.DziTileSource = function( width, height, tileSize, tileOverlap, tilesUrl, fileFormat, displayRects ) {
|
|
|
|
var i,
|
|
|
|
rect,
|
|
|
|
level;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
$.TileSource.call( this, width, height, tileSize, tileOverlap, null, null );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
this._levelRects = {};
|
|
|
|
this.tilesUrl = tilesUrl;
|
|
|
|
this.fileFormat = fileFormat;
|
2011-12-06 07:50:25 +04:00
|
|
|
this.displayRects = displayRects;
|
2011-12-14 03:34:12 +04:00
|
|
|
|
|
|
|
if ( this.displayRects ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
for ( i = this.displayRects.length - 1; i >= 0; i-- ) {
|
|
|
|
rect = this.displayRects[ i ];
|
|
|
|
for ( level = rect.minLevel; level <= rect.maxLevel; level++ ) {
|
|
|
|
if ( !this._levelRects[ level ] ) {
|
|
|
|
this._levelRects[ level ] = [];
|
2011-12-14 03:29:25 +04:00
|
|
|
}
|
2012-01-24 07:48:45 +04:00
|
|
|
this._levelRects[ level ].push( rect );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-14 03:34:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.DziTileSource.prototype.getTileUrl
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getTileUrl: function( level, x, y ) {
|
|
|
|
return [ this.tilesUrl, level, '/', x, '_', y, '.', this.fileFormat ].join( '' );
|
2011-12-14 03:29:25 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.DziTileSource.prototype.tileExists
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
tileExists: function( level, x, y ) {
|
|
|
|
var rects = this._levelRects[ level ],
|
|
|
|
rect,
|
|
|
|
scale,
|
|
|
|
xMin,
|
|
|
|
yMin,
|
|
|
|
xMax,
|
|
|
|
yMax,
|
|
|
|
i;
|
|
|
|
|
|
|
|
if ( !rects || !rects.length ) {
|
2011-12-14 03:29:25 +04:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
for ( i = rects.length - 1; i >= 0; i-- ) {
|
|
|
|
rect = rects[ i ];
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( level < rect.minLevel || level > rect.maxLevel ) {
|
2011-12-14 03:29:25 +04:00
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
scale = this.getLevelScale( level );
|
|
|
|
xMin = rect.x * scale;
|
|
|
|
yMin = rect.y * scale;
|
|
|
|
xMax = xMin + rect.width * scale;
|
|
|
|
yMax = yMin + rect.height * scale;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
xMin = Math.floor( xMin / this.tileSize );
|
|
|
|
yMin = Math.floor( yMin / this.tileSize );
|
|
|
|
xMax = Math.ceil( xMax / this.tileSize );
|
|
|
|
yMax = Math.ceil( yMax / this.tileSize );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( xMin <= x && x < xMax && yMin <= y && y < yMax ) {
|
2011-12-14 03:29:25 +04:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|