Add support for custom tile size to Zoomify layer.

https://github.com/openlayers/openlayers/issues/6608
This commit is contained in:
Lasse Laakkonen
2017-10-19 15:38:00 +03:00
parent 0e9bd75bc6
commit e41693816a
4 changed files with 35 additions and 11 deletions

View File

@@ -7326,6 +7326,15 @@ olx.source.ZoomifyOptions.prototype.size;
olx.source.ZoomifyOptions.prototype.transition; olx.source.ZoomifyOptions.prototype.transition;
/**
* Tile size. Same tile size is used for all zoom levels. Default value is
* `OpenLayers.DEFAULT_TILE_SIZE`.
* @type {number|undefined}
* @api
*/
olx.source.ZoomifyOptions.prototype.tileSize;
/** /**
* Namespace. * Namespace.
* @type {Object} * @type {Object}

View File

@@ -19,6 +19,7 @@ goog.require('ol.events.EventType');
* @param {olx.TileOptions=} opt_options Tile options. * @param {olx.TileOptions=} opt_options Tile options.
*/ */
ol.ImageTile = function(tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) { ol.ImageTile = function(tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
var options = opt_options || {};
ol.Tile.call(this, tileCoord, state, opt_options); ol.Tile.call(this, tileCoord, state, opt_options);
@@ -51,6 +52,14 @@ ol.ImageTile = function(tileCoord, state, src, crossOrigin, tileLoadFunction, op
*/ */
this.tileLoadFunction_ = tileLoadFunction; this.tileLoadFunction_ = tileLoadFunction;
var tileCoordZ = tileCoord[0];
var tileGridTileSize = (options.tileGrid ? options.tileGrid.getTileSize(tileCoordZ) : undefined);
/**
* @protected
* @type {number}
*/
this.tileSize_ = tileGridTileSize || ol.DEFAULT_TILE_SIZE;
}; };
ol.inherits(ol.ImageTile, ol.Tile); ol.inherits(ol.ImageTile, ol.Tile);

View File

@@ -75,7 +75,10 @@ ol.source.Tile = function(options) {
* @protected * @protected
* @type {olx.TileOptions} * @type {olx.TileOptions}
*/ */
this.tileOptions = {transition: options.transition}; this.tileOptions = {
transition: options.transition,
tileGrid: this.tileGrid
};
}; };
ol.inherits(ol.source.Tile, ol.source.Source); ol.inherits(ol.source.Tile, ol.source.Source);

View File

@@ -33,25 +33,26 @@ ol.source.Zoomify = function(opt_options) {
var imageWidth = size[0]; var imageWidth = size[0];
var imageHeight = size[1]; var imageHeight = size[1];
var tierSizeInTiles = []; var tierSizeInTiles = [];
var tileSize = ol.DEFAULT_TILE_SIZE; var tileSize = options.tileSize || ol.DEFAULT_TILE_SIZE;
var tileSizeForTierSizeCalculation = tileSize;
switch (tierSizeCalculation) { switch (tierSizeCalculation) {
case ol.source.Zoomify.TierSizeCalculation_.DEFAULT: case ol.source.Zoomify.TierSizeCalculation_.DEFAULT:
while (imageWidth > tileSize || imageHeight > tileSize) { while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([ tierSizeInTiles.push([
Math.ceil(imageWidth / tileSize), Math.ceil(imageWidth / tileSizeForTierSizeCalculation),
Math.ceil(imageHeight / tileSize) Math.ceil(imageHeight / tileSizeForTierSizeCalculation)
]); ]);
tileSize += tileSize; tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation;
} }
break; break;
case ol.source.Zoomify.TierSizeCalculation_.TRUNCATED: case ol.source.Zoomify.TierSizeCalculation_.TRUNCATED:
var width = imageWidth; var width = imageWidth;
var height = imageHeight; var height = imageHeight;
while (width > tileSize || height > tileSize) { while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([ tierSizeInTiles.push([
Math.ceil(width / tileSize), Math.ceil(width / tileSizeForTierSizeCalculation),
Math.ceil(height / tileSize) Math.ceil(height / tileSizeForTierSizeCalculation)
]); ]);
width >>= 1; width >>= 1;
height >>= 1; height >>= 1;
@@ -79,6 +80,7 @@ ol.source.Zoomify = function(opt_options) {
var extent = [0, -size[1], size[0], 0]; var extent = [0, -size[1], size[0], 0];
var tileGrid = new ol.tilegrid.TileGrid({ var tileGrid = new ol.tilegrid.TileGrid({
tileSize: tileSize,
extent: extent, extent: extent,
origin: ol.extent.getTopLeft(extent), origin: ol.extent.getTopLeft(extent),
resolutions: resolutions resolutions: resolutions
@@ -113,7 +115,8 @@ ol.source.Zoomify = function(opt_options) {
var tileIndex = var tileIndex =
tileCoordX + tileCoordX +
tileCoordY * tierSizeInTiles[tileCoordZ][0]; 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 = { var localContext = {
'z': tileCoordZ, 'z': tileCoordZ,
'x': tileCoordX, 'x': tileCoordX,
@@ -180,7 +183,7 @@ ol.source.Zoomify.Tile_.prototype.getImage = function() {
if (this.zoomifyImage_) { if (this.zoomifyImage_) {
return this.zoomifyImage_; return this.zoomifyImage_;
} }
var tileSize = ol.DEFAULT_TILE_SIZE; var tileSize = this.tileSize_;
var image = ol.ImageTile.prototype.getImage.call(this); var image = ol.ImageTile.prototype.getImage.call(this);
if (this.state == ol.TileState.LOADED) { if (this.state == ol.TileState.LOADED) {
if (image.width == tileSize && image.height == tileSize) { if (image.width == tileSize && image.height == tileSize) {