2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - TmsTileSource
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
2013-05-14 07:32:09 +04:00
|
|
|
* Copyright (C) 2010-2013 OpenSeadragon contributors
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-05-13 02:07:20 +04:00
|
|
|
/*
|
|
|
|
* Derived from the TMS tile source in Rainer Simon's seajax-utils project
|
|
|
|
* <http://github.com/rsimon/seajax-utils>. Rainer Simon has contributed
|
|
|
|
* the included code to the OpenSeadragon project under the New BSD license;
|
2013-05-14 07:39:27 +04:00
|
|
|
* see <https://github.com/openseadragon/openseadragon/issues/58>.
|
2013-05-13 02:07:20 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-02-09 00:45:22 +04:00
|
|
|
(function( $ ){
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-02-09 00:45:22 +04:00
|
|
|
/**
|
2013-11-25 20:48:44 +04:00
|
|
|
* @class TmsTileSource
|
|
|
|
* @classdesc A tilesource implementation for Tiled Map Services (TMS).
|
2013-05-13 02:07:20 +04:00
|
|
|
* TMS tile scheme ( [ as supported by OpenLayers ] is described here
|
|
|
|
* ( http://openlayers.org/dev/examples/tms.html ).
|
2013-02-09 00:45:22 +04:00
|
|
|
*
|
2013-11-16 10:19:53 +04:00
|
|
|
* @memberof OpenSeadragon
|
2013-02-09 00:45:22 +04:00
|
|
|
* @extends OpenSeadragon.TileSource
|
|
|
|
* @param {Number|Object} width - the pixel width of the image or the idiomatic
|
|
|
|
* options object which is used instead of positional arguments.
|
|
|
|
* @param {Number} height
|
|
|
|
* @param {Number} tileSize
|
|
|
|
* @param {Number} tileOverlap
|
|
|
|
* @param {String} tilesUrl
|
2013-06-19 21:33:25 +04:00
|
|
|
*/
|
2013-02-09 00:45:22 +04:00
|
|
|
$.TmsTileSource = function( width, height, tileSize, tileOverlap, tilesUrl ) {
|
|
|
|
var options;
|
|
|
|
|
|
|
|
if( $.isPlainObject( width ) ){
|
|
|
|
options = width;
|
|
|
|
}else{
|
|
|
|
options = {
|
|
|
|
width: arguments[0],
|
|
|
|
height: arguments[1],
|
|
|
|
tileSize: arguments[2],
|
|
|
|
tileOverlap: arguments[3],
|
|
|
|
tilesUrl: arguments[4]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// TMS has integer multiples of 256 for width/height and adds buffer
|
|
|
|
// if necessary -> account for this!
|
|
|
|
var bufferedWidth = Math.ceil(options.width / 256) * 256,
|
|
|
|
bufferedHeight = Math.ceil(options.height / 256) * 256,
|
|
|
|
max;
|
|
|
|
|
|
|
|
// Compute number of zoomlevels in this tileset
|
|
|
|
if (bufferedWidth > bufferedHeight) {
|
|
|
|
max = bufferedWidth / 256;
|
|
|
|
} else {
|
|
|
|
max = bufferedHeight / 256;
|
|
|
|
}
|
2017-01-08 17:52:57 +03:00
|
|
|
options.maxLevel = Math.ceil(Math.log(max) / Math.log(2)) - 1;
|
2013-02-09 00:45:22 +04:00
|
|
|
options.tileSize = 256;
|
|
|
|
options.width = bufferedWidth;
|
|
|
|
options.height = bufferedHeight;
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-02-09 00:45:22 +04:00
|
|
|
$.TileSource.apply( this, [ options ] );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-11-16 10:19:53 +04:00
|
|
|
$.extend( $.TmsTileSource.prototype, $.TileSource.prototype, /** @lends OpenSeadragon.TmsTileSource.prototype */{
|
2013-02-09 00:45:22 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ){
|
2020-06-26 02:01:14 +03:00
|
|
|
return ( data.type && "tiledmapservice" === data.type );
|
2013-02-09 00:45:22 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-19 21:33:25 +04:00
|
|
|
*
|
2013-02-09 00:45:22 +04:00
|
|
|
* @function
|
|
|
|
* @param {Object} data - the raw configuration
|
2018-09-01 15:36:31 +03:00
|
|
|
* @param {String} url - the url the data was retrieved from if any.
|
2022-01-20 20:03:08 +03:00
|
|
|
* @param {String} postData - HTTP POST data in k=v&k2=v2... form; or null
|
2013-06-19 21:33:25 +04:00
|
|
|
* @return {Object} options - A dictionary of keyword arguments sufficient
|
2013-02-09 00:45:22 +04:00
|
|
|
* to configure this tile sources constructor.
|
|
|
|
*/
|
2021-12-08 11:54:14 +03:00
|
|
|
configure: function( data, url, postData ){
|
2013-02-09 00:45:22 +04:00
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
|
|
|
getTileUrl: function( level, x, y ) {
|
|
|
|
// Convert from Deep Zoom definition to TMS zoom definition
|
|
|
|
var yTiles = this.getNumTiles( level ).y - 1;
|
|
|
|
|
2017-01-08 17:52:57 +03:00
|
|
|
return this.tilesUrl + level + "/" + x + "/" + (yTiles - y) + ".png";
|
2013-02-09 00:45:22 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-05-01 08:46:16 +04:00
|
|
|
}( OpenSeadragon ));
|