changeset 10:418baf7942ca gmap2

Cleanups.
author ggr
date Mon, 21 Sep 2009 14:32:07 +0000
parents 6c05a50c0851
children 464b0131bafd
files js/map.js
diffstat 1 files changed, 41 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/js/map.js	Mon Sep 21 14:19:44 2009 +0000
+++ b/js/map.js	Mon Sep 21 14:32:07 2009 +0000
@@ -9,14 +9,15 @@
 	new GLatLngBounds(new GLatLng(-90, -180), 
 	new GLatLng(90, 180)),
 	0, "Map data by BAT ry, Ooga, Ggr, Slobber and Jeskko");
+
 var cc = new GCopyrightCollection('BatMUD');
 cc.addCopyright(copyright);
 
 var tl = [new GTileLayer(cc, 2, 10),
 	  new GTileLayer(cc, 2, 10)];
 
-tl[0].getTileUrl=function(a,b){ return "/map/tiles/"+(b)+"/"+a.y+"/"+a.x+".png"; }
-tl[1].getTileUrl=function(a,b){ return "/map/overlay.php?x="+a.x+"&y="+a.y+"&zoom="+(b); }
+tl[0].getTileUrl = function(a,b) { return "/map/tiles/"+(b)+"/"+a.y+"/"+a.x+".png"; }
+tl[1].getTileUrl = function(a,b) { return "/map/overlay.php?x="+a.x+"&y="+a.y+"&zoom="+(b); }
 
 var custommap = new GMapType(tl, new GMercatorProjection(12),"BatMud", {errorMessage:"No data available"});
 map.addMapType(custommap);
@@ -24,51 +25,45 @@
 
 var proj=map.getCurrentMapType().getProjection();
 
-google.maps.Event.addListener(map, "mousemove", function(point) {
-  var p=proj.fromLatLngToPixel(point,7);
-  tx=Math.round((p.x-16383)/2)-1;
-  ty=Math.round((p.y-16383)/2)-1;
-  xx=tx;
-  yy=ty;
-  cont="Deep Sea";
-  if (tx>0&&tx<829&&ty>0&&ty<783)
-  {
-    cont="Laenor";
-    xx=tx;
-    yy=ty;
-  }
-  if (tx>1210&&tx<1653&&ty>1154&&ty<1655)
-  {
-    cont="Furnachia";
-    xx=tx-1210;
-    yy=ty-1154;
+function checkCoords(cx, cy, cxmin, cymin, cxmax, cymax, cname) {
+  if (cx > cxmin && cx < cxmax && cy > cymin && cy < cymax) {
+    return {x: cx + cxmin, y: cy + cymin, name: cname};
+  } else {
+    return null;
   }
-  if (tx>1310&&tx<1792&&ty>-1256&&ty<-774)
-  {
-    cont="Rothikgen";
-    xx=tx-1310;
-    yy=ty-1256;
-  }
-  if (tx>-635&&tx<68&&ty>2344&&ty<2847)
-  {
-    cont="Lucentium";
-    xx=tx+635;
-    yy=ty-2344;
+}
+
+var continents = [
+// "Name"         x0,    y0,    x1,    y1
+  ["Laenor",      0,     0,     829,   783],
+  ["Furnachia",   1210,  1154,  1653,  1655],
+  ["Rothikgen",   1310, -1256,  1792, -774],
+  ["Lucentium",  -635,   2344,  68,    2847],
+  ["Desolathya", -1211,  819,  -669,   1352],
+  ["Renardy",     2066, -912,   2238, -825],
+];
+
+google.maps.Event.addListener(map, "mousemove", function(point) {
+  var p = proj.fromLatLngToPixel(point,7);
+  tx = Math.round((p.x-16383)/2)-1;
+  ty = Math.round((p.y-16383)/2)-1;
+
+  xx = tx;
+  yy = ty;
+  cont = "Deep Sea";
+  
+  for (i = 0; i < continents.length; i++) {
+    var c = continents[i];
+    if (tx > c[1] && tx < c[3] && ty > c[2] && ty < c[4]) {
+      cont = c[0];
+      xx = tx + c[1];
+      yy = ty + c[2];
+      break;
+    }
   }
-  if (tx>-1211&&tx<-669&&ty>819&&ty<1352)
-  {
-    cont="Desolathya";
-    xx=tx+1211;
-    yy=ty-819;
-  }
-  if (tx>2066&&tx<2238&&ty>-912&&ty<-825)
-  {
-    cont="Renardy";
-    xx=tx-2068;
-    yy=ty+910;
-  }
-  document.getElementById("xcoord").innerHTML=xx;
-  document.getElementById("ycoord").innerHTML=yy;
-  document.getElementById("continent").innerHTML=cont;
+
+  document.getElementById("xcoord").innerHTML = xx;
+  document.getElementById("ycoord").innerHTML = yy;
+  document.getElementById("continent").innerHTML = cont;
 });