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:
+11
-1
@@ -7233,7 +7233,8 @@ olx.source.CartoDBOptions.prototype.account;
|
|||||||
* url: !string,
|
* url: !string,
|
||||||
* tierSizeCalculation: (string|undefined),
|
* tierSizeCalculation: (string|undefined),
|
||||||
* size: ol.Size,
|
* size: ol.Size,
|
||||||
* transition: (number|undefined)}}
|
* transition: (number|undefined),
|
||||||
|
* tileSize: (number|undefined)}}
|
||||||
*/
|
*/
|
||||||
olx.source.ZoomifyOptions;
|
olx.source.ZoomifyOptions;
|
||||||
|
|
||||||
@@ -7333,6 +7334,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}
|
||||||
|
|||||||
+26
-16
@@ -7,6 +7,7 @@ goog.require('ol.TileUrlFunction');
|
|||||||
goog.require('ol.asserts');
|
goog.require('ol.asserts');
|
||||||
goog.require('ol.dom');
|
goog.require('ol.dom');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
|
goog.require('ol.size');
|
||||||
goog.require('ol.source.TileImage');
|
goog.require('ol.source.TileImage');
|
||||||
goog.require('ol.tilegrid.TileGrid');
|
goog.require('ol.tilegrid.TileGrid');
|
||||||
|
|
||||||
@@ -33,25 +34,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 +81,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 +116,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,
|
||||||
@@ -130,6 +134,8 @@ ol.source.Zoomify = function(opt_options) {
|
|||||||
|
|
||||||
var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate));
|
var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate));
|
||||||
|
|
||||||
|
var ZoomifyTileClass = ol.source.Zoomify.Tile_.bind(null, tileGrid);
|
||||||
|
|
||||||
ol.source.TileImage.call(this, {
|
ol.source.TileImage.call(this, {
|
||||||
attributions: options.attributions,
|
attributions: options.attributions,
|
||||||
cacheSize: options.cacheSize,
|
cacheSize: options.cacheSize,
|
||||||
@@ -137,7 +143,7 @@ ol.source.Zoomify = function(opt_options) {
|
|||||||
logo: options.logo,
|
logo: options.logo,
|
||||||
projection: options.projection,
|
projection: options.projection,
|
||||||
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
||||||
tileClass: ol.source.Zoomify.Tile_,
|
tileClass: ZoomifyTileClass,
|
||||||
tileGrid: tileGrid,
|
tileGrid: tileGrid,
|
||||||
tileUrlFunction: tileUrlFunction,
|
tileUrlFunction: tileUrlFunction,
|
||||||
transition: options.transition
|
transition: options.transition
|
||||||
@@ -146,10 +152,10 @@ ol.source.Zoomify = function(opt_options) {
|
|||||||
};
|
};
|
||||||
ol.inherits(ol.source.Zoomify, ol.source.TileImage);
|
ol.inherits(ol.source.Zoomify, ol.source.TileImage);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.ImageTile}
|
* @extends {ol.ImageTile}
|
||||||
|
* @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to.
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
* @param {ol.TileState} state State.
|
* @param {ol.TileState} state State.
|
||||||
* @param {string} src Image source URI.
|
* @param {string} src Image source URI.
|
||||||
@@ -159,7 +165,7 @@ ol.inherits(ol.source.Zoomify, ol.source.TileImage);
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.source.Zoomify.Tile_ = function(
|
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);
|
ol.ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
|
||||||
|
|
||||||
@@ -169,6 +175,11 @@ ol.source.Zoomify.Tile_ = function(
|
|||||||
*/
|
*/
|
||||||
this.zoomifyImage_ = null;
|
this.zoomifyImage_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Size}
|
||||||
|
*/
|
||||||
|
this.tileSize_ = ol.size.toSize(tileGrid.getTileSize(tileCoord[0]));
|
||||||
};
|
};
|
||||||
ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile);
|
ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile);
|
||||||
|
|
||||||
@@ -180,14 +191,14 @@ 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 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) {
|
var tileSize = this.tileSize_;
|
||||||
|
if (image.width == tileSize[0] && image.height == tileSize[1]) {
|
||||||
this.zoomifyImage_ = image;
|
this.zoomifyImage_ = image;
|
||||||
return image;
|
return image;
|
||||||
} else {
|
} else {
|
||||||
var context = ol.dom.createCanvasContext2D(tileSize, tileSize);
|
var context = ol.dom.createCanvasContext2D(tileSize[0], tileSize[1]);
|
||||||
context.drawImage(image, 0, 0);
|
context.drawImage(image, 0, 0);
|
||||||
this.zoomifyImage_ = context.canvas;
|
this.zoomifyImage_ = context.canvas;
|
||||||
return context.canvas;
|
return context.canvas;
|
||||||
@@ -197,7 +208,6 @@ ol.source.Zoomify.Tile_.prototype.getImage = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
goog.require('ol');
|
||||||
goog.require('ol.dom');
|
goog.require('ol.dom');
|
||||||
goog.require('ol.events');
|
goog.require('ol.events');
|
||||||
goog.require('ol.proj.Projection');
|
goog.require('ol.proj.Projection');
|
||||||
@@ -30,6 +31,13 @@ describe('ol.source.Zoomify', function() {
|
|||||||
size: size
|
size: size
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function getZoomifySourceWith1024pxTiles() {
|
||||||
|
return new ol.source.Zoomify({
|
||||||
|
url: zoomifyUrl,
|
||||||
|
size: size,
|
||||||
|
tileSize: 1024
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
|
|
||||||
@@ -148,6 +156,14 @@ describe('ol.source.Zoomify', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('has expected tileSize', function() {
|
||||||
|
var sources = [getZoomifySource(), getZoomifySourceWith1024pxTiles()];
|
||||||
|
var expectedTileSizes = [ol.DEFAULT_TILE_SIZE, 1024];
|
||||||
|
for (var i = 0; i < sources.length; i++) {
|
||||||
|
var tileGrid = sources[i].getTileGrid();
|
||||||
|
expect(tileGrid.getTileSize()).to.eql(expectedTileSizes[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tierSizeCalculation configuration', function() {
|
describe('tierSizeCalculation configuration', function() {
|
||||||
@@ -232,11 +248,6 @@ describe('ol.source.Zoomify', function() {
|
|||||||
|
|
||||||
describe('uses a custom tileClass', function() {
|
describe('uses a custom tileClass', function() {
|
||||||
|
|
||||||
it('uses "ol.source.Zoomify.Tile_" as tileClass', function() {
|
|
||||||
var source = getZoomifySource();
|
|
||||||
expect(source.tileClass).to.be(ol.source.Zoomify.Tile_);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns expected tileClass instances via "getTile"', function() {
|
it('returns expected tileClass instances via "getTile"', function() {
|
||||||
var source = getZoomifySource();
|
var source = getZoomifySource();
|
||||||
var tile = source.getTile(0, 0, -1, 1, proj);
|
var tile = source.getTile(0, 0, -1, 1, proj);
|
||||||
|
|||||||
Reference in New Issue
Block a user