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} level The zoom level this tile belongs to.
|
|
|
|
* @param {Number} x The vector component 'x'.
|
|
|
|
* @param {Number} y The vector component 'y'.
|
|
|
|
* @param {OpenSeadragon.Point} bounds Where this tile fits, in normalized
|
|
|
|
* coordinates
|
|
|
|
* @param {Boolean} exists Is this tile a part of a sparse image? ( Also has
|
|
|
|
* this tile failed to load?
|
|
|
|
* @param {String} url The URL of this tile's image.
|
|
|
|
*
|
|
|
|
* @property {Number} level The zoom level this tile belongs to.
|
|
|
|
* @property {Number} x The vector component 'x'.
|
|
|
|
* @property {Number} y The vector component 'y'.
|
|
|
|
* @property {OpenSeadragon.Point} bounds Where this tile fits, in normalized
|
|
|
|
* coordinates
|
|
|
|
* @property {Boolean} exists Is this tile a part of a sparse image? ( Also has
|
|
|
|
* this tile failed to load?
|
|
|
|
* @property {String} url The URL of this tile's image.
|
|
|
|
* @property {Boolean} loaded Is this tile loaded?
|
|
|
|
* @property {Boolean} loading Is this tile loading
|
2012-02-02 01:56:04 +04:00
|
|
|
* @property {Element} element The HTML element for this tile
|
2012-02-01 00:59:09 +04:00
|
|
|
* @property {Image} image The Image object for this tile
|
2012-02-02 01:56:04 +04:00
|
|
|
* @property {String} style The alias of this.element.style.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @property {String} position This tile's position on screen, in pixels.
|
|
|
|
* @property {String} size This tile's size on screen, in pixels
|
|
|
|
* @property {String} blendStart The start time of this tile's blending
|
|
|
|
* @property {String} opacity The current opacity this tile should be.
|
|
|
|
* @property {String} distance The distance of this tile to the viewport center
|
|
|
|
* @property {String} visibility The visibility score of this tile.
|
|
|
|
* @property {Boolean} beingDrawn Whether this tile is currently being drawn
|
|
|
|
* @property {Number} lastTouchTime Timestamp the tile was last touched.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
$.Tile = function(level, x, y, bounds, exists, url) {
|
2012-01-12 03:22:13 +04:00
|
|
|
this.level = level;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2012-02-01 00:59:09 +04:00
|
|
|
this.bounds = bounds;
|
|
|
|
this.exists = exists;
|
|
|
|
this.url = url;
|
|
|
|
this.loaded = false;
|
|
|
|
this.loading = false;
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
this.element = null;
|
2012-02-01 00:59:09 +04:00
|
|
|
this.image = null;
|
|
|
|
|
|
|
|
this.style = null;
|
|
|
|
this.position = null;
|
|
|
|
this.size = null;
|
|
|
|
this.blendStart = null;
|
|
|
|
this.opacity = null;
|
|
|
|
this.distance = null;
|
|
|
|
this.visibility = null;
|
|
|
|
|
|
|
|
this.beingDrawn = false;
|
|
|
|
this.lastTouchTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Tile.prototype = {
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Provides a string representation of this tiles level and (x,y)
|
|
|
|
* components.
|
|
|
|
* @function
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
toString: function() {
|
|
|
|
return this.level + "/" + this.x + "_" + this.y;
|
|
|
|
},
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Renders the tile in an html container.
|
|
|
|
* @function
|
|
|
|
* @param {Element} container
|
|
|
|
*/
|
2012-01-12 03:22:13 +04:00
|
|
|
drawHTML: function( container ) {
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
var position = this.position.apply( Math.floor ),
|
|
|
|
size = this.size.apply( Math.ceil );
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
if ( !this.loaded ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
$.console.warn(
|
2012-01-24 07:48:45 +04:00
|
|
|
"Attempting to draw tile %s when it's not yet loaded.",
|
|
|
|
this.toString()
|
2012-01-12 03:22:13 +04:00
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
if ( !this.element ) {
|
|
|
|
this.element = $.makeNeutralElement("img");
|
|
|
|
this.element.src = this.url;
|
|
|
|
this.style = this.element.style;
|
2012-01-12 03:22:13 +04:00
|
|
|
|
|
|
|
this.style.position = "absolute";
|
2011-12-06 07:50:25 +04:00
|
|
|
this.style.msInterpolationMode = "nearest-neighbor";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
if ( this.element.parentNode != container ) {
|
|
|
|
container.appendChild( this.element );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
this.element.style.left = position.x + "px";
|
|
|
|
this.element.style.top = position.y + "px";
|
|
|
|
this.element.style.width = size.x + "px";
|
|
|
|
this.element.style.height = size.y + "px";
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
$.setElementOpacity( this.element, this.opacity );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
},
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Renders the tile in a canvas-based context.
|
|
|
|
* @function
|
|
|
|
* @param {Canvas} context
|
|
|
|
*/
|
|
|
|
drawCanvas: function( context ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
|
|
|
|
var position = this.position,
|
|
|
|
size = this.size;
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( !this.loaded ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
$.console.warn(
|
2012-01-24 07:48:45 +04:00
|
|
|
"Attempting to draw tile %s when it's not yet loaded.",
|
|
|
|
this.toString()
|
2012-01-12 03:22:13 +04:00
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.globalAlpha = this.opacity;
|
2012-02-01 00:59:09 +04:00
|
|
|
context.drawImage( this.image, position.x, position.y, size.x, size.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Removes tile from it's contianer.
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
unload: function() {
|
2012-02-02 01:56:04 +04:00
|
|
|
if ( this.element && this.element.parentNode ) {
|
|
|
|
this.element.parentNode.removeChild( this.element );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
this.element = null;
|
2012-01-18 03:30:41 +04:00
|
|
|
this.image = null;
|
|
|
|
this.loaded = false;
|
2011-12-06 07:50:25 +04:00
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|