From 72e9b74b3e2562b919b2d07783b785a91e9558e7 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 8 Jun 2017 15:33:53 +0200 Subject: [PATCH] Abort loading when tile is disposed --- src/ol/imagetile.js | 7 ++++--- test/spec/ol/imagetile.test.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ol/imagetile.js b/src/ol/imagetile.js index 7a032bf8ce..fe9bff4aaf 100644 --- a/src/ol/imagetile.js +++ b/src/ol/imagetile.js @@ -31,7 +31,7 @@ ol.ImageTile = function(tileCoord, state, src, crossOrigin, tileLoadFunction) { /** * @private - * @type {Image} + * @type {Image|HTMLCanvasElement} */ this.image_ = new Image(); if (crossOrigin !== null) { @@ -60,6 +60,7 @@ ol.inherits(ol.ImageTile, ol.Tile); ol.ImageTile.prototype.disposeInternal = function() { if (this.state == ol.TileState.LOADING) { this.unlistenImage_(); + this.image_.src = ol.ImageTile.blankImage.toDataURL('image/png'); } if (this.interimTile) { this.interimTile.dispose(); @@ -95,8 +96,8 @@ ol.ImageTile.prototype.getKey = function() { */ ol.ImageTile.prototype.handleImageError_ = function() { this.state = ol.TileState.ERROR; - this.image_ = ol.ImageTile.blankImage; this.unlistenImage_(); + this.image_ = ol.ImageTile.blankImage; this.changed(); }; @@ -149,7 +150,7 @@ ol.ImageTile.prototype.unlistenImage_ = function() { /** * A blank image. - * @type {Image} + * @type {HTMLCanvasElement} */ ol.ImageTile.blankImage = (function() { var ctx = ol.dom.createCanvasContext2D(1, 1); diff --git a/test/spec/ol/imagetile.test.js b/test/spec/ol/imagetile.test.js index 6b6bdb5ce3..de4d59d82a 100644 --- a/test/spec/ol/imagetile.test.js +++ b/test/spec/ol/imagetile.test.js @@ -82,4 +82,21 @@ describe('ol.ImageTile', function() { }); + describe('dispose', function() { + + it('sets image src to a blank image data uri', function() { + var tileCoord = [0, 0, 0]; + var state = ol.TileState.IDLE; + var src = 'spec/ol/data/osm-0-0-0.png'; + var tileLoadFunction = ol.source.Image.defaultImageLoadFunction; + var tile = new ol.ImageTile(tileCoord, state, src, null, tileLoadFunction); + tile.load(); + expect(tile.getState()).to.be(ol.TileState.LOADING); + tile.dispose(); + expect(tile.getState()).to.be(ol.TileState.ABORT); + expect(tile.getImage().src).to.be(ol.ImageTile.blankImage.toDataURL('image/png')); + }); + + }); + });