Fix using multiple Zoomify sources at a time..
This commit is contained in:
+57
-58
@@ -11,62 +11,6 @@ goog.require('ol.source.TileImage');
|
|||||||
goog.require('ol.tilegrid.TileGrid');
|
goog.require('ol.tilegrid.TileGrid');
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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.
|
|
||||||
* @param {?string} crossOrigin Cross origin.
|
|
||||||
* @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
|
|
||||||
* @param {olx.TileOptions=} opt_options Tile options.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
var ZoomifyTileClass = function(
|
|
||||||
tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
|
|
||||||
|
|
||||||
ol.ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
|
|
||||||
*/
|
|
||||||
this.zoomifyImage_ = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {ol.Size|number}
|
|
||||||
*/
|
|
||||||
this.tileSize_ = tileGrid.getTileSize(tileCoord[0]);
|
|
||||||
};
|
|
||||||
ol.inherits(ZoomifyTileClass, ol.ImageTile);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ZoomifyTileClass.prototype.getImage = function() {
|
|
||||||
if (this.zoomifyImage_) {
|
|
||||||
return this.zoomifyImage_;
|
|
||||||
}
|
|
||||||
var tileSize = (Array.isArray(this.tileSize_) ? this.tileSize_[0] : this.tileSize_);
|
|
||||||
var image = ol.ImageTile.prototype.getImage.call(this);
|
|
||||||
if (this.state == ol.TileState.LOADED) {
|
|
||||||
if (image.width == tileSize && image.height == tileSize) {
|
|
||||||
this.zoomifyImage_ = image;
|
|
||||||
return image;
|
|
||||||
} else {
|
|
||||||
var context = ol.dom.createCanvasContext2D(tileSize, tileSize);
|
|
||||||
context.drawImage(image, 0, 0);
|
|
||||||
this.zoomifyImage_ = context.canvas;
|
|
||||||
return context.canvas;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
* Layer source for tile data in Zoomify format (both Zoomify and Internet
|
* Layer source for tile data in Zoomify format (both Zoomify and Internet
|
||||||
@@ -189,7 +133,7 @@ ol.source.Zoomify = function(opt_options) {
|
|||||||
|
|
||||||
var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate));
|
var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate));
|
||||||
|
|
||||||
ol.source.Zoomify.Tile_ = ZoomifyTileClass.bind(null, tileGrid);
|
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,
|
||||||
@@ -198,7 +142,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
|
||||||
@@ -207,6 +151,61 @@ ol.source.Zoomify = function(opt_options) {
|
|||||||
};
|
};
|
||||||
ol.inherits(ol.source.Zoomify, ol.source.TileImage);
|
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.
|
||||||
|
* @param {?string} crossOrigin Cross origin.
|
||||||
|
* @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
|
||||||
|
* @param {olx.TileOptions=} opt_options Tile options.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.source.Zoomify.Tile_ = function(
|
||||||
|
tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
|
||||||
|
|
||||||
|
ol.ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
|
||||||
|
*/
|
||||||
|
this.zoomifyImage_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Size|number}
|
||||||
|
*/
|
||||||
|
this.tileSize_ = tileGrid.getTileSize(tileCoord[0]);
|
||||||
|
};
|
||||||
|
ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.source.Zoomify.Tile_.prototype.getImage = function() {
|
||||||
|
if (this.zoomifyImage_) {
|
||||||
|
return this.zoomifyImage_;
|
||||||
|
}
|
||||||
|
var tileSize = (Array.isArray(this.tileSize_) ? this.tileSize_[0] : this.tileSize_);
|
||||||
|
var image = ol.ImageTile.prototype.getImage.call(this);
|
||||||
|
if (this.state == ol.TileState.LOADED) {
|
||||||
|
if (image.width == tileSize && image.height == tileSize) {
|
||||||
|
this.zoomifyImage_ = image;
|
||||||
|
return image;
|
||||||
|
} else {
|
||||||
|
var context = ol.dom.createCanvasContext2D(tileSize, tileSize);
|
||||||
|
context.drawImage(image, 0, 0);
|
||||||
|
this.zoomifyImage_ = context.canvas;
|
||||||
|
return context.canvas;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
|
|||||||
@@ -248,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