all repos — felt @ e34ab4711cc9be60fa9949ddabd0b129883b7d5b

virtual tabletop for dungeons and dragons (and similar) using Go, MongoDB, and websockets

popup anchor and resize fix
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmSzKhwACgkQO3+8IhRO
Y5j9cw/+JUruyuxB07STp9KrD3/8h287JCwxOUDhNn5uB1s9Iv6AhK93b8nk3bpE
g4epCv9Gx/xtW8NpG1RBTPj6IdOeyO5rwoU9cSUJaziunN83HJpzVltZ2KRiRmXU
+LFL6gOz1cIwXQfaiZKCpE9GGqu/iFCJO1lnsHMF9ZfPnoxw+V0FtOSFjLjo5kMg
CLEbMfGAey+BmrqyGQy9qf2UZGl6vo2IJumIxmPgFOFV2qOm7NFf7SDt7auEsR6J
rjWwU0V17vURLFAl1bvxjbADhVGvF+wZsQMzvkUkHgZPtbHweqcilnpP29Q29nhl
S+y56vMWSSt0tyUMGMhUwl3XUTfb23VeXgyK/OfLwp/EmsqtDzZOpT4erys4vbdm
VD8+XNwVRpGGntlKSsvHHlf4gy8BEb0WIoERI48upd9p5bxoT9qdAxmCzm65AxAv
PN1cDk77ulSG7/NqLcvkCP+PQQk301K8OdpyGxtwYvBecM3/nk4RsScTYmqBJ/jz
gQUXriFBIxQYoiGHAxG/LnFOFny5MmO7qV79zClkRVQQu6UL0ZbroI5HYSOqxh0M
5KURDvP5XaK1fWlfTPZjOTDGBLrRpsmNHRvV7e6dp1qUjiD6It3ol8txI6u4zEl0
5szDEDzxQkP7yG17dodZo+zovEzq9al1/KNLyT16tHTOTAOy5HY=
=E8Gc
-----END PGP SIGNATURE-----
commit

e34ab4711cc9be60fa9949ddabd0b129883b7d5b

parent

fdc675dd220728476187918ec10f0111f6d5710a

2 files changed, 18 insertions(+), 10 deletions(-)

jump to
M static/map.jsstatic/map.js

@@ -24,16 +24,24 @@ }

// this works but assumes the map is square (reasonable limitation I think) function resizeMarkers() { + let tryAgain = false; tokens.forEach(t=>{ - const icon = t.m.options.icon; - const scaleFactor = mapImg._image.clientWidth / mapImg._image.naturalWidth; + if (t.m._icon == null) { + tryAgain = true; + } else { + const icon = t.m.options.icon; + const scaleFactor = mapImg._image.clientWidth / mapImg._image.naturalWidth; - icon.options.iconSize = [scaleFactor * t.t.w, scaleFactor * t.t.h]; - icon.options.iconAnchor = [scaleFactor * t.t.oX, scaleFactor * t.t.oY]; - icon.options.popupAnchor = [0, -scaleFactor * t.t.oY]; + icon.options.iconSize = [scaleFactor * t.t.w, scaleFactor * t.t.h]; + icon.options.iconAnchor = [scaleFactor * t.t.oX, 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) {

@@ -45,7 +53,6 @@ // token was made active

if (t.x != null && t.y != null && !self.t.active && t.active) { self.t.active = true; self.m.addTo(map); - resizeMarkers(); // token was made inactive } else if (t.x != null && t.y != null && self.t.active && !t.active) { self.t.active = false;

@@ -74,7 +81,6 @@ return 0;

}); if (t.active) { self.m.addTo(map); - resizeMarkers(); } } }
M static/socket.jsstatic/socket.js

@@ -197,8 +197,10 @@ while (tokens.some(t=>t)) {

tokens[0].m.removeFrom(map); tokens.shift(); } - mapImg.removeFrom(map); - mapImg = null; + if (mapImg) { + mapImg.removeFrom(map); + mapImg = null; + } } }); conn.addEventListener("open", e => {