diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index ae1896df..908fc38d 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -65,9 +65,18 @@ $.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; + var scfs = this.scale_factors || this.scale_factor; + if ( scfs instanceof Array ) { + for ( var i = 0; i < scfs.length; i++ ) { + var cf = Number( scfs[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;