Merge pull request #7136 from ahocevar/empty-image

Use data URI instead of whole empty image
This commit is contained in:
Andreas Hocevar
2017-08-17 11:04:21 -04:00
committed by GitHub
2 changed files with 8 additions and 8 deletions

View File

@@ -60,7 +60,7 @@ ol.inherits(ol.ImageTile, ol.Tile);
ol.ImageTile.prototype.disposeInternal = function() { ol.ImageTile.prototype.disposeInternal = function() {
if (this.state == ol.TileState.LOADING) { if (this.state == ol.TileState.LOADING) {
this.unlistenImage_(); this.unlistenImage_();
this.image_.src = ol.ImageTile.blankImage.toDataURL('image/png'); this.image_.src = ol.ImageTile.blankImageUrl;
} }
if (this.interimTile) { if (this.interimTile) {
this.interimTile.dispose(); this.interimTile.dispose();
@@ -97,7 +97,7 @@ ol.ImageTile.prototype.getKey = function() {
ol.ImageTile.prototype.handleImageError_ = function() { ol.ImageTile.prototype.handleImageError_ = function() {
this.state = ol.TileState.ERROR; this.state = ol.TileState.ERROR;
this.unlistenImage_(); this.unlistenImage_();
this.image_ = ol.ImageTile.blankImage; this.image_.src = ol.ImageTile.blankImageUrl;
this.changed(); this.changed();
}; };
@@ -149,12 +149,12 @@ ol.ImageTile.prototype.unlistenImage_ = function() {
/** /**
* A blank image. * Data URI for a blank image.
* @type {HTMLCanvasElement} * @type {string}
*/ */
ol.ImageTile.blankImage = (function() { ol.ImageTile.blankImageUrl = (function() {
var ctx = ol.dom.createCanvasContext2D(1, 1); var ctx = ol.dom.createCanvasContext2D(1, 1);
ctx.fillStyle = 'rgba(0,0,0,0)'; ctx.fillStyle = 'rgba(0,0,0,0)';
ctx.fillRect(0, 0, 1, 1); ctx.fillRect(0, 0, 1, 1);
return ctx.canvas; return ctx.canvas.toDataURL('image/png');
})(); })();

View File

@@ -72,7 +72,7 @@ describe('ol.ImageTile', function() {
var state = tile.getState(); var state = tile.getState();
if (state == ol.TileState.ERROR) { if (state == ol.TileState.ERROR) {
expect(state).to.be(ol.TileState.ERROR); expect(state).to.be(ol.TileState.ERROR);
expect(tile.image_).to.be(ol.ImageTile.blankImage); expect(tile.image_.src).to.be(ol.ImageTile.blankImageUrl);
done(); done();
} }
}); });
@@ -94,7 +94,7 @@ describe('ol.ImageTile', function() {
expect(tile.getState()).to.be(ol.TileState.LOADING); expect(tile.getState()).to.be(ol.TileState.LOADING);
tile.dispose(); tile.dispose();
expect(tile.getState()).to.be(ol.TileState.ABORT); expect(tile.getState()).to.be(ol.TileState.ABORT);
expect(tile.getImage().src).to.be(ol.ImageTile.blankImage.toDataURL('image/png')); expect(tile.getImage().src).to.be(ol.ImageTile.blankImageUrl);
}); });
}); });