Manual class transform
This commit is contained in:
@@ -34,23 +34,28 @@ const TierSizeCalculation = {
|
||||
* @param {module:ol/Tile~LoadFunction} tileLoadFunction Tile load function.
|
||||
* @param {module:ol/Tile~Options=} opt_options Tile options.
|
||||
*/
|
||||
export const CustomTile = function(
|
||||
tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
|
||||
export class CustomTile {
|
||||
|
||||
ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
|
||||
constructor(tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
|
||||
*/
|
||||
this.zoomifyImage_ = null;
|
||||
ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
|
||||
*/
|
||||
this.zoomifyImage_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/size~Size}
|
||||
*/
|
||||
this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0]));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/size~Size}
|
||||
*/
|
||||
this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0]));
|
||||
};
|
||||
inherits(CustomTile, ImageTile);
|
||||
|
||||
|
||||
@@ -124,135 +129,138 @@ CustomTile.prototype.getImage = function() {
|
||||
* @param {module:ol/source/Zoomify~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const Zoomify = function(opt_options) {
|
||||
class Zoomify {
|
||||
|
||||
const options = opt_options || {};
|
||||
constructor(opt_options) {
|
||||
|
||||
const size = options.size;
|
||||
const tierSizeCalculation = options.tierSizeCalculation !== undefined ?
|
||||
options.tierSizeCalculation :
|
||||
TierSizeCalculation.DEFAULT;
|
||||
const options = opt_options || {};
|
||||
|
||||
const imageWidth = size[0];
|
||||
const imageHeight = size[1];
|
||||
const extent = options.extent || [0, -size[1], size[0], 0];
|
||||
const tierSizeInTiles = [];
|
||||
const tileSize = options.tileSize || DEFAULT_TILE_SIZE;
|
||||
let tileSizeForTierSizeCalculation = tileSize;
|
||||
const size = options.size;
|
||||
const tierSizeCalculation = options.tierSizeCalculation !== undefined ?
|
||||
options.tierSizeCalculation :
|
||||
TierSizeCalculation.DEFAULT;
|
||||
|
||||
switch (tierSizeCalculation) {
|
||||
case TierSizeCalculation.DEFAULT:
|
||||
while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) {
|
||||
tierSizeInTiles.push([
|
||||
Math.ceil(imageWidth / tileSizeForTierSizeCalculation),
|
||||
Math.ceil(imageHeight / tileSizeForTierSizeCalculation)
|
||||
]);
|
||||
tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation;
|
||||
}
|
||||
break;
|
||||
case TierSizeCalculation.TRUNCATED:
|
||||
let width = imageWidth;
|
||||
let height = imageHeight;
|
||||
while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) {
|
||||
tierSizeInTiles.push([
|
||||
Math.ceil(width / tileSizeForTierSizeCalculation),
|
||||
Math.ceil(height / tileSizeForTierSizeCalculation)
|
||||
]);
|
||||
width >>= 1;
|
||||
height >>= 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(false, 53); // Unknown `tierSizeCalculation` configured
|
||||
break;
|
||||
}
|
||||
const imageWidth = size[0];
|
||||
const imageHeight = size[1];
|
||||
const extent = options.extent || [0, -size[1], size[0], 0];
|
||||
const tierSizeInTiles = [];
|
||||
const tileSize = options.tileSize || DEFAULT_TILE_SIZE;
|
||||
let tileSizeForTierSizeCalculation = tileSize;
|
||||
|
||||
tierSizeInTiles.push([1, 1]);
|
||||
tierSizeInTiles.reverse();
|
||||
|
||||
const resolutions = [1];
|
||||
const tileCountUpToTier = [0];
|
||||
for (let 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();
|
||||
|
||||
const tileGrid = new TileGrid({
|
||||
tileSize: tileSize,
|
||||
extent: extent,
|
||||
origin: getTopLeft(extent),
|
||||
resolutions: resolutions
|
||||
});
|
||||
|
||||
let url = options.url;
|
||||
if (url && url.indexOf('{TileGroup}') == -1 && url.indexOf('{tileIndex}') == -1) {
|
||||
url += '{TileGroup}/{z}-{x}-{y}.jpg';
|
||||
}
|
||||
const urls = expandUrl(url);
|
||||
|
||||
/**
|
||||
* @param {string} template Template.
|
||||
* @return {module:ol/Tile~UrlFunction} Tile URL function.
|
||||
*/
|
||||
function createFromTemplate(template) {
|
||||
|
||||
return (
|
||||
/**
|
||||
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile Coordinate.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {module:ol/proj/Projection} projection Projection.
|
||||
* @return {string|undefined} Tile URL.
|
||||
*/
|
||||
function(tileCoord, pixelRatio, projection) {
|
||||
if (!tileCoord) {
|
||||
return undefined;
|
||||
} else {
|
||||
const tileCoordZ = tileCoord[0];
|
||||
const tileCoordX = tileCoord[1];
|
||||
const tileCoordY = -tileCoord[2] - 1;
|
||||
const tileIndex =
|
||||
tileCoordX +
|
||||
tileCoordY * tierSizeInTiles[tileCoordZ][0];
|
||||
const tileSize = tileGrid.getTileSize(tileCoordZ);
|
||||
const tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / tileSize) | 0;
|
||||
const localContext = {
|
||||
'z': tileCoordZ,
|
||||
'x': tileCoordX,
|
||||
'y': tileCoordY,
|
||||
'tileIndex': tileIndex,
|
||||
'TileGroup': 'TileGroup' + tileGroup
|
||||
};
|
||||
return template.replace(/\{(\w+?)\}/g, function(m, p) {
|
||||
return localContext[p];
|
||||
});
|
||||
switch (tierSizeCalculation) {
|
||||
case TierSizeCalculation.DEFAULT:
|
||||
while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) {
|
||||
tierSizeInTiles.push([
|
||||
Math.ceil(imageWidth / tileSizeForTierSizeCalculation),
|
||||
Math.ceil(imageHeight / tileSizeForTierSizeCalculation)
|
||||
]);
|
||||
tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation;
|
||||
}
|
||||
}
|
||||
);
|
||||
break;
|
||||
case TierSizeCalculation.TRUNCATED:
|
||||
let width = imageWidth;
|
||||
let height = imageHeight;
|
||||
while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) {
|
||||
tierSizeInTiles.push([
|
||||
Math.ceil(width / tileSizeForTierSizeCalculation),
|
||||
Math.ceil(height / tileSizeForTierSizeCalculation)
|
||||
]);
|
||||
width >>= 1;
|
||||
height >>= 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(false, 53); // Unknown `tierSizeCalculation` configured
|
||||
break;
|
||||
}
|
||||
|
||||
tierSizeInTiles.push([1, 1]);
|
||||
tierSizeInTiles.reverse();
|
||||
|
||||
const resolutions = [1];
|
||||
const tileCountUpToTier = [0];
|
||||
for (let 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();
|
||||
|
||||
const tileGrid = new TileGrid({
|
||||
tileSize: tileSize,
|
||||
extent: extent,
|
||||
origin: getTopLeft(extent),
|
||||
resolutions: resolutions
|
||||
});
|
||||
|
||||
let url = options.url;
|
||||
if (url && url.indexOf('{TileGroup}') == -1 && url.indexOf('{tileIndex}') == -1) {
|
||||
url += '{TileGroup}/{z}-{x}-{y}.jpg';
|
||||
}
|
||||
const urls = expandUrl(url);
|
||||
|
||||
/**
|
||||
* @param {string} template Template.
|
||||
* @return {module:ol/Tile~UrlFunction} Tile URL function.
|
||||
*/
|
||||
function createFromTemplate(template) {
|
||||
|
||||
return (
|
||||
/**
|
||||
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile Coordinate.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {module:ol/proj/Projection} projection Projection.
|
||||
* @return {string|undefined} Tile URL.
|
||||
*/
|
||||
function(tileCoord, pixelRatio, projection) {
|
||||
if (!tileCoord) {
|
||||
return undefined;
|
||||
} else {
|
||||
const tileCoordZ = tileCoord[0];
|
||||
const tileCoordX = tileCoord[1];
|
||||
const tileCoordY = -tileCoord[2] - 1;
|
||||
const tileIndex =
|
||||
tileCoordX +
|
||||
tileCoordY * tierSizeInTiles[tileCoordZ][0];
|
||||
const tileSize = tileGrid.getTileSize(tileCoordZ);
|
||||
const tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / tileSize) | 0;
|
||||
const localContext = {
|
||||
'z': tileCoordZ,
|
||||
'x': tileCoordX,
|
||||
'y': tileCoordY,
|
||||
'tileIndex': tileIndex,
|
||||
'TileGroup': 'TileGroup' + tileGroup
|
||||
};
|
||||
return template.replace(/\{(\w+?)\}/g, function(m, p) {
|
||||
return localContext[p];
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const tileUrlFunction = createFromTileUrlFunctions(urls.map(createFromTemplate));
|
||||
|
||||
const ZoomifyTileClass = CustomTile.bind(null, tileGrid);
|
||||
|
||||
TileImage.call(this, {
|
||||
attributions: options.attributions,
|
||||
cacheSize: options.cacheSize,
|
||||
crossOrigin: options.crossOrigin,
|
||||
projection: options.projection,
|
||||
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
||||
tileClass: ZoomifyTileClass,
|
||||
tileGrid: tileGrid,
|
||||
tileUrlFunction: tileUrlFunction,
|
||||
transition: options.transition
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
const tileUrlFunction = createFromTileUrlFunctions(urls.map(createFromTemplate));
|
||||
|
||||
const ZoomifyTileClass = CustomTile.bind(null, tileGrid);
|
||||
|
||||
TileImage.call(this, {
|
||||
attributions: options.attributions,
|
||||
cacheSize: options.cacheSize,
|
||||
crossOrigin: options.crossOrigin,
|
||||
projection: options.projection,
|
||||
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
||||
tileClass: ZoomifyTileClass,
|
||||
tileGrid: tileGrid,
|
||||
tileUrlFunction: tileUrlFunction,
|
||||
transition: options.transition
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
inherits(Zoomify, TileImage);
|
||||
|
||||
|
||||
export default Zoomify;
|
||||
|
||||
Reference in New Issue
Block a user