Avoid uncaught exception 'Error: Image given has not completed loading' while drawing with canvas

This commit is contained in:
Daniel García Aubert 2019-03-28 15:31:48 +01:00
parent 2f97d7fda0
commit 0edffef74b

View File

@ -250,7 +250,15 @@ var CartoDatasource = require('./datasource');
var frame = layer.frames()[fr];
var fr_sprites = sprites[frame] || (sprites[frame] = []);
for (var k = 0, len = keys.length; k < len; k++) {
this._renderTile(tile, keys[k] - frame, frame, fr_sprites, layer);
try {
this._renderTile(tile, keys[k] - frame, frame, fr_sprites, layer);
} catch (error) {
if (callback) {
return callback(error);
}
throw new Error(error);
}
}
}
}
@ -338,7 +346,7 @@ var CartoDatasource = require('./datasource');
if (sp) {
var x = tile.x[posIdx]- (sp.width >> 1) + anchor;
var y = tileMax - tile.y[posIdx] + anchor; // flip mercator
ctx.drawImage(sp, x, y - (sp.height >> 1));
ctx.drawImage(sp, x, y - (sp.height >> 1));
}
}
}