Remove unused context arg for tile.getImage()
This commit is contained in:
+2
-17
@@ -4,7 +4,6 @@ goog.require('ol');
|
|||||||
goog.require('ol.Tile');
|
goog.require('ol.Tile');
|
||||||
goog.require('ol.events');
|
goog.require('ol.events');
|
||||||
goog.require('ol.events.EventType');
|
goog.require('ol.events.EventType');
|
||||||
goog.require('ol.obj');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,22 +79,8 @@ ol.ImageTile.prototype.disposeInternal = function() {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.ImageTile.prototype.getImage = function(opt_context) {
|
ol.ImageTile.prototype.getImage = function() {
|
||||||
if (opt_context !== undefined) {
|
return this.image_;
|
||||||
var image;
|
|
||||||
var key = ol.getUid(opt_context);
|
|
||||||
if (key in this.imageByContext_) {
|
|
||||||
return this.imageByContext_[key];
|
|
||||||
} else if (ol.obj.isEmpty(this.imageByContext_)) {
|
|
||||||
image = this.image_;
|
|
||||||
} else {
|
|
||||||
image = /** @type {Image} */ (this.image_.cloneNode(false));
|
|
||||||
}
|
|
||||||
this.imageByContext_[key] = image;
|
|
||||||
return image;
|
|
||||||
} else {
|
|
||||||
return this.image_;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-23
@@ -6,7 +6,6 @@ goog.require('ol.events');
|
|||||||
goog.require('ol.events.EventType');
|
goog.require('ol.events.EventType');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.math');
|
goog.require('ol.math');
|
||||||
goog.require('ol.obj');
|
|
||||||
goog.require('ol.reproj');
|
goog.require('ol.reproj');
|
||||||
goog.require('ol.reproj.Triangulation');
|
goog.require('ol.reproj.Triangulation');
|
||||||
|
|
||||||
@@ -62,12 +61,6 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
|
|||||||
*/
|
*/
|
||||||
this.canvas_ = null;
|
this.canvas_ = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {Object.<number, HTMLCanvasElement>}
|
|
||||||
*/
|
|
||||||
this.canvasByContext_ = {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.tilegrid.TileGrid}
|
* @type {ol.tilegrid.TileGrid}
|
||||||
@@ -216,22 +209,8 @@ ol.reproj.Tile.prototype.disposeInternal = function() {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.reproj.Tile.prototype.getImage = function(opt_context) {
|
ol.reproj.Tile.prototype.getImage = function() {
|
||||||
if (opt_context !== undefined) {
|
return this.canvas_;
|
||||||
var image;
|
|
||||||
var key = ol.getUid(opt_context);
|
|
||||||
if (key in this.canvasByContext_) {
|
|
||||||
return this.canvasByContext_[key];
|
|
||||||
} else if (ol.obj.isEmpty(this.canvasByContext_)) {
|
|
||||||
image = this.canvas_;
|
|
||||||
} else {
|
|
||||||
image = /** @type {HTMLCanvasElement} */ (this.canvas_.cloneNode(false));
|
|
||||||
}
|
|
||||||
this.canvasByContext_[key] = image;
|
|
||||||
return image;
|
|
||||||
} else {
|
|
||||||
return this.canvas_;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ ol.source.TileDebug.Tile_ = function(tileCoord, tileSize, text) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<number, HTMLCanvasElement>}
|
* @type {HTMLCanvasElement}
|
||||||
*/
|
*/
|
||||||
this.canvasByContext_ = {};
|
this.canvas_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
ol.inherits(ol.source.TileDebug.Tile_, ol.Tile);
|
ol.inherits(ol.source.TileDebug.Tile_, ol.Tile);
|
||||||
@@ -89,16 +89,12 @@ ol.inherits(ol.source.TileDebug.Tile_, ol.Tile);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the image element for this tile.
|
* Get the image element for this tile.
|
||||||
* @param {Object=} opt_context Optional context. Only used by the DOM
|
|
||||||
* renderer.
|
|
||||||
* @return {HTMLCanvasElement} Image.
|
* @return {HTMLCanvasElement} Image.
|
||||||
*/
|
*/
|
||||||
ol.source.TileDebug.Tile_.prototype.getImage = function(opt_context) {
|
ol.source.TileDebug.Tile_.prototype.getImage = function() {
|
||||||
var key = opt_context !== undefined ? ol.getUid(opt_context) : -1;
|
if (this.canvas_) {
|
||||||
if (key in this.canvasByContext_) {
|
return this.canvas_;
|
||||||
return this.canvasByContext_[key];
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var tileSize = this.tileSize_;
|
var tileSize = this.tileSize_;
|
||||||
var context = ol.dom.createCanvasContext2D(tileSize[0], tileSize[1]);
|
var context = ol.dom.createCanvasContext2D(tileSize[0], tileSize[1]);
|
||||||
|
|
||||||
@@ -111,8 +107,7 @@ ol.source.TileDebug.Tile_.prototype.getImage = function(opt_context) {
|
|||||||
context.font = '24px sans-serif';
|
context.font = '24px sans-serif';
|
||||||
context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2);
|
context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2);
|
||||||
|
|
||||||
this.canvasByContext_[key] = context.canvas;
|
this.canvas_ = context.canvas;
|
||||||
return context.canvas;
|
return context.canvas;
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -322,11 +322,9 @@ ol.inherits(ol.source.TileUTFGrid.Tile_, ol.Tile);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the image element for this tile.
|
* Get the image element for this tile.
|
||||||
* @param {Object=} opt_context Optional context. Only used for the DOM
|
|
||||||
* renderer.
|
|
||||||
* @return {Image} Image.
|
* @return {Image} Image.
|
||||||
*/
|
*/
|
||||||
ol.source.TileUTFGrid.Tile_.prototype.getImage = function(opt_context) {
|
ol.source.TileUTFGrid.Tile_.prototype.getImage = function() {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+17
-21
@@ -140,10 +140,9 @@ ol.source.Zoomify.Tile_ = function(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<string,
|
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
|
||||||
* HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>}
|
|
||||||
*/
|
*/
|
||||||
this.zoomifyImageByContext_ = {};
|
this.zoomifyImage_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile);
|
ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile);
|
||||||
@@ -152,27 +151,24 @@ ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile);
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.source.Zoomify.Tile_.prototype.getImage = function(opt_context) {
|
ol.source.Zoomify.Tile_.prototype.getImage = function() {
|
||||||
|
if (this.zoomifyImage_) {
|
||||||
|
return this.zoomifyImage_;
|
||||||
|
}
|
||||||
var tileSize = ol.DEFAULT_TILE_SIZE;
|
var tileSize = ol.DEFAULT_TILE_SIZE;
|
||||||
var key = opt_context !== undefined ?
|
var image = ol.ImageTile.prototype.getImage.call(this);
|
||||||
ol.getUid(opt_context).toString() : '';
|
if (this.state == ol.Tile.State.LOADED) {
|
||||||
if (key in this.zoomifyImageByContext_) {
|
if (image.width == tileSize && image.height == tileSize) {
|
||||||
return this.zoomifyImageByContext_[key];
|
this.zoomifyImage_ = image;
|
||||||
} else {
|
|
||||||
var image = ol.ImageTile.prototype.getImage.call(this, opt_context);
|
|
||||||
if (this.state == ol.Tile.State.LOADED) {
|
|
||||||
if (image.width == tileSize && image.height == tileSize) {
|
|
||||||
this.zoomifyImageByContext_[key] = image;
|
|
||||||
return image;
|
|
||||||
} else {
|
|
||||||
var context = ol.dom.createCanvasContext2D(tileSize, tileSize);
|
|
||||||
context.drawImage(image, 0, 0);
|
|
||||||
this.zoomifyImageByContext_[key] = context.canvas;
|
|
||||||
return context.canvas;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return image;
|
return image;
|
||||||
|
} else {
|
||||||
|
var context = ol.dom.createCanvasContext2D(tileSize, tileSize);
|
||||||
|
context.drawImage(image, 0, 0);
|
||||||
|
this.zoomifyImage_ = context.canvas;
|
||||||
|
return context.canvas;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return image;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -60,10 +60,9 @@ ol.Tile.prototype.changed = function() {
|
|||||||
/**
|
/**
|
||||||
* Get the HTML image element for this tile (may be a Canvas, Image, or Video).
|
* Get the HTML image element for this tile (may be a Canvas, Image, or Video).
|
||||||
* @abstract
|
* @abstract
|
||||||
* @param {Object=} opt_context Object.
|
|
||||||
* @return {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} Image.
|
* @return {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} Image.
|
||||||
*/
|
*/
|
||||||
ol.Tile.prototype.getImage = function(opt_context) {};
|
ol.Tile.prototype.getImage = function() {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -216,20 +216,18 @@ describe('ol.source.Zoomify', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('"tile.getImage" returns and caches a loaded canvas', function(done) {
|
it('"tile.getImage" returns and caches a loaded canvas', function(done) {
|
||||||
// It'll only cache if the same context is passed, see below
|
|
||||||
var context = ol.dom.createCanvasContext2D(256, 256);
|
|
||||||
var source = getZoomifySource();
|
var source = getZoomifySource();
|
||||||
|
|
||||||
var tile = source.getTile(0, 0, -1, 1, proj);
|
var tile = source.getTile(0, 0, -1, 1, proj);
|
||||||
|
|
||||||
ol.events.listen(tile, 'change', function() {
|
ol.events.listen(tile, 'change', function() {
|
||||||
if (tile.getState() == 2) { // LOADED
|
if (tile.getState() == 2) { // LOADED
|
||||||
var img = tile.getImage(context);
|
var img = tile.getImage();
|
||||||
expect(img).to.be.a(HTMLCanvasElement);
|
expect(img).to.be.a(HTMLCanvasElement);
|
||||||
|
|
||||||
var tile2 = source.getTile(0, 0, -1, 1, proj);
|
var tile2 = source.getTile(0, 0, -1, 1, proj);
|
||||||
expect(tile2.getState()).to.be(2); // LOADED
|
expect(tile2.getState()).to.be(2); // LOADED
|
||||||
var img2 = tile2.getImage(context);
|
var img2 = tile2.getImage();
|
||||||
expect(img).to.be(img2);
|
expect(img).to.be(img2);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -237,28 +235,6 @@ describe('ol.source.Zoomify', function() {
|
|||||||
tile.load();
|
tile.load();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('"tile.getImage" returns and caches an image only for same context', function() {
|
|
||||||
var source = getZoomifySource();
|
|
||||||
|
|
||||||
var tile = source.getTile(0, 0, -1, 1, proj);
|
|
||||||
var img = tile.getImage(ol.dom.createCanvasContext2D(256, 256));
|
|
||||||
|
|
||||||
var tile2 = source.getTile(0, 0, -1, 1, proj);
|
|
||||||
var img2 = tile2.getImage(ol.dom.createCanvasContext2D(256, 256));
|
|
||||||
|
|
||||||
expect(img).to.be.a(HTMLImageElement);
|
|
||||||
expect(img).to.not.be(img2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('passing the context to "tile.getImage" is optional', function() {
|
|
||||||
var source = getZoomifySource();
|
|
||||||
|
|
||||||
var tile = source.getTile(0, 0, -1, 1, proj);
|
|
||||||
var img = tile.getImage();
|
|
||||||
|
|
||||||
expect(img).to.be.a(HTMLImageElement);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user