popup anchor and resize fix

This commit is contained in:
Iris Lightshard 2023-07-15 17:22:04 -06:00
parent fdc675dd22
commit e34ab4711c
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
2 changed files with 18 additions and 10 deletions

View file

@ -24,7 +24,11 @@ function initializeMap(mapImgUrl) {
// this works but assumes the map is square (reasonable limitation I think) // this works but assumes the map is square (reasonable limitation I think)
function resizeMarkers() { function resizeMarkers() {
let tryAgain = false;
tokens.forEach(t=>{ tokens.forEach(t=>{
if (t.m._icon == null) {
tryAgain = true;
} else {
const icon = t.m.options.icon; const icon = t.m.options.icon;
const scaleFactor = mapImg._image.clientWidth / mapImg._image.naturalWidth; const scaleFactor = mapImg._image.clientWidth / mapImg._image.naturalWidth;
@ -33,7 +37,11 @@ function resizeMarkers() {
icon.options.popupAnchor = [0, -scaleFactor * t.t.oY]; icon.options.popupAnchor = [0, -scaleFactor * t.t.oY];
t.m.setIcon(icon); t.m.setIcon(icon);
}
}); });
if (tryAgain) {
setTimeout(resizeMarkers, 500)
}
} }
function processTokens(tokenChanges) { function processTokens(tokenChanges) {
@ -45,7 +53,6 @@ function processTokens(tokenChanges) {
if (t.x != null && t.y != null && !self.t.active && t.active) { if (t.x != null && t.y != null && !self.t.active && t.active) {
self.t.active = true; self.t.active = true;
self.m.addTo(map); self.m.addTo(map);
resizeMarkers();
// token was made inactive // token was made inactive
} else if (t.x != null && t.y != null && self.t.active && !t.active) { } else if (t.x != null && t.y != null && self.t.active && !t.active) {
self.t.active = false; self.t.active = false;
@ -74,7 +81,6 @@ function processTokens(tokenChanges) {
}); });
if (t.active) { if (t.active) {
self.m.addTo(map); self.m.addTo(map);
resizeMarkers();
} }
} }
} }

View file

@ -197,9 +197,11 @@ function dial() {
tokens[0].m.removeFrom(map); tokens[0].m.removeFrom(map);
tokens.shift(); tokens.shift();
} }
if (mapImg) {
mapImg.removeFrom(map); mapImg.removeFrom(map);
mapImg = null; mapImg = null;
} }
}
}); });
conn.addEventListener("open", e => { conn.addEventListener("open", e => {
offline = false; offline = false;