changeset 170:fb98e644b80c gmap2

Fix coordinates display.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Mar 2014 20:19:58 +0200
parents 7c14ab0281ad
children b874aae3e75f
files map.js
diffstat 1 files changed, 27 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/map.js	Mon Mar 10 15:28:00 2014 +0200
+++ b/map.js	Tue Mar 11 20:19:58 2014 +0200
@@ -4,6 +4,23 @@
 var pmapCanvas;
 var proj;
 
+var pmapTileSize = 256;
+var pmapTileOrig = pmapTileSize / 2.0;
+var pmapTilePxPerDeg = pmapTileSize / 360.0;
+var pmapTilePxPerRad = pmapTileSize / (2.0 * Math.PI);
+
+
+function pmapLatLngToMapCoord(latLng, zoom)
+{
+  msiny = Math.sin((latLng.lat() * Math.PI) / 180.0);
+
+  px = latLng.lng() * pmapTilePxPerDeg;
+  py = 0.5 * Math.log((1 + msiny) / (1 - msiny)) * - pmapTilePxPerRad;
+  numTiles = 1 << zoom;
+  return new google.maps.Point(px * numTiles, py * numTiles);
+}
+
+
 function CanvasProjectionOverlay() {}
 CanvasProjectionOverlay.prototype = new google.maps.OverlayView();
 CanvasProjectionOverlay.prototype.constructor = CanvasProjectionOverlay;
@@ -48,7 +65,7 @@
   pmapCanvas = new CanvasProjectionOverlay();
   pmapCanvas.setMap(pmap);
 
-//  google.maps.event.addListener(pmap, "mousemove", pmapCoordinateListener);
+  google.maps.event.addListener(pmap, "mousemove", pmapCoordinateListener);
 
   pmapInitializeIcons();
   pmapInitializeMarkers();
@@ -61,12 +78,12 @@
 //
 function pmapCoordinateListener(point)
 {
-  var p = proj.fromLatLngToPixel(point, 7);
-  var tx = Math.round((p.x - 16383) / 2);
-  var ty = Math.round((p.y - 16383) / 2);
+  var p = pmapLatLngToMapCoord(point.latLng, 7);
+  var tx = Math.round((p.x + 1) / 2);
+  var ty = Math.round((p.y + 1) / 2);
 
-  var xx = tx;
-  var yy = ty;
+  var cx = tx;
+  var cy = ty;
   var cont = "Deep Sea";
   
   for (i = 0; i < pmapContinents.length; i++)
@@ -75,13 +92,13 @@
     if (c != null && tx > c[1] && tx < c[3] && ty > c[2] && ty < c[4])
     {
       cont = c[0];
-      xx = tx - c[1];
-      yy = ty - c[2];
+      cx = tx - c[1];
+      cy = ty - c[2];
       break;
     }
   }
 
-  document.getElementById("xcoord").innerHTML = xx;
-  document.getElementById("ycoord").innerHTML = yy;
+  document.getElementById("xcoord").innerHTML = cx;
+  document.getElementById("ycoord").innerHTML = cy;
   document.getElementById("continent").innerHTML = cont;
 }