Tidy up ol.source.Zoomify tile URL calculations

This commit is contained in:
Tom Payne
2014-01-02 14:08:25 +01:00
parent 94fa3fb211
commit 71b91cd16a

View File

@@ -52,38 +52,31 @@ ol.source.Zoomify = function(opt_options) {
}
resolutions.reverse();
var createFromUrl = function(url) {
var template = url + '{tileIndex}/{z}-{x}-{y}.jpg';
return (
/**
* @this {ol.source.TileImage}
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {ol.proj.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, projection) {
if (goog.isNull(tileCoord)) {
return undefined;
} else {
var tileIndex = tileCoord.x +
(tileCoord.y * tierSizeInTiles[tileCoord.z][0]) +
tileCountUpToTier[tileCoord.z];
return template.replace('{tileIndex}', 'TileGroup' +
Math.floor((tileIndex) / ol.DEFAULT_TILE_SIZE))
.replace('{z}', '' + tileCoord.z)
.replace('{x}', '' + tileCoord.x)
.replace('{y}', '' + tileCoord.y);
}
}
);
};
var tileGrid = new ol.tilegrid.Zoomify({
resolutions: resolutions
});
var url = options.url;
var tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
tileGrid.createTileCoordTransform({extent: [0, 0, size[0], size[1]]}),
createFromUrl(options.url));
/**
* @this {ol.source.TileImage}
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {ol.proj.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, projection) {
if (goog.isNull(tileCoord)) {
return undefined;
} else {
var tileIndex = tileCoord.x +
tileCoord.y * tierSizeInTiles[tileCoord.z][0] +
tileCountUpToTier[tileCoord.z];
var tileGroup = (tileIndex / ol.DEFAULT_TILE_SIZE) | 0;
return url + 'TileGroup' + tileGroup + '/' +
tileCoord.z + '-' + tileCoord.x + '-' + tileCoord.y + '.jpg';
}
});
goog.base(this, {
attributions: options.attributions,