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
+13 -17
View File
@@ -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;