User:Zophar/coordstooltip.js

/* Formulaic logic: xNum = numeric position of East/West parameter. yNum = numeric position of North/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 = ((yNum - yMin) / Range) -- the Left-right offset percentage used to map the point.

HOWTO add/change coordinates: Go ingame, switch to full screen, open the map (Map has to be full discovered). Move the mouse the the SE and the NW corner. Write down coordinates for both SE and NW corners. Add those values to xMax, xMin, yMax, yMin for the appropriate area. // global variables needed to set positions... xPos = ""; yPos = ""; mapsize = "300"; var linkCache = new Object; var coords_hidden = new Boolean;

function getImageAndDisplay(zone) { var specialImageTitle = zone; var xNum = xPos; var xMin = 0; var xMax = 0; var yNum = yPos; var yMin = 0; var yMax = 0; switch (specialImageTitle) { //Alderaan case "Alsakan Lowlands": xMin = -501; xMax = 1524; yMin = 787; yMax = 2811; break; case "The Apalis Coast": xMin = -1850; xMax = -280; yMin = 660; yMax = 2228; break; case "The Glarus Valley": xMin = -2651; xMax = 747; yMin = -1969; yMax = 1462; break; case "The Juran Mountains": xMin = 92; xMax = 3000; yMin = -1312; yMax = 1592; break; //Balmorra Republic case "Bugtown": xMin = -237; xMax = 763; yMin = -725; yMax = 380; break; case "Gorinth Canyon (Republic)": xMin = -1091; xMax = 806; yMin = 825; yMax = 2721; break; case "Markaran Plains (Republic)": xMin = -1952; xMax = -465; yMin = 566; yMax = 2053; break; case "Sundari Flatlands (Republic)": xMin = 370; xMax = 1992; yMin = 479; yMax = 2100; break; //Belsavis case "High Security Section": xMin = -2672; xMax = 978; yMin = -714; yMax = 2933; break; case "Maximum Security Section": xMin = -2713; xMax = -129.; yMin = -573; yMax = 844; break; case "Minimum Security Section": xMin = 35; xMax = 1908; yMin = -29; yMax = 1842; break; //Corellia case "Axial Park": xMin = -265; xMax = 1764; yMin = -3503; yMax = -1475; break; case "Blastfield Shipyards": xMin = -464; xMax = 1528; yMin = 507; yMax = 2498; break; case "Government District": xMin = 1731; xMax = 4674; yMin = -3710; yMax = -770; break; case "Labor Valley": xMin = -4066; xMax = -1718; yMin = -3330; yMax = -985; break; //Coruscant case "Black Sun Territory": xMin = -4129; xMax = -3006; yMin = -581; yMax = 541; break; case "Justicar Territory": xMin = 520; xMax = 1617; yMin = 3844; yMax = 4939; break; case "Old Galactic Market": xMin = 2132; xMax = 2720; yMin = 857; yMax = 1444; break; case "Senate Plaza": xMin = -1430; xMax = -878; yMin = -4616; yMax = -4064; break; //Dromund Kaas case "Dromund Kaas": xMin = -2082; xMax = 1226; yMin = -1016; yMax = 2289; break; case "Dark Temple Approach": xMin = -2039; xMax = -595; yMin = -300; yMax = 1141; break; case "Kaas City": xMin = -593; xMax = 118; yMin = -279; yMax = 431; break; case "The Unfinished Colossus": xMin = -91; xMax = 874; yMin = 598; yMax = 1563; break; //Hoth case "Clabburn Tundra": xMin = -4248; xMax = -1801; yMin = -1222; yMax = 1222; break; case "Glacial Fissure": xMin = -1125; xMax = 1479; yMin = -1297; yMax = 1304; break; case "Highmount Ridge": xMin = -2857; xMax = 280; yMin = -1295; yMax = 1838; break; case "Icefall Plains": xMin = -4247; xMax = -1254; yMin = 16; yMax = 3006; break; case "The Starship Graveyard": xMin = 802; xMax = 3085; yMin = -960; yMax = 1319; break; case "Whiterock Wastes": xMin = -3697; xMax = -1919; yMin = -1837; yMax = -60; break; //Hutta case "Hutta": xMin = -682; xMax = 965; yMin = -413; yMax = 1232; break; //Korriban case "Korriban": xMin = -336; xMax = 702; yMin = -495; yMax = 542; break; //Nar Shaddaa case "Lower Industrial Sector": xMin = -2591; xMax = -1923; yMin = 2727; yMax = 3395; break; case "Nikto Sector": xMin = -3866; xMax = -3244; yMin = -3496; yMax = -2875; break; case "Red Light Sector": xMin = 2998; xMax = 3733; yMin = -3763; yMax = -3028; break; case "Shadow Town": xMin = 2152; xMax = 2805; yMin = 2578; yMax = 3231; break; case "The Works": xMin = 646; xMax = 1364; yMin = 4233; yMax = 4951; break; //Ord Mantell case "Fort Garnik": xMin = -14; xMax = 344; yMin = -168; yMax = 188; break; case "Mannett Point": xMin = 378; xMax = 1075; yMin = -28; yMax = 667; break; case "Savrip Island": xMin = -835; xMax = -506; yMin = -729; yMax = -400; break; case "Talloran Village": xMin = 389; xMax = 544; yMin = -233; yMax = -78; break; //Tatooine case "Anchorhead": xMin = 1296; xMax = 2523; yMin = -4261; yMax = -3036; break; case "Jundland": xMin = -1031; xMax = 2942; yMin = -3046; yMax = 923; break; case "The Dune Sea": xMin = -2814; xMax = -182; yMin = -2283; yMax = 345; break; //Voss case "The Gormak Lands": xMin = -935; xMax = 1208; yMin = 612; yMax = 2754; break; case "The Nightmare Lands": xMin = -74; xMax = 2698; yMin = -1269; yMax = 1500; break; case "The Old Paths": xMin = -2840; xMax = -273; yMin = -1900; yMax = 663; break; case "The Pelath-Ri Marches": xMin = -1595; xMax = 1360; yMin = -3334; yMax = -381; break; case "Voss-Ka": xMin = -482; xMax = 675; yMin = -724; yMax = 433; break; }	xPos = getOffset(xMin, xMax, xNum); yPos = getOffset(yMin, yMax, yNum);

//if our link hasn't been fetched yet, fetch it	if(linkCache[specialImageTitle] == null) { $.getJSON(			"/api.php?action=query&format=json",			{titles: "File:"+specialImageTitle+" map.jpg|File:"+specialImageTitle+" map.png", 				prop: "imageinfo", 				iiprop: "url",				iiurlwidth: mapsize			},			function(data) { 				imageFound = false;				for( var page in data.query.pages ) {				//== null means comparing for "undefined" or "null"					if(data.query.pages[page].missing == null) {						if(!coords_hidden)							linkCache[specialImageTitle] = data.query.pages[page].imageinfo[0].thumburl;						showCoordsTip(linkCache[specialImageTitle]);						imageFound = true;					}					if(imageFound)						break;				}				if(!imageFound)					alert("Error, image "+"File:"+specialImageTitle+"_map.jpg"+" or File:"+specialImageTitle+"_map.png were not found!");			}		); } else { return showCoordsTip(linkCache[specialImageTitle]); }

}

// 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 = -1; }	else { if (actualPos < minPos) { offsetPos = -1; }		else { offsetPos = ((actualPos - minPos) / rangeValue) * 100; }	}	return offsetPos; }

// the core display tooltip function. function tryCoordsTip(i) { if (tooltipsOn) { coords_hidden = false; var Span = $('#'+i); var zoneInfo = Span.attr("class").replace("coordslink ", ""); var zone = "Universe"; if (zoneInfo) { rawMapInfo = zoneInfo.split("--"); zone = rawMapInfo[0]; xPos = rawMapInfo[1]; yPos = rawMapInfo[2]; }		zoneImage = getImageAndDisplay(zone); } }

function showCoordsTip(zoneImage) { var tip = document.getElementById('coordstfb'); tooltip = ttHTMLStart + ''; tooltip = tooltip + ''; if (yPos >= 0 && xPos >= 0) { 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 { coords_hidden = true; var tip = document.getElementById('coordstfb'); tip.innerHTML = ""; tip.style.display = "none"; }

// This function moves the tool-tips when our mouse moves function moveCoordsTip { dbSleft = $(document).scrollLeft; dbStop = $(document).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]); $('.coordslink').each(function(i) {		$(this).attr("id", "ctt" + i);		$(this).bind({ mouseover: function { tryCoordsTip($(this).attr("id")); },			mouseout: function { hideCoordsTip; },			mousemove: function { moveCoordsTip; }		});	}); } cttMouseOver;