diff --git a/src/tiledimage.js b/src/tiledimage.js index e28ed224..42319144 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1931,24 +1931,35 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag } previousBest.push(tile); if (previousBest.length > maxNTiles) { - previousBest.sort(function (a, b) { - if (a === null) { - return 1; - } - if (b === null) { - return -1; - } - if (a.visibility === b.visibility) { - return (a.squaredDistance - b.squaredDistance); - } else { - return (a.visibility - b.visibility); - } - }); + this._sortTiles(previousBest); previousBest.pop(); } return previousBest; }, + /** + * @private + * @inner + * Sorts tiles in an array according to distance and visibility. + * + * @param {OpenSeadragon.Tile[]} tiles The tiles. + */ + _sortTiles: function( tiles ) { + tiles.sort(function (a, b) { + if (a === null) { + return 1; + } + if (b === null) { + return -1; + } + if (a.visibility === b.visibility) { + return (a.squaredDistance - b.squaredDistance); + } else { + return (a.visibility - b.visibility); + } + }); + }, + /** * @private * @inner