diff --git a/static/map.js b/static/map.js index d8296e0..b8e3117 100644 --- a/static/map.js +++ b/static/map.js @@ -24,11 +24,11 @@ function initializeMap(mapImgUrl) { // this works but assumes the map is square (reasonable limitation I think) function resizeMarkers() { - let tryAgain = false; + + // for newly created tokens, the icon may not be loaded and thus the resize will not properly complete + // we need a way to queue the resize for when the icon is finished loading + tokens.forEach(t=>{ - if (t.m._icon == null) { - tryAgain = true; - } else { const icon = t.m.options.icon; const scaleFactor = mapImg._image.clientWidth / mapImg._image.naturalWidth; @@ -39,9 +39,7 @@ function resizeMarkers() { t.m.setIcon(icon); } }); - if (tryAgain) { - setTimeout(resizeMarkers, 500) - } + } function processTokens(tokenChanges) {