Performance improvement: only create context when it is needed

This commit is contained in:
Andreas Hocevar
2017-02-07 16:35:22 +01:00
parent 302087b4ec
commit 7db5eea56b
3 changed files with 37 additions and 22 deletions
+4 -1
View File
@@ -24,7 +24,7 @@ ol.VectorTile = function(tileCoord, state, src, format, tileLoadFunction) {
* @private
* @type {CanvasRenderingContext2D}
*/
this.context_ = ol.dom.createCanvasContext2D();
this.context_ = null;
/**
* @private
@@ -83,6 +83,9 @@ ol.inherits(ol.VectorTile, ol.Tile);
* @return {CanvasRenderingContext2D} The rendering context.
*/
ol.VectorTile.prototype.getContext = function() {
if (!this.context_) {
this.context_ = ol.dom.createCanvasContext2D();
}
return this.context_;
};