User:Toranosuke/coords.js

// based upon http://www.wowwiki.com/User:Pcj/coords.js /*

/* Formulaic logic: The map flow is top to bottom, left to right for placement. It uses a percent placement logic versus fixed. This allows flexibility in map sizes as long as the aspect ratio is maintained. This means: x (North/South) INCREASES as you move south/down. y (East/West) DECREASES as you move East/right. Thus the math on offset for "x" is straight but for "y" it is (100 - value) to reverse the percentage.

Due to Misty Mountains unique layout, that zone will require special handling for East/West work. Misty Mountains breaks West and East at 0.0 where East is 0-13.0 and West is 0-11.9

Due to Angmar's unique layout, that zone will require special handling for North/South work. Angmar breaks North and South at 0.0 where South is 0-7.1 and North is 0-14.6.

Due to decimal based locations, it rounds to even numbers before math so everything is *10.

xType = N for North, S for South, E for East, W for West. All other (currently existing) zones are South/West referenced so we'll ignore xType for them. This is for Angmar/MM support.

xNum = numeric position of Nort/South parameter. xMax, xMin, yMax and yMin are the minimum and maximum locations on a given map respectively. Range = (Max - Min) for the total available range of values on a map. xOffset = ((xNum - xMin) / Range) -- the Top-down offset percentage used to map the point. yOffset = 100 - ((yNum - yMin) / Range) -- the Left-in offset percentage used to map the point. I included the Min and Max values in the formulas incase they change at any time or need tweaking.

// global variables needed to set positions... xPos = ""; yPos = "";

function getImage(zone) { var imageTitle = ""; var xType = xPos.charAt(xPos.length-1); var xNum = xPos.substr(0,(xPos.length-1)) * 10; var xMin = 0; var xMax = 0; var yType = yPos.charAt(yPos.length-1); var yNum = yPos.substr(0, (yPos.length-1)) * 10; var yMin = 0; var yMax = 0; switch (zone) { case "Middle-earth": case "Middle Earth": case "World": imageTitle = "1/1c/Middle-earth450.jpg"; // pos values not supported at this level. yPos = 0; xPos = 0; break; case "Eriador": imageTitle = "3/3d/Eriador450.jpg"; // pos values not supported at this level. yPos = 0; xPos = 0; break; case "Angmar": imageTitle = "1/16/Angmar450.jpg"; // xPos is a special case for Angmar due to 0.0 North/South in zone. if (xType == "N") { // North -- 0 base the top of the map by removing North reference to the 0 point. xNum = 147 - xNum; }			else { // South -- Add 147 to the number to offset the 0 base at top. if (xType == "S") { xNum = xNum + 147; }			}			xMin = 0.1 * 10; xMax = 21.8 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 13.6 * 10; yMax = 42.7 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Bree-land": case "Breeland": imageTitle = "1/1d/Bree-land450.jpg"; xMin = 17.6 * 10; xMax = 38.8 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 37.3 * 10; yMax = 65.6 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Archet": imageTitle = "1/19/Archet450.jpg"; xMin = 24.2 * 10; xMax = 28.3 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 45.2 * 10; yMax = 50.7 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Bree": imageTitle = "4/4a/Bree450.jpg"; xMin = 28 * 10; xMax = 33 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 47.9 * 10; yMax = 54.6 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Bree-land Homestead": case "Bree-land Homesteads": imageTitle = "5/53/Bree-land_homesteads450.jpg"; xMin = 33.9 * 10; xMax = 38 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 44.6 * 10; yMax = 49.9 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Ered Luin": imageTitle = "e/e5/Ered_Luin450.jpg"; xMin = 12.6 * 10; xMax = 32.2 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 86.5 * 10; yMax = 112.9 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Thorin's Gate": imageTitle = "9/98/Thorin's_Gate450.jpg"; xMin = 11.1 * 10; xMax = 17 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 98.7 * 10; yMax = 106.8 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Thorin's Hall Homestead": case "Thorin's Hall Homesteads": imageTitle = "4/49/Thorin's_Hall_Homesteads450.jpg"; // No coord info yet... xMin = 13.2 * 10; xMax = 17.3 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 104.6 * 10; yMax = 110 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Falathlorn Homestead": case "Falathlorn Homesteads": imageTitle = "d/d1/Falathlorn_Homesteads450.jpg"; // No coord info yet... xMin = 24.3 * 10; xMax = 28.5 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 88 * 10; yMax = 93.5 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Ettenmoors": imageTitle = "0/00/Ettenmoors450.jpg"; xMin = 9.9 * 10; xMax = 21.8 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 8.2 * 10; yMax = 24.3 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Evendim": imageTitle = "b/b5/Evendim450.jpg"; xMin = 1.7 * 10; xMax = 24.3 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 52.5 * 10; yMax = 82.8 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Lone-lands": imageTitle = "e/ea/Lone-lands450.jpg"; xMin = 26.2 * 10; xMax = 43.8 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 20.9 * 10; yMax = 44.3 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Misty Mountains": imageTitle = "1/19/Misty_Mountains450.jpg"; // Misty Mountains needs special handling... xMin = 14.6 * 10; xMax = 33.2 * 10; xPos = getOffset(xMin, xMax, xNum); if (yType == "E") { // East -- 0 base the east of the map by removing east reference to the 0 point. yNum = 130 - yNum; }			else { // South -- Add 147 to the number to offset the 0 base at top. if (yType == "W") { yNum = yNum + 130; }			}			yMin = 0.1 * 10; yMax = 24.9 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "North Downs": case "Esteldin": imageTitle = "d/dc/North_Downs450.jpg"; xMin = 1 * 10; xMax = 22.2 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 32.2 * 10; yMax = 60.5 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Rivendell": case "Rivendell Valley": imageTitle = "1/17/Rivendell450.jpg"; xMin = 26.2 * 10; xMax = 33.5 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 0.1 * 10; yMax = 9.4 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Shire": case "The Shire": imageTitle = "c/cc/Shire450.jpg"; xMin = 23.5 * 10; xMax = 37.8 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 59.7 * 10; yMax = 78.7 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Shire Homestead": case "The Shire Homestead": case "Shire Homesteads": case "The Shire Homesteads": imageTitle = "b/bb/Shire_Homesteads450.jpg"; // No coord info yet... xMin = 34.5 * 10; xMax = 38.9 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 71.8 * 10; yMax = 77.4 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Trollshaws": imageTitle = "e/ea/Trollshaws450.jpg"; xMin = 20.8 * 10; xMax = 41.3 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 0.1 * 10 - 10; yMax = 26.4 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; }	return "http://ja.lotro.wikia.com/images/" + imageTitle; }

// validate the position is valid with respect to min and max "valid" positional values. // if so, return its percent based relative position. If not, return 0. function getOffset(minPos, maxPos, actualPos) { offset = 0; rangeValue = (maxPos - minPos); if (actualPos > maxPos) { offsetPos = 0; }	else { if (actualPos < minPos) { offsetPos = 0; }		else { offsetPos = ((actualPos - minPos) / rangeValue) * 100; }	}	return offsetPos; }

// the core display tooltip function. function showCoordsTip(i) { if (tooltipsOn) { var Span = document.getElementById( "ctt" + i ); var zoneInfo = Span.className.replace("coordslink ", ""); var zone = "Universe"; if (zoneInfo) { rawMapInfo = zoneInfo.split("--"); zone = rawMapInfo[0]; xPos = rawMapInfo[1]; yPos = rawMapInfo[2]; }		zoneImage = getImage(zone); var tip = document.getElementById('coordstfb'); tooltip = ttHTMLStart + ' '; tooltip = tooltip + ''; if (yPos + xPos == 0) { tooltip = tooltip + ' '; }		else { tooltip = tooltip + ''; tooltip = tooltip + '  '; }		tip.innerHTML = tooltip; tip.style.position = "absolute"; tip.style.visibility = "hidden"; tip.style.display = "block"; tip.style.zIndex = "999"; moveCoordsTip; tip.style.visibility = "visible"; } }

// this function hides the tooltip. function hideCoordsTip { var tip = document.getElementById('coordstfb'); tip.innerHTML = ""; tip.style.display = "none"; }

// This function moves the tool-tips when our mouse moves function moveCoordsTip { if (document.documentElement && document.documentElement.scrollTop) { // IE6 +4.01 and user has scrolled dbSleft = document.documentElement.scrollLeft; dbStop = document.documentElement.scrollTop; } else { // IE5 or DTD 3.2 dbSleft = document.body.scrollLeft; dbStop = document.body.scrollTop; }	var tip = document.getElementById('coordstfb'); var newTop = mousePos.y - (tip.clientHeight + 40); var newLeft = mousePos.x - ( tip.clientWidth / 2 ); if( newTop < dbStop ) { newTop = mousePos.y + 1; if ( newTop + tip.clientHeight > winSize.y ) newTop = dbStop; }	if( newLeft < dbSleft ) newLeft = dbSleft; if( ( mousePos.x + ( tip.clientWidth / 2 ) ) >= winSize.x - 150 ) newLeft = mousePos.x - ( 1.75 * tip.clientWidth ); tip.style.top = newTop + "px"; tip.style.left = newLeft + "px"; }

// activation function... function cttMouseOver { ttfdiv = document.createElement("div"); ttfdiv.setAttribute("id", "coordstfb"); contentstart = document.getElementById("content"); contentstart.insertBefore(ttfdiv, contentstart.childNodes[0]); var Spans = document.getElementsByTagName( "span" ); for ( var i = 0; i < Spans.length; i++ ) { if ( hasClass( Spans[i], "coordslink" ) ) { Spans[i].setAttribute("id", "ctt" + i); Spans[i].onmouseover = showCoordsTip.bind(Spans[i],i); Spans[i].onmouseout = hideCoordsTip; Spans[i].onmousemove = moveCoordsTip; }	} } cttMouseOver; /*