/* * OpenSeadragon - IIIF1_1TileSource * * Copyright (C) 2009 CodePlex Foundation * Copyright (C) 2010-2013 OpenSeadragon contributors * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of CodePlex Foundation nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ (function( $ ){ /** * @class IIIF1_1TileSource * @classdesc A client implementation of the International Image Interoperability * Format: Image API 1.1 * * @memberof OpenSeadragon * @extends OpenSeadragon.TileSource * @see http://library.stanford.edu/iiif/image-api/ */ $.IIIF1_1TileSource = function( options ){ $.extend( true, this, options ); if( !(this.height && this.width && this['@id'] ) ){ throw new Error('IIIF required parameters not provided.'); } if ( !(this.tile_width && this.tile_height) ) { // use the short dimension if there aren't tile sizes provided. options.tileSize = Math.min(this.height, this.width); } else { options.tileSize = this.tile_width; } 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 ] ); }; $.extend( $.IIIF1_1TileSource.prototype, $.TileSource.prototype, /** @lends OpenSeadragon.IIIF1_1TileSource.prototype */{ /** * Determine if the data and/or url imply the image service is supported by * this tile source. * @function * @param {Object|Array} data * @param {String} optional - url */ supports: function( data, url ){ return data.profile && ( "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0" == data.profile || "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1" == data.profile || "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2" == data.profile || "http://library.stanford.edu/iiif/image-api/1.1/compliance.html" == data.profile ); }, /** * * @function * @param {Object} data - the raw configuration * @example