Skip to content

Commit

Permalink
fix: getImageFromSpriteSync & getImageFromSpriteAsync: handle missing…
Browse files Browse the repository at this point in the history
… icon 🐛
  • Loading branch information
derhuerst committed Sep 21, 2022
1 parent 7d2e9dc commit c0d0160
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/util/mapIconUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ function getImageFromSpriteSync(icon, width, height, fill) {
return null;
}
const symbol = document.getElementById(icon);
if (!symbol) {
return null;
}
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('width', width);
svg.setAttribute('height', height);
Expand Down Expand Up @@ -237,6 +240,10 @@ function getImageFromSpriteAsync(icon, width, height, fill) {
return new Promise(resolve => {
// TODO: check that icon exists using MutationObserver
const image = getImageFromSpriteSync(icon, width, height, fill);
if (!image) {
resolve(null);
return;
}
image.onload = () => resolve(image);
});
}
Expand Down

0 comments on commit c0d0160

Please sign in to comment.