Skip to content

Commit 83592c1

Browse files
committed
Images: Return promise for image loading
1 parent 8e75905 commit 83592c1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/components/images/draw.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ module.exports = function draw(gd) {
8585
}
8686

8787
thisImage.attr({
88-
href: d.source,
8988
x: xPos,
9089
y: yPos,
9190
width: width,
@@ -95,6 +94,22 @@ module.exports = function draw(gd) {
9594
});
9695

9796

97+
// Images load async so we must add the promise to the list
98+
var imagePromise = new Promise(function(resolve) {
99+
100+
thisImage.on('load', resolve);
101+
thisImage.on('error', function() {
102+
thisImage.remove();
103+
console.log('Image with source ' + d.source + ' could not be loaded.');
104+
resolve();
105+
});
106+
107+
thisImage.attr('href', d.source);
108+
});
109+
110+
gd._promises.push(imagePromise);
111+
112+
98113
// Set proper clipping on images
99114
var xId = xref ? xref._id : '',
100115
yId = yref ? yref._id : '',

0 commit comments

Comments
 (0)