Merge remote-tracking branch 'openlayers/master' into vector-api
This commit is contained in:
@@ -22,6 +22,9 @@ goog.require('ol.tilegrid.TileGrid');
|
||||
* logo: (string|undefined),
|
||||
* opaque: (boolean|undefined),
|
||||
* projection: ol.proj.ProjectionLike,
|
||||
* tileClass: (function(new: ol.ImageTile, ol.TileCoord,
|
||||
* ol.TileState, string, ?string,
|
||||
* ol.TileLoadFunctionType)|undefined),
|
||||
* tileGrid: (ol.tilegrid.TileGrid|undefined),
|
||||
* tileLoadFunction: (ol.TileLoadFunctionType|undefined),
|
||||
* tileUrlFunction: (ol.TileUrlFunctionType|undefined)}}
|
||||
@@ -57,25 +60,33 @@ ol.source.TileImage = function(options) {
|
||||
ol.TileUrlFunction.nullTileUrlFunction;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @protected
|
||||
* @type {?string}
|
||||
*/
|
||||
this.crossOrigin_ =
|
||||
this.crossOrigin =
|
||||
goog.isDef(options.crossOrigin) ? options.crossOrigin : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @protected
|
||||
* @type {ol.TileCache}
|
||||
*/
|
||||
this.tileCache_ = new ol.TileCache();
|
||||
this.tileCache = new ol.TileCache();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @protected
|
||||
* @type {ol.TileLoadFunctionType}
|
||||
*/
|
||||
this.tileLoadFunction_ = goog.isDef(options.tileLoadFunction) ?
|
||||
this.tileLoadFunction = goog.isDef(options.tileLoadFunction) ?
|
||||
options.tileLoadFunction : ol.source.TileImage.defaultTileLoadFunction;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {function(new: ol.ImageTile, ol.TileCoord, ol.TileState, string,
|
||||
* ?string, ol.TileLoadFunctionType)}
|
||||
*/
|
||||
this.tileClass = goog.isDef(options.tileClass) ?
|
||||
options.tileClass : ol.ImageTile;
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.TileImage, ol.source.Tile);
|
||||
|
||||
@@ -93,7 +104,7 @@ ol.source.TileImage.defaultTileLoadFunction = function(imageTile, src) {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileImage.prototype.canExpireCache = function() {
|
||||
return this.tileCache_.canExpireCache();
|
||||
return this.tileCache.canExpireCache();
|
||||
};
|
||||
|
||||
|
||||
@@ -101,7 +112,7 @@ ol.source.TileImage.prototype.canExpireCache = function() {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileImage.prototype.expireCache = function(usedTiles) {
|
||||
this.tileCache_.expireCache(usedTiles);
|
||||
this.tileCache.expireCache(usedTiles);
|
||||
};
|
||||
|
||||
|
||||
@@ -110,19 +121,19 @@ ol.source.TileImage.prototype.expireCache = function(usedTiles) {
|
||||
*/
|
||||
ol.source.TileImage.prototype.getTile = function(z, x, y, projection) {
|
||||
var tileCoordKey = this.getKeyZXY(z, x, y);
|
||||
if (this.tileCache_.containsKey(tileCoordKey)) {
|
||||
return /** @type {!ol.Tile} */ (this.tileCache_.get(tileCoordKey));
|
||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
|
||||
} else {
|
||||
goog.asserts.assert(projection);
|
||||
var tileCoord = new ol.TileCoord(z, x, y);
|
||||
var tileUrl = this.tileUrlFunction(tileCoord, projection);
|
||||
var tile = new ol.ImageTile(
|
||||
var tile = new this.tileClass(
|
||||
tileCoord,
|
||||
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,
|
||||
goog.isDef(tileUrl) ? tileUrl : '',
|
||||
this.crossOrigin_,
|
||||
this.tileLoadFunction_);
|
||||
this.tileCache_.set(tileCoordKey, tile);
|
||||
this.crossOrigin,
|
||||
this.tileLoadFunction);
|
||||
this.tileCache.set(tileCoordKey, tile);
|
||||
return tile;
|
||||
}
|
||||
};
|
||||
@@ -135,7 +146,7 @@ ol.source.TileImage.prototype.setTileUrlFunction = function(tileUrlFunction) {
|
||||
// FIXME It should be possible to be more intelligent and avoid clearing the
|
||||
// FIXME cache. The tile URL function would need to be incorporated into the
|
||||
// FIXME cache key somehow.
|
||||
this.tileCache_.clear();
|
||||
this.tileCache.clear();
|
||||
this.tileUrlFunction = tileUrlFunction;
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
@@ -146,7 +157,7 @@ ol.source.TileImage.prototype.setTileUrlFunction = function(tileUrlFunction) {
|
||||
*/
|
||||
ol.source.TileImage.prototype.useTile = function(z, x, y) {
|
||||
var tileCoordKey = this.getKeyZXY(z, x, y);
|
||||
if (this.tileCache_.containsKey(tileCoordKey)) {
|
||||
this.tileCache_.get(tileCoordKey);
|
||||
if (this.tileCache.containsKey(tileCoordKey)) {
|
||||
this.tileCache.get(tileCoordKey);
|
||||
}
|
||||
};
|
||||
|
||||
1
src/ol/source/zoomifysource.exports
Normal file
1
src/ol/source/zoomifysource.exports
Normal file
@@ -0,0 +1 @@
|
||||
@exportSymbol ol.source.Zoomify
|
||||
149
src/ol/source/zoomifysource.js
Normal file
149
src/ol/source/zoomifysource.js
Normal file
@@ -0,0 +1,149 @@
|
||||
goog.provide('ol.source.Zoomify');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('ol.ImageTile');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.TileState');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.TileImage');
|
||||
goog.require('ol.tilegrid.Zoomify');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.source.TileImage}
|
||||
* @param {olx.source.ZoomifyOptions=} opt_options Options.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.source.Zoomify = function(opt_options) {
|
||||
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
|
||||
var size = options.size;
|
||||
var imageWidth = size[0];
|
||||
var imageHeight = size[1];
|
||||
|
||||
var tierSizeInTiles = [];
|
||||
var tileSize = ol.DEFAULT_TILE_SIZE;
|
||||
while (imageWidth > tileSize || imageHeight > tileSize) {
|
||||
tierSizeInTiles.push([
|
||||
Math.ceil(imageWidth / tileSize),
|
||||
Math.ceil(imageHeight / tileSize)
|
||||
]);
|
||||
tileSize += tileSize;
|
||||
}
|
||||
tierSizeInTiles.push([1, 1]);
|
||||
tierSizeInTiles.reverse();
|
||||
|
||||
var resolutions = [1];
|
||||
var tileCountUpToTier = [0];
|
||||
var i, ii;
|
||||
for (i = 1, ii = tierSizeInTiles.length; i < ii; i++) {
|
||||
resolutions.push(1 << i);
|
||||
tileCountUpToTier.push(
|
||||
tierSizeInTiles[i - 1][0] * tierSizeInTiles[i - 1][1] +
|
||||
tileCountUpToTier[i - 1]
|
||||
);
|
||||
}
|
||||
resolutions.reverse();
|
||||
|
||||
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]]}),
|
||||
/**
|
||||
* @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,
|
||||
crossOrigin: options.crossOrigin,
|
||||
logo: options.logo,
|
||||
tileClass: ol.source.ZoomifyTile_,
|
||||
tileGrid: tileGrid,
|
||||
tileUrlFunction: tileUrlFunction
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.Zoomify, ol.source.TileImage);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.ImageTile}
|
||||
* @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.
|
||||
* @private
|
||||
*/
|
||||
ol.source.ZoomifyTile_ = function(
|
||||
tileCoord, state, src, crossOrigin, tileLoadFunction) {
|
||||
|
||||
goog.base(this, tileCoord, state, src, crossOrigin, tileLoadFunction);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string,
|
||||
* HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>}
|
||||
*/
|
||||
this.zoomifyImageByContext_ = {};
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.ZoomifyTile_, ol.ImageTile);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.ZoomifyTile_.prototype.getImage = function(opt_context) {
|
||||
var key = goog.isDef(opt_context) ? goog.getUid(opt_context).toString() : '';
|
||||
if (key in this.zoomifyImageByContext_) {
|
||||
return this.zoomifyImageByContext_[key];
|
||||
} else {
|
||||
var image = goog.base(this, 'getImage', opt_context);
|
||||
if (this.state == ol.TileState.LOADED) {
|
||||
if (image.width == ol.DEFAULT_TILE_SIZE &&
|
||||
image.height == ol.DEFAULT_TILE_SIZE) {
|
||||
this.zoomifyImageByContext_[key] = image;
|
||||
return image;
|
||||
} else {
|
||||
var canvas = /** @type {HTMLCanvasElement} */
|
||||
(goog.dom.createElement(goog.dom.TagName.CANVAS));
|
||||
canvas.width = ol.DEFAULT_TILE_SIZE;
|
||||
canvas.height = ol.DEFAULT_TILE_SIZE;
|
||||
var context = /** @type {CanvasRenderingContext2D} */
|
||||
(canvas.getContext('2d'));
|
||||
context.drawImage(image, 0, 0);
|
||||
this.zoomifyImageByContext_[key] = canvas;
|
||||
return canvas;
|
||||
}
|
||||
} else {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user