Mercurial > hg > batmud > maputils
changeset 2652:1e163f43e70a
Improve world map functionality: add selecting active location from the map
itself by doubleclicking on the label.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 26 Feb 2024 10:38:44 +0200 |
parents | 590522fd537c |
children | 0f2a476e06c5 |
files | src/worldmap.js |
diffstat | 1 files changed, 40 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/worldmap.js Mon Feb 19 10:53:31 2024 +0200 +++ b/src/worldmap.js Mon Feb 26 10:38:44 2024 +0200 @@ -140,7 +140,6 @@ } } - // Set the active item in the location dropdown var ssel = document.getElementById("slocation"); if (ssel) @@ -159,6 +158,15 @@ if (!found) ssel.selectedIndex = 0; } + + // Set browser window href + var slink = window.location.href; + var spos; + if ((spos = slink.indexOf("#")) >= 0) + slink = slink.substr(0, spos); + slink += newLoc != null ? "#" + newLoc : ""; + + window.location.href = slink; } @@ -169,9 +177,8 @@ } -function mapGotoLocation() +function mapSetLocation(newLoc) { - var newLoc = document.getElementById("slocation").value; if (newLoc == "") { mapCurrLoc = null; @@ -207,15 +214,26 @@ } mapSetActiveLocation(newLoc); +} - // Set href - var slink = window.location.href; - var spos; - if ((spos = slink.indexOf("#")) >= 0) - slink = slink.substr(0, spos); - slink += newLoc != null ? "#" + newLoc : ""; + +function mapGotoLocation(ev) +{ + mapSetLocation(document.getElementById("slocation").value); +} + - window.location.href = slink; +function mapLocationLabelClick(ev) +{ + if (!mapDragGoing) + { + setTimeout(function() + { + mapSetActiveLocation(ev.target.id); + mapSetPosToElem(ev.target); + }, + 50); + } } @@ -293,8 +311,8 @@ { setTimeout(function() { + mapSetActiveLocation(eid); mapSetPosToElem(nelem); - mapSetActiveLocation(eid); }, 50); } @@ -307,6 +325,17 @@ document.addEventListener("mousemove", mapDragMoveHandler); document.addEventListener("mouseup", mapDragUpHandler); + // Add event listeners to locations + var elems = mapElem.getElementsByClassName("label"); + for (let i = 0; i < elems.length; i++) + { + var aelems = elems[i].getElementsByTagName("a"); + if (aelems.length > 0) + { + aelems[0].addEventListener("dblclick", mapLocationLabelClick); + } + } + mapUpdateLabelVisibility(); mapUpdateDragPan(); }