# HG changeset patch # User Matti Hamalainen # Date 1394561998 -7200 # Node ID fb98e644b80c76d5c7ad4f7d2a541784fb0725a3 # Parent 7c14ab0281ad5e1dcc3e21d6077f2da94637ccfb Fix coordinates display. diff -r 7c14ab0281ad -r fb98e644b80c map.js --- 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; }