From 1a60238c61b3f6a8d49384aca91d340ccdec36b0 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Tue, 16 May 2017 13:49:59 -0700 Subject: [PATCH 1/2] Improved best first level calculation --- src/tiledimage.js | 2 +- src/tilesource.js | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index f4178c8d..31a763c5 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -978,7 +978,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag var targetZeroRatio = viewport.deltaPixelsFromPointsNoRotate( this.source.getPixelRatio( Math.max( - this.source.getClosestLevel(viewport.containerSize) - 1, + this.source.getClosestLevel(), 0 ) ), diff --git a/src/tilesource.js b/src/tilesource.js index 26c220b7..d4c1e044 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -320,21 +320,14 @@ $.TileSource.prototype = { /** * @function - * @param {Rect} rect */ - getClosestLevel: function( rect ) { + getClosestLevel: function() { var i, - tilesPerSide, tiles; - for( i = this.minLevel; i < this.maxLevel; i++ ){ + for( i = this.minLevel; i <= this.maxLevel; i++ ){ tiles = this.getNumTiles( i ); - tilesPerSide = new $.Point( - Math.floor( rect.x / this.getTileWidth(i) ), - Math.floor( rect.y / this.getTileHeight(i) ) - ); - - if( tiles.x + 1 >= tilesPerSide.x && tiles.y + 1 >= tilesPerSide.y ){ + if (tiles.x > 1 || tiles.y > 1) { break; } } From 82b1b3e599d0d65cd7b1c1890af2bd5198f99849 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Fri, 19 May 2017 11:12:01 -0700 Subject: [PATCH 2/2] getClosestLevel refinement --- src/tilesource.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tilesource.js b/src/tilesource.js index d4c1e044..e83c4fab 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -320,18 +320,20 @@ $.TileSource.prototype = { /** * @function + * @returns {Number} The highest level in this tile source that can be contained in a single tile. */ getClosestLevel: function() { var i, tiles; - for( i = this.minLevel; i <= this.maxLevel; i++ ){ - tiles = this.getNumTiles( i ); + for (i = this.minLevel + 1; i <= this.maxLevel; i++){ + tiles = this.getNumTiles(i); if (tiles.x > 1 || tiles.y > 1) { break; } } - return Math.max( 0, i - 1 ); + + return i - 1; }, /**