Reuse existing canvases from vector render tiles

This commit is contained in:
Andreas Hocevar
2020-01-08 10:42:34 +01:00
parent 5a8df1d4e2
commit 9f4dbd3c35
4 changed files with 27 additions and 4 deletions

View File

@@ -7,10 +7,12 @@
* Create an html canvas element and returns its 2d context.
* @param {number=} opt_width Canvas width.
* @param {number=} opt_height Canvas height.
* @param {Array<HTMLCanvasElement>=} opt_canvasPool Canvas pool to take existing canvas from.
* @return {CanvasRenderingContext2D} The context.
*/
export function createCanvasContext2D(opt_width, opt_height) {
const canvas = document.createElement('canvas');
export function createCanvasContext2D(opt_width, opt_height, opt_canvasPool) {
const canvas = opt_canvasPool && opt_canvasPool.length ?
opt_canvasPool.shift() : document.createElement('canvas');
if (opt_width) {
canvas.width = opt_width;
}