diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index ae1896df..9c0ea902 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -65,10 +65,19 @@ $.IIIFTileSource = function( options ){ // to preserve backward compatibility. options.tileSize = this.tile_width; - options.maxLevel = options.maxLevel ? options.maxLevel : Number( - Math.ceil( Math.log( Math.max( this.width, this.height ), 2 ) ) - ); - + if (! options.maxLevel ) { + var mf = -1; + if ( this.scale_factor instanceof Array ) + for ( var i = 0; i < this.scale_factor.length; i++ ) + { + var cf = Number( this.scale_factor[i] ); + if ( !isNaN( cf ) && cf > mf ) mf = cf; + } + if ( mf < 0 ) + options.maxLevel = Number( Math.ceil( Math.log( Math.max( this.width, this.height ), 2 ))) + else options.maxLevel = mf; + } + $.TileSource.apply( this, [ options ] ); }; @@ -176,7 +185,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, { iiif_tile_h; - if ( level_width < this.tile_width || level_height < this.tile_height ){ + if ( level_width < this.tile_width && level_height < this.tile_height ){ iiif_region = 'full'; } else { iiif_tile_x = x * iiif_tile_size_width;