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 and Forochel's unique layout, those zones will require special handling for North/South work. Angmar breaks North and South at 0.0 where South is 0-7.2 and North is 0-14.7. Forochel breaks North and South at 0.0 where South is 0-5.7 and North is 0-25.0.

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": case "中つ国": imageTitle = "images4.wikia.nocookie.net/lotro/ja/images/3/3e/450px-Middle_Earth.jpg"; // pos values not supported at this level. yPos = 0; xPos = 0; break; case "Eriador": case "エリアドール": imageTitle = "images1.wikia.nocookie.net/lotro/ja/images/6/66/450px-Eriador.jpg"; // pos values not supported at this level. yPos = 0; xPos = 0; break; case "Angmar": case "アングマール": imageTitle = "images1.wikia.nocookie.net/lotro/ja/images/7/74/450px-Angmar.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; // 0.1S to 7.2S + 0.0N to 14.7N = 21.8 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": case "ブリー郷": imageTitle = "images4.wikia.nocookie.net/lotro/ja/images/0/06/450px-Breeland.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": case "アーチェト村": imageTitle = "images2.wikia.nocookie.net/lotro/ja/images/b/b6/450px-Archet.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": case "ブリー村": imageTitle = "images4.wikia.nocookie.net/lotro/ja/images/b/bf/450px-Bree.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": case "ブリー郷の住宅地": imageTitle = "images3.wikia.nocookie.net/lotro/ja/images/f/f0/450px-Bree-land_Homesteads.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": case "エレド・ルイン": imageTitle = "images2.wikia.nocookie.net/lotro/ja/images/1/1a/450px-Ered_Luin.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": case "トーリンの門": imageTitle = "images3.wikia.nocookie.net/lotro/ja/images/2/21/450px-Thorin's_Gate.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": case "トーリンの館の住宅地": imageTitle = "images3.wikia.nocookie.net/lotro/ja/images/a/a3/450px-Thorin's_Hall_Homesteads.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": case "ファラスロルンの住宅地": imageTitle = "images3.wikia.nocookie.net/lotro/ja/images/a/a6/450px-Falathlorn_Homesteads.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 "Forochel": case "フォロヘル": imageTitle = "images3.wikia.nocookie.net/lotro/ja/images/c/c2/450px-Forochel.jpg"; // xPos is a special case for Forochel 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 = 250 - xNum; }			else { // South -- Add 250 to the number to offset the 0 base at top. if (xType == "S") { xNum = xNum + 250; }			}			xMin = 0.1 * 10; xMax = 30.6 * 10; // 0.1S to 5.7S + 0.0N to 25.0N = 30.6 xPos = getOffset(xMin, xMax, xNum); yMin = 51.9 * 10; yMax = 92.8 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Ettenmoors": case "エテン高地": imageTitle = "images4.wikia.nocookie.net/lotro/ja/images/5/5d/450px-Ettenmoors.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": case "イヴンディム": imageTitle = "images2.wikia.nocookie.net/lotro/ja/images/1/1e/450px-Evendim.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": case "さびし野": imageTitle = "images1.wikia.nocookie.net/lotro/ja/images/4/4a/450px-Lone-lands.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": case "霧ふり山脈": imageTitle = "images3.wikia.nocookie.net/lotro/ja/images/d/d2/450px-Misty_Mountains.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 130 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": case "北連丘": case "エステルディン": imageTitle = "images1.wikia.nocookie.net/lotro/ja/images/3/36/450px-North_downs.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 "裂け谷": case "Rivendell Valley": imageTitle = "images3.wikia.nocookie.net/lotro/ja/images/2/20/450px-Rivendell.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": case "ホビット庄": imageTitle = "images2.wikia.nocookie.net/lotro/ja/images/6/61/450px-Shire.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": case "ホビット庄の住宅地": imageTitle = "images2.wikia.nocookie.net/lotro/ja/images/5/51/450px-Shire_Homesteads.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 "Old Forest": case "The Old Forest": case "古森": imageTitle = "images3.wikia.nocookie.net/lotro/ja/images/8/8e/450px-古森.jpg"; xMin = 29.2 * 10; xMax = 38.9 * 10; xPos = getOffset(xMin, xMax, xNum); yMin = 52.3 * 10; yMax = 65.3 * 10; yPos = 100 - getOffset(yMin, yMax, yNum); break; case "Trollshaws": case "トロルの森": imageTitle = "images4.wikia.nocookie.net/lotro/ja/images/3/32/450px-Trollshaws.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://" + 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; /*