Use HTMLImageElement.decode if available

This commit is contained in:
Frederic Junod
2019-03-21 10:42:18 +01:00
parent 5a4541dadb
commit 2e34dd0faf
3 changed files with 51 additions and 27 deletions

View File

@@ -4,8 +4,7 @@
import Tile from './Tile.js';
import TileState from './TileState.js';
import {createCanvasContext2D} from './dom.js';
import {listenOnce, unlistenByKey} from './events.js';
import EventType from './events/EventType.js';
import {listenImage, unlistenImage} from './Image.js';
class ImageTile extends Tile {
@@ -134,13 +133,12 @@ class ImageTile extends Tile {
if (this.state == TileState.IDLE) {
this.state = TileState.LOADING;
this.changed();
this.imageListenerKeys_ = [
listenOnce(this.image_, EventType.ERROR,
this.handleImageError_, this),
listenOnce(this.image_, EventType.LOAD,
this.handleImageLoad_, this)
];
this.tileLoadFunction_(this, this.src_);
this.imageListenerKeys_ = listenImage(
this.image_,
this.handleImageLoad_.bind(this),
this.handleImageError_.bind(this)
);
}
}
@@ -150,8 +148,7 @@ class ImageTile extends Tile {
* @private
*/
unlistenImage_() {
this.imageListenerKeys_.forEach(unlistenByKey);
this.imageListenerKeys_ = null;
unlistenImage(this.imageListenerKeys_);
}
}