merged with upstream and improved key handling

This commit is contained in:
Dmitry Fedorov
2018-11-02 17:19:10 -07:00
252 changed files with 5980 additions and 3750 deletions

View File

@@ -11,8 +11,8 @@ import {getKeyZXY} from '../tilecoord.js';
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize]
* @property {import("../extent.js").Extent} [extent]
* @property {boolean} [opaque]
* @property {import("../proj.js").ProjectionLike} [projection]
* @property {import("./State.js").default} [state]
@@ -24,6 +24,7 @@ import {getKeyZXY} from '../tilecoord.js';
* @property {Array<string>} [urls]
* @property {boolean} [wrapX=true]
* @property {number} [transition]
* @property {string} [key]
*/
@@ -31,27 +32,34 @@ import {getKeyZXY} from '../tilecoord.js';
* @classdesc
* Base class for sources providing tiles divided into a tile grid over http.
*
* @fires import("./TileEvent.js").default
* @fires import("./Tile.js").TileSourceEvent
*/
class UrlTile extends TileSource {
/**
* @param {Options=} options Image tile options.
* @param {Options} options Image tile options.
*/
constructor(options) {
super({
attributions: options.attributions,
cacheSize: options.cacheSize,
extent: options.extent,
opaque: options.opaque,
projection: options.projection,
state: options.state,
tileGrid: options.tileGrid,
tilePixelRatio: options.tilePixelRatio,
wrapX: options.wrapX,
transition: options.transition
transition: options.transition,
key: options.key,
attributionsCollapsible: options.attributionsCollapsible
});
/**
* @private
* @type {boolean}
*/
this.generateTileUrlFunction_ = !options.tileUrlFunction;
/**
* @protected
* @type {import("../Tile.js").LoadFunction}
@@ -62,9 +70,7 @@ class UrlTile extends TileSource {
* @protected
* @type {import("../Tile.js").UrlFunction}
*/
this.tileUrlFunction = this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) : nullTileUrlFunction;
this.key_ = options.opt_key || this.key_;
this.tileUrlFunction = options.tileUrlFunction ? options.tileUrlFunction.bind(this) : nullTileUrlFunction;
/**
* @protected
@@ -77,13 +83,14 @@ class UrlTile extends TileSource {
} else if (options.url) {
this.setUrl(options.url);
}
if (options.tileUrlFunction) {
this.setTileUrlFunction(options.tileUrlFunction, options.opt_key);
this.setTileUrlFunction(options.tileUrlFunction, this.key_);
}
/**
* @private
* @type {!Object<number, boolean>}
* @type {!Object<string, boolean>}
*/
this.tileLoadingKeys_ = {};
@@ -156,14 +163,14 @@ class UrlTile extends TileSource {
/**
* Set the tile URL function of the source.
* @param {import("../Tile.js").UrlFunction} tileUrlFunction Tile URL function.
* @param {string=} opt_key Optional new tile key for the source.
* @param {string=} key Optional new tile key for the source.
* @api
*/
setTileUrlFunction(tileUrlFunction, opt_key) {
setTileUrlFunction(tileUrlFunction, key) {
this.tileUrlFunction = tileUrlFunction;
this.tileCache.pruneExceptNewestZ();
if (typeof opt_key !== 'undefined') {
this.setKey(opt_key);
if (typeof key !== 'undefined') {
this.setKey(key);
} else {
this.changed();
}
@@ -176,9 +183,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);
}
/**
@@ -189,9 +194,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);
}
}
/**
@@ -206,10 +213,4 @@ class UrlTile extends TileSource {
}
/**
* @type {import("../Tile.js").UrlFunction|undefined}
* @protected
*/
UrlTile.prototype.fixedTileUrlFunction;
export default UrlTile;