Merge pull request #7379 from lasselaakkonen/6608-zoomify-custom-tile-size

Add support for custom tile size to Zoomify source
This commit is contained in:
Andreas Hocevar
2017-10-31 10:50:37 +01:00
committed by GitHub
3 changed files with 53 additions and 22 deletions

View File

@@ -7,6 +7,7 @@ goog.require('ol.TileUrlFunction');
goog.require('ol.asserts');
goog.require('ol.dom');
goog.require('ol.extent');
goog.require('ol.size');
goog.require('ol.source.TileImage');
goog.require('ol.tilegrid.TileGrid');
@@ -33,25 +34,26 @@ ol.source.Zoomify = function(opt_options) {
var imageWidth = size[0];
var imageHeight = size[1];
var tierSizeInTiles = [];
var tileSize = ol.DEFAULT_TILE_SIZE;
var tileSize = options.tileSize || ol.DEFAULT_TILE_SIZE;
var tileSizeForTierSizeCalculation = tileSize;
switch (tierSizeCalculation) {
case ol.source.Zoomify.TierSizeCalculation_.DEFAULT:
while (imageWidth > tileSize || imageHeight > tileSize) {
while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([
Math.ceil(imageWidth / tileSize),
Math.ceil(imageHeight / tileSize)
Math.ceil(imageWidth / tileSizeForTierSizeCalculation),
Math.ceil(imageHeight / tileSizeForTierSizeCalculation)
]);
tileSize += tileSize;
tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation;
}
break;
case ol.source.Zoomify.TierSizeCalculation_.TRUNCATED:
var width = imageWidth;
var height = imageHeight;
while (width > tileSize || height > tileSize) {
while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([
Math.ceil(width / tileSize),
Math.ceil(height / tileSize)
Math.ceil(width / tileSizeForTierSizeCalculation),
Math.ceil(height / tileSizeForTierSizeCalculation)
]);
width >>= 1;
height >>= 1;
@@ -79,6 +81,7 @@ ol.source.Zoomify = function(opt_options) {
var extent = [0, -size[1], size[0], 0];
var tileGrid = new ol.tilegrid.TileGrid({
tileSize: tileSize,
extent: extent,
origin: ol.extent.getTopLeft(extent),
resolutions: resolutions
@@ -113,7 +116,8 @@ ol.source.Zoomify = function(opt_options) {
var tileIndex =
tileCoordX +
tileCoordY * tierSizeInTiles[tileCoordZ][0];
var tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / ol.DEFAULT_TILE_SIZE) | 0;
var tileSize = tileGrid.getTileSize(tileCoordZ);
var tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / tileSize) | 0;
var localContext = {
'z': tileCoordZ,
'x': tileCoordX,
@@ -130,6 +134,8 @@ ol.source.Zoomify = function(opt_options) {
var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate));
var ZoomifyTileClass = ol.source.Zoomify.Tile_.bind(null, tileGrid);
ol.source.TileImage.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
@@ -137,7 +143,7 @@ ol.source.Zoomify = function(opt_options) {
logo: options.logo,
projection: options.projection,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileClass: ol.source.Zoomify.Tile_,
tileClass: ZoomifyTileClass,
tileGrid: tileGrid,
tileUrlFunction: tileUrlFunction,
transition: options.transition
@@ -146,10 +152,10 @@ ol.source.Zoomify = function(opt_options) {
};
ol.inherits(ol.source.Zoomify, ol.source.TileImage);
/**
* @constructor
* @extends {ol.ImageTile}
* @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.TileState} state State.
* @param {string} src Image source URI.
@@ -159,7 +165,7 @@ ol.inherits(ol.source.Zoomify, ol.source.TileImage);
* @private
*/
ol.source.Zoomify.Tile_ = function(
tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
ol.ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
@@ -169,6 +175,11 @@ ol.source.Zoomify.Tile_ = function(
*/
this.zoomifyImage_ = null;
/**
* @private
* @type {ol.Size}
*/
this.tileSize_ = ol.size.toSize(tileGrid.getTileSize(tileCoord[0]));
};
ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile);
@@ -180,14 +191,14 @@ ol.source.Zoomify.Tile_.prototype.getImage = function() {
if (this.zoomifyImage_) {
return this.zoomifyImage_;
}
var tileSize = ol.DEFAULT_TILE_SIZE;
var image = ol.ImageTile.prototype.getImage.call(this);
if (this.state == ol.TileState.LOADED) {
if (image.width == tileSize && image.height == tileSize) {
var tileSize = this.tileSize_;
if (image.width == tileSize[0] && image.height == tileSize[1]) {
this.zoomifyImage_ = image;
return image;
} else {
var context = ol.dom.createCanvasContext2D(tileSize, tileSize);
var context = ol.dom.createCanvasContext2D(tileSize[0], tileSize[1]);
context.drawImage(image, 0, 0);
this.zoomifyImage_ = context.canvas;
return context.canvas;
@@ -197,7 +208,6 @@ ol.source.Zoomify.Tile_.prototype.getImage = function() {
}
};
/**
* @enum {string}
* @private