removed super class prototype extension patterns from DziTileSource in favor of more concise $.extend

This commit is contained in:
thatcher 2011-12-13 18:29:25 -05:00
parent f1882259e2
commit a7050af619
2 changed files with 90 additions and 94 deletions

View File

@ -2595,63 +2595,61 @@ $.DziTileSource = function(width, height, tileSize, tileOverlap, tilesUrl, fileF
this.initialize(); this.initialize();
}; };
$.DziTileSource.prototype = new $.TileSource(); $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
$.DziTileSource.prototype.constructor = $.DziTileSource; initialize: function() {
if (!this.displayRects) {
return;
}
$.DziTileSource.prototype.initialize = function() { for (var i = this.displayRects.length - 1; i >= 0; i--) {
if (!this.displayRects) { var rect = this.displayRects[i];
return; for (var level = rect.minLevel; level <= rect.maxLevel; level++) {
} if (!this._levelRects[level]) {
this._levelRects[level] = [];
for (var i = this.displayRects.length - 1; i >= 0; i--) { }
var rect = this.displayRects[i]; this._levelRects[level].push(rect);
for (var level = rect.minLevel; level <= rect.maxLevel; level++) {
if (!this._levelRects[level]) {
this._levelRects[level] = [];
} }
this._levelRects[level].push(rect);
} }
} },
};
$.DziTileSource.prototype.getTileUrl = function(level, x, y) { getTileUrl: function(level, x, y) {
return [this.tilesUrl, level, '/', x, '_', y, '.', this.fileFormat].join(''); return [this.tilesUrl, level, '/', x, '_', y, '.', this.fileFormat].join('');
}; },
$.DziTileSource.prototype.tileExists = function(level, x, y) { tileExists: function(level, x, y) {
var rects = this._levelRects[level]; var rects = this._levelRects[level];
if (!rects || !rects.length) { if (!rects || !rects.length) {
return true;
}
for (var i = rects.length - 1; i >= 0; i--) {
var rect = rects[i];
if (level < rect.minLevel || level > rect.maxLevel) {
continue;
}
var scale = this.getLevelScale(level);
var xMin = rect.x * scale;
var yMin = rect.y * scale;
var xMax = xMin + rect.width * scale;
var yMax = yMin + rect.height * scale;
xMin = Math.floor(xMin / this.tileSize);
yMin = Math.floor(yMin / this.tileSize);
xMax = Math.ceil(xMax / this.tileSize);
yMax = Math.ceil(yMax / this.tileSize);
if (xMin <= x && x < xMax && yMin <= y && y < yMax) {
return true; return true;
} }
for (var i = rects.length - 1; i >= 0; i--) {
var rect = rects[i];
if (level < rect.minLevel || level > rect.maxLevel) {
continue;
}
var scale = this.getLevelScale(level);
var xMin = rect.x * scale;
var yMin = rect.y * scale;
var xMax = xMin + rect.width * scale;
var yMax = yMin + rect.height * scale;
xMin = Math.floor(xMin / this.tileSize);
yMin = Math.floor(yMin / this.tileSize);
xMax = Math.ceil(xMax / this.tileSize);
yMax = Math.ceil(yMax / this.tileSize);
if (xMin <= x && x < xMax && yMin <= y && y < yMax) {
return true;
}
}
return false;
} }
});
return false;
};
$.DziTileSourceHelper = { $.DziTileSourceHelper = {
createFromXml: function(xmlUrl, xmlString, callback) { createFromXml: function(xmlUrl, xmlString, callback) {

View File

@ -13,63 +13,61 @@ $.DziTileSource = function(width, height, tileSize, tileOverlap, tilesUrl, fileF
this.initialize(); this.initialize();
}; };
$.DziTileSource.prototype = new $.TileSource(); $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
$.DziTileSource.prototype.constructor = $.DziTileSource; initialize: function() {
if (!this.displayRects) {
return;
}
$.DziTileSource.prototype.initialize = function() { for (var i = this.displayRects.length - 1; i >= 0; i--) {
if (!this.displayRects) { var rect = this.displayRects[i];
return; for (var level = rect.minLevel; level <= rect.maxLevel; level++) {
} if (!this._levelRects[level]) {
this._levelRects[level] = [];
for (var i = this.displayRects.length - 1; i >= 0; i--) { }
var rect = this.displayRects[i]; this._levelRects[level].push(rect);
for (var level = rect.minLevel; level <= rect.maxLevel; level++) {
if (!this._levelRects[level]) {
this._levelRects[level] = [];
} }
this._levelRects[level].push(rect);
} }
} },
};
$.DziTileSource.prototype.getTileUrl = function(level, x, y) { getTileUrl: function(level, x, y) {
return [this.tilesUrl, level, '/', x, '_', y, '.', this.fileFormat].join(''); return [this.tilesUrl, level, '/', x, '_', y, '.', this.fileFormat].join('');
}; },
$.DziTileSource.prototype.tileExists = function(level, x, y) { tileExists: function(level, x, y) {
var rects = this._levelRects[level]; var rects = this._levelRects[level];
if (!rects || !rects.length) { if (!rects || !rects.length) {
return true;
}
for (var i = rects.length - 1; i >= 0; i--) {
var rect = rects[i];
if (level < rect.minLevel || level > rect.maxLevel) {
continue;
}
var scale = this.getLevelScale(level);
var xMin = rect.x * scale;
var yMin = rect.y * scale;
var xMax = xMin + rect.width * scale;
var yMax = yMin + rect.height * scale;
xMin = Math.floor(xMin / this.tileSize);
yMin = Math.floor(yMin / this.tileSize);
xMax = Math.ceil(xMax / this.tileSize);
yMax = Math.ceil(yMax / this.tileSize);
if (xMin <= x && x < xMax && yMin <= y && y < yMax) {
return true; return true;
} }
for (var i = rects.length - 1; i >= 0; i--) {
var rect = rects[i];
if (level < rect.minLevel || level > rect.maxLevel) {
continue;
}
var scale = this.getLevelScale(level);
var xMin = rect.x * scale;
var yMin = rect.y * scale;
var xMax = xMin + rect.width * scale;
var yMax = yMin + rect.height * scale;
xMin = Math.floor(xMin / this.tileSize);
yMin = Math.floor(yMin / this.tileSize);
xMax = Math.ceil(xMax / this.tileSize);
yMax = Math.ceil(yMax / this.tileSize);
if (xMin <= x && x < xMax && yMin <= y && y < yMax) {
return true;
}
}
return false;
} }
});
return false;
};
$.DziTileSourceHelper = { $.DziTileSourceHelper = {
createFromXml: function(xmlUrl, xmlString, callback) { createFromXml: function(xmlUrl, xmlString, callback) {