Manual class transform

This commit is contained in:
Tim Schaub
2018-07-16 17:09:50 -06:00
parent 7b4a73f3b9
commit f78d0d4cfa
96 changed files with 8112 additions and 7964 deletions

View File

@@ -22,115 +22,115 @@ import PriorityQueue from './structs/PriorityQueue.js';
* Function called on each tile change event.
* @struct
*/
const TileQueue = function(tilePriorityFunction, tileChangeCallback) {
class TileQueue {
constructor(tilePriorityFunction, tileChangeCallback) {
PriorityQueue.call(
this,
/**
* @param {Array} element Element.
* @return {number} Priority.
*/
function(element) {
return tilePriorityFunction.apply(null, element);
},
/**
* @param {Array} element Element.
* @return {string} Key.
*/
function(element) {
return (/** @type {module:ol/Tile} */ (element[0]).getKey());
});
PriorityQueue.call(
this,
/**
* @param {Array} element Element.
* @return {number} Priority.
* @private
* @type {function(): ?}
*/
function(element) {
return tilePriorityFunction.apply(null, element);
},
this.tileChangeCallback_ = tileChangeCallback;
/**
* @param {Array} element Element.
* @return {string} Key.
* @private
* @type {number}
*/
function(element) {
return (/** @type {module:ol/Tile} */ (element[0]).getKey());
});
this.tilesLoading_ = 0;
/**
* @private
* @type {!Object.<string,boolean>}
*/
this.tilesLoadingKeys_ = {};
}
/**
* @private
* @type {function(): ?}
* @inheritDoc
*/
this.tileChangeCallback_ = tileChangeCallback;
enqueue(element) {
const added = PriorityQueue.prototype.enqueue.call(this, element);
if (added) {
const tile = element[0];
listen(tile, EventType.CHANGE, this.handleTileChange, this);
}
return added;
}
/**
* @private
* @type {number}
* @return {number} Number of tiles loading.
*/
this.tilesLoading_ = 0;
getTilesLoading() {
return this.tilesLoading_;
}
/**
* @private
* @type {!Object.<string,boolean>}
* @param {module:ol/events/Event} event Event.
* @protected
*/
this.tilesLoadingKeys_ = {};
handleTileChange(event) {
const tile = /** @type {module:ol/Tile} */ (event.target);
const state = tile.getState();
if (state === TileState.LOADED || state === TileState.ERROR ||
state === TileState.EMPTY || state === TileState.ABORT) {
unlisten(tile, EventType.CHANGE, this.handleTileChange, this);
const tileKey = tile.getKey();
if (tileKey in this.tilesLoadingKeys_) {
delete this.tilesLoadingKeys_[tileKey];
--this.tilesLoading_;
}
this.tileChangeCallback_();
}
}
};
/**
* @param {number} maxTotalLoading Maximum number tiles to load simultaneously.
* @param {number} maxNewLoads Maximum number of new tiles to load.
*/
loadMoreTiles(maxTotalLoading, maxNewLoads) {
let newLoads = 0;
let abortedTiles = false;
let state, tile, tileKey;
while (this.tilesLoading_ < maxTotalLoading && newLoads < maxNewLoads &&
this.getCount() > 0) {
tile = /** @type {module:ol/Tile} */ (this.dequeue()[0]);
tileKey = tile.getKey();
state = tile.getState();
if (state === TileState.ABORT) {
abortedTiles = true;
} else if (state === TileState.IDLE && !(tileKey in this.tilesLoadingKeys_)) {
this.tilesLoadingKeys_[tileKey] = true;
++this.tilesLoading_;
++newLoads;
tile.load();
}
}
if (newLoads === 0 && abortedTiles) {
// Do not stop the render loop when all wanted tiles were aborted due to
// a small, saturated tile cache.
this.tileChangeCallback_();
}
}
}
inherits(TileQueue, PriorityQueue);
/**
* @inheritDoc
*/
TileQueue.prototype.enqueue = function(element) {
const added = PriorityQueue.prototype.enqueue.call(this, element);
if (added) {
const tile = element[0];
listen(tile, EventType.CHANGE, this.handleTileChange, this);
}
return added;
};
/**
* @return {number} Number of tiles loading.
*/
TileQueue.prototype.getTilesLoading = function() {
return this.tilesLoading_;
};
/**
* @param {module:ol/events/Event} event Event.
* @protected
*/
TileQueue.prototype.handleTileChange = function(event) {
const tile = /** @type {module:ol/Tile} */ (event.target);
const state = tile.getState();
if (state === TileState.LOADED || state === TileState.ERROR ||
state === TileState.EMPTY || state === TileState.ABORT) {
unlisten(tile, EventType.CHANGE, this.handleTileChange, this);
const tileKey = tile.getKey();
if (tileKey in this.tilesLoadingKeys_) {
delete this.tilesLoadingKeys_[tileKey];
--this.tilesLoading_;
}
this.tileChangeCallback_();
}
};
/**
* @param {number} maxTotalLoading Maximum number tiles to load simultaneously.
* @param {number} maxNewLoads Maximum number of new tiles to load.
*/
TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) {
let newLoads = 0;
let abortedTiles = false;
let state, tile, tileKey;
while (this.tilesLoading_ < maxTotalLoading && newLoads < maxNewLoads &&
this.getCount() > 0) {
tile = /** @type {module:ol/Tile} */ (this.dequeue()[0]);
tileKey = tile.getKey();
state = tile.getState();
if (state === TileState.ABORT) {
abortedTiles = true;
} else if (state === TileState.IDLE && !(tileKey in this.tilesLoadingKeys_)) {
this.tilesLoadingKeys_[tileKey] = true;
++this.tilesLoading_;
++newLoads;
tile.load();
}
}
if (newLoads === 0 && abortedTiles) {
// Do not stop the render loop when all wanted tiles were aborted due to
// a small, saturated tile cache.
this.tileChangeCallback_();
}
};
export default TileQueue;