2013-02-09 00:45:22 +04:00
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A tilesource implementation for OpenStreetMap. Adopted from Rainer Simon
|
|
|
|
* project http://github.com/rsimon/seajax-utils.
|
|
|
|
*
|
|
|
|
* Note 1. Zoomlevels. Deep Zoom and OSM define zoom levels differently. In Deep
|
|
|
|
* Zoom, level 0 equals an image of 1x1 pixels. In OSM, level 0 equals an image of
|
|
|
|
* 256x256 levels (see http://gasi.ch/blog/inside-deep-zoom-2). I.e. there is a
|
|
|
|
* difference of log2(256)=8 levels.
|
|
|
|
*
|
|
|
|
* Note 2. Image dimension. According to the OSM Wiki
|
|
|
|
* (http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Zoom_levels)
|
|
|
|
* the highest Mapnik zoom level has 256.144x256.144 tiles, with a 256x256
|
|
|
|
* pixel size. I.e. the Deep Zoom image dimension is 65.572.864x65.572.864
|
|
|
|
* pixels.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
$.OsmTileSource = 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]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
//apply default setting for standard public OpenStreatMaps service
|
|
|
|
//but allow them to be specified so fliks can host there own instance
|
|
|
|
//or apply against other services supportting the same standard
|
|
|
|
if( !options.width || !options.height ){
|
|
|
|
options.width = 65572864;
|
|
|
|
options.height = 65572864;
|
|
|
|
}
|
|
|
|
if( !options.tileSize ){
|
|
|
|
options.tileSize = 256;
|
|
|
|
options.tileOverlap = 0;
|
|
|
|
}
|
|
|
|
if( !options.tilesUrl ){
|
|
|
|
options.tilesUrl = "http://tile.openstreetmap.org/";
|
|
|
|
}
|
|
|
|
options.minLevel = 8;
|
|
|
|
|
|
|
|
$.TileSource.apply( this, [ options ] );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( $.OsmTileSource.prototype, $.TileSource.prototype, {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the data and/or url imply the image service is supported by
|
|
|
|
* this tile source.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.DziTileSource.prototype.supports
|
|
|
|
* @param {Object|Array} data
|
|
|
|
* @param {String} optional - url
|
|
|
|
*/
|
|
|
|
supports: function( data, url ){
|
|
|
|
return (
|
|
|
|
data.type &&
|
|
|
|
"openstreetmaps" == data.type
|
2013-02-13 07:40:08 +04:00
|
|
|
);
|
2013-02-09 00:45:22 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.OsmTileSource.prototype.configure
|
|
|
|
* @param {Object} data - the raw configuration
|
|
|
|
* @param {String} url - the url the data was retreived from if any.
|
|
|
|
* @return {Object} options - A dictionary of keyword arguments sufficient
|
|
|
|
* to configure this tile sources constructor.
|
|
|
|
*/
|
|
|
|
configure: function( data, url ){
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.OsmTileSource.prototype.getTileUrl
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
|
|
|
getTileUrl: function( level, x, y ) {
|
|
|
|
return this.tilesUrl + (level - 8) + "/" + x + "/" + y + ".png";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|