Simplify logic for fixed tile url functions

This commit is contained in:
ahocevar
2018-10-02 10:52:03 +02:00
parent 023ad3c531
commit 4aff3d0631
5 changed files with 106 additions and 102 deletions
+40 -35
View File
@@ -76,6 +76,7 @@ class TileArcGISRest extends TileImage {
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true,
@@ -169,41 +170,6 @@ class TileArcGISRest extends TileImage {
return /** @type {number} */ (pixelRatio);
}
/**
* @inheritDoc
*/
fixedTileUrlFunction(tileCoord, pixelRatio, projection) {
let tileGrid = this.getTileGrid();
if (!tileGrid) {
tileGrid = this.getTileGridForProjection(projection);
}
if (tileGrid.getResolutions().length <= tileCoord[0]) {
return undefined;
}
const tileExtent = tileGrid.getTileCoordExtent(
tileCoord, this.tmpExtent_);
let tileSize = toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
if (pixelRatio != 1) {
tileSize = scaleSize(tileSize, pixelRatio, this.tmpSize);
}
// Apply default params and override with user specified values.
const baseParams = {
'F': 'image',
'FORMAT': 'PNG32',
'TRANSPARENT': true
};
assign(baseParams, this.params_);
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
pixelRatio, projection, baseParams);
}
/**
* Update the user-provided params.
* @param {Object} params Params.
@@ -215,5 +181,44 @@ class TileArcGISRest extends TileImage {
}
}
/**
* @param {import("../tilecoord.js").TileCoord} tileCoord The tile coordinate
* @param {number} pixelRatio The pixel ratio
* @param {import("../proj/Projection.js").default} projection The projection
* @return {string|undefined} The tile URL
* @this {TileArcGISRest}
*/
function tileUrlFunction(tileCoord, pixelRatio, projection) {
let tileGrid = this.getTileGrid();
if (!tileGrid) {
tileGrid = this.getTileGridForProjection(projection);
}
if (tileGrid.getResolutions().length <= tileCoord[0]) {
return undefined;
}
const tileExtent = tileGrid.getTileCoordExtent(
tileCoord, this.tmpExtent_);
let tileSize = toSize(
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
if (pixelRatio != 1) {
tileSize = scaleSize(tileSize, pixelRatio, this.tmpSize);
}
// Apply default params and override with user specified values.
const baseParams = {
'F': 'image',
'FORMAT': 'PNG32',
'TRANSPARENT': true
};
assign(baseParams, this.params_);
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
pixelRatio, projection, baseParams);
}
export default TileArcGISRest;