2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
$.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;
|
|
|
|
this.bounds = bounds; // where this tile fits, in normalized coordinates
|
|
|
|
this.exists = exists; // part of sparse image? tile hasn't failed to load?
|
|
|
|
this.loaded = false; // is this tile loaded?
|
2011-12-06 07:50:25 +04:00
|
|
|
this.loading = false; // or is this tile loading?
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.elmt = null; // the HTML element for this tile
|
|
|
|
this.image = null; // the Image object for this tile
|
|
|
|
this.url = url; // the URL of this tile's image
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.style = null; // alias of this.elmt.style
|
|
|
|
this.position = null; // this tile's position on screen, in pixels
|
|
|
|
this.size = null; // this tile's size on screen, in pixels
|
2011-12-06 07:50:25 +04:00
|
|
|
this.blendStart = null; // the start time of this tile's blending
|
2012-01-12 03:22:13 +04:00
|
|
|
this.opacity = null; // the current opacity this tile should be
|
|
|
|
this.distance = null; // the distance of this tile to the viewport center
|
2011-12-06 07:50:25 +04:00
|
|
|
this.visibility = null; // the visibility score of this tile
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.beingDrawn = false; // whether this tile is currently being drawn
|
|
|
|
this.lastTouchTime = 0; // the time that tile was last touched
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Tile.prototype = {
|
|
|
|
|
|
|
|
toString: function() {
|
|
|
|
return this.level + "/" + this.x + "_" + this.y;
|
|
|
|
},
|
2012-01-12 03:22:13 +04:00
|
|
|
|
|
|
|
drawHTML: function( container ) {
|
|
|
|
|
|
|
|
if ( !this.loaded ) {
|
|
|
|
$.Debug.error(
|
|
|
|
"Attempting to draw tile " +
|
|
|
|
this.toString() +
|
|
|
|
" when it's not yet loaded."
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
if ( !this.elmt ) {
|
2012-01-18 03:30:41 +04:00
|
|
|
this.elmt = $.makeNeutralElement("img");
|
2012-01-12 03:22:13 +04:00
|
|
|
this.elmt.src = this.url;
|
|
|
|
this.style = this.elmt.style;
|
|
|
|
|
|
|
|
this.style.position = "absolute";
|
2011-12-06 07:50:25 +04:00
|
|
|
this.style.msInterpolationMode = "nearest-neighbor";
|
|
|
|
}
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
var position = this.position.apply( Math.floor );
|
|
|
|
var size = this.size.apply( Math.ceil );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
if ( this.elmt.parentNode != container ) {
|
|
|
|
container.appendChild( this.elmt );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.elmt.style.left = position.x + "px";
|
|
|
|
this.elmt.style.top = position.y + "px";
|
|
|
|
this.elmt.style.width = size.x + "px";
|
|
|
|
this.elmt.style.height = size.y + "px";
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.setElementOpacity( this.elmt, this.opacity );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
},
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
drawCanvas: function(context) {
|
|
|
|
if (!this.loaded) {
|
2012-01-12 03:22:13 +04:00
|
|
|
$.Debug.error(
|
|
|
|
"Attempting to draw tile " +
|
|
|
|
this.toString() +
|
|
|
|
" when it's not yet loaded."
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
var position = this.position,
|
|
|
|
size = this.size;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
context.globalAlpha = this.opacity;
|
|
|
|
context.drawImage(this.image, position.x, position.y, size.x, size.y);
|
|
|
|
},
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
unload: function() {
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( this.elmt && this.elmt.parentNode ) {
|
|
|
|
this.elmt.parentNode.removeChild( this.elmt );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
this.elmt = null;
|
|
|
|
this.image = null;
|
|
|
|
this.loaded = false;
|
2011-12-06 07:50:25 +04:00
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|