Simplify logic for fixed tile url functions
This commit is contained in:
@@ -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,
|
||||
@@ -170,9 +171,24 @@ class TileArcGISRest extends TileImage {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Update the user-provided params.
|
||||
* @param {Object} params Params.
|
||||
* @api
|
||||
*/
|
||||
fixedTileUrlFunction(tileCoord, pixelRatio, projection) {
|
||||
updateParams(params) {
|
||||
assign(this.params_, params);
|
||||
this.setKey(this.getKeyForParams_());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
@@ -202,17 +218,6 @@ class TileArcGISRest extends TileImage {
|
||||
|
||||
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
|
||||
pixelRatio, projection, baseParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user-provided params.
|
||||
* @param {Object} params Params.
|
||||
* @api
|
||||
*/
|
||||
updateParams(params) {
|
||||
assign(this.params_, params);
|
||||
this.setKey(this.getKeyForParams_());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ class TileWMS extends TileImage {
|
||||
tileClass: options.tileClass,
|
||||
tileGrid: options.tileGrid,
|
||||
tileLoadFunction: options.tileLoadFunction,
|
||||
tileUrlFunction: tileUrlFunction,
|
||||
url: options.url,
|
||||
urls: options.urls,
|
||||
wrapX: options.wrapX !== undefined ? options.wrapX : true,
|
||||
@@ -322,9 +323,33 @@ class TileWMS extends TileImage {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Update the user-provided params.
|
||||
* @param {Object} params Params.
|
||||
* @api
|
||||
*/
|
||||
fixedTileUrlFunction(tileCoord, pixelRatio, projection) {
|
||||
updateParams(params) {
|
||||
assign(this.params_, params);
|
||||
this.updateV13_();
|
||||
this.setKey(this.getKeyForParams_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
updateV13_() {
|
||||
const version = this.params_['VERSION'] || DEFAULT_WMS_VERSION;
|
||||
this.v13_ = compareVersions(version, '1.3') >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 {TileWMS}
|
||||
*/
|
||||
function tileUrlFunction(tileCoord, pixelRatio, projection) {
|
||||
|
||||
let tileGrid = this.getTileGrid();
|
||||
if (!tileGrid) {
|
||||
@@ -365,26 +390,6 @@ class TileWMS extends TileImage {
|
||||
|
||||
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
|
||||
pixelRatio, projection, baseParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user-provided params.
|
||||
* @param {Object} params Params.
|
||||
* @api
|
||||
*/
|
||||
updateParams(params) {
|
||||
assign(this.params_, params);
|
||||
this.updateV13_();
|
||||
this.setKey(this.getKeyForParams_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
updateV13_() {
|
||||
const version = this.params_['VERSION'] || DEFAULT_WMS_VERSION;
|
||||
this.v13_ = compareVersions(version, '1.3') >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,6 +50,12 @@ class UrlTile extends TileSource {
|
||||
transition: options.transition
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.generateTileUrlFunction_ = !options.tileUrlFunction;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {import("../Tile.js").LoadFunction}
|
||||
@@ -60,8 +66,7 @@ class UrlTile extends TileSource {
|
||||
* @protected
|
||||
* @type {import("../Tile.js").UrlFunction}
|
||||
*/
|
||||
this.tileUrlFunction = this.fixedTileUrlFunction ?
|
||||
this.fixedTileUrlFunction.bind(this) : nullTileUrlFunction;
|
||||
this.tileUrlFunction = options.tileUrlFunction ? options.tileUrlFunction.bind(this) : nullTileUrlFunction;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
@@ -74,9 +79,6 @@ class UrlTile extends TileSource {
|
||||
} else if (options.url) {
|
||||
this.setUrl(options.url);
|
||||
}
|
||||
if (options.tileUrlFunction) {
|
||||
this.setTileUrlFunction(options.tileUrlFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -173,9 +175,7 @@ class UrlTile extends TileSource {
|
||||
*/
|
||||
setUrl(url) {
|
||||
const urls = this.urls = expandUrl(url);
|
||||
this.setTileUrlFunction(this.fixedTileUrlFunction ?
|
||||
this.fixedTileUrlFunction.bind(this) :
|
||||
createFromTemplates(urls, this.tileGrid), url);
|
||||
this.setUrls(urls);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,9 +186,11 @@ class UrlTile extends TileSource {
|
||||
setUrls(urls) {
|
||||
this.urls = urls;
|
||||
const key = urls.join('\n');
|
||||
this.setTileUrlFunction(this.fixedTileUrlFunction ?
|
||||
this.fixedTileUrlFunction.bind(this) :
|
||||
createFromTemplates(urls, this.tileGrid), key);
|
||||
if (this.generateTileUrlFunction_) {
|
||||
this.setTileUrlFunction(createFromTemplates(urls, this.tileGrid), key);
|
||||
} else {
|
||||
this.setKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,10 +205,4 @@ class UrlTile extends TileSource {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @type {import("../Tile.js").UrlFunction|undefined}
|
||||
* @protected
|
||||
*/
|
||||
UrlTile.prototype.fixedTileUrlFunction;
|
||||
|
||||
export default UrlTile;
|
||||
|
||||
@@ -159,9 +159,7 @@ class WMTS extends TileImage {
|
||||
setUrls(urls) {
|
||||
this.urls = urls;
|
||||
const key = urls.join('\n');
|
||||
this.setTileUrlFunction(this.fixedTileUrlFunction ?
|
||||
this.fixedTileUrlFunction.bind(this) :
|
||||
createFromTileUrlFunctions(urls.map(createFromWMTSTemplate.bind(this))), key);
|
||||
this.setTileUrlFunction(createFromTileUrlFunctions(urls.map(createFromWMTSTemplate.bind(this))), key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -310,7 +310,7 @@ describe('ol.source.TileWMS', function() {
|
||||
});
|
||||
|
||||
describe('#setUrls()', function() {
|
||||
it ('updates the source key', function() {
|
||||
it('updates the source key', function() {
|
||||
const source = new TileWMS({
|
||||
urls: ['u1', 'u2']
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user