Mercurial > hg > batmud > gmap2
changeset 171:b874aae3e75f gmap2
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Mar 2014 20:48:17 +0200 |
parents | fb98e644b80c |
children | c62f0cf2bf16 |
files | map.js |
diffstat | 1 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/map.js Tue Mar 11 20:19:58 2014 +0200 +++ b/map.js Tue Mar 11 20:48:17 2014 +0200 @@ -10,14 +10,20 @@ var pmapTilePxPerRad = pmapTileSize / (2.0 * Math.PI); -function pmapLatLngToMapCoord(latLng, zoom) +function pmapMinMax(vval, vmin, vmax) { - msiny = Math.sin((latLng.lat() * Math.PI) / 180.0); + return Math.min(Math.max(vval, vmin), vmax); +} + + +function pmapLatLngToMapCoords(latLng) +{ + msiny = pmapMinMax(Math.sin((latLng.lat() * Math.PI) / 180.0), -0.9999, 0.9999); 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); + + return new google.maps.Point(Math.round((px * pmapTileOrig + 1) / 2), Math.round((py * pmapTileOrig + 1) / 2)); } @@ -31,6 +37,7 @@ function pmapInitializeMap() { + // Initialize custom imagemap with our tiles var pmapBatMap = new google.maps.ImageMapType( { getTileUrl: function(coord, zoom) @@ -38,13 +45,14 @@ return "tiles/"+ zoom +"/"+ coord.y +"/"+ coord.x +".png"; }, - tileSize: new google.maps.Size(256, 256), + tileSize: new google.maps.Size(pmapTileSize, pmapTileSize), maxZoom: 10, minZoom: 3, radius: 1738000, name: 'BatMap' }); + // Create map controller object pmap = new google.maps.Map(document.getElementById("map"), { zoom: 3, @@ -78,9 +86,9 @@ // function pmapCoordinateListener(point) { - var p = pmapLatLngToMapCoord(point.latLng, 7); - var tx = Math.round((p.x + 1) / 2); - var ty = Math.round((p.y + 1) / 2); + var p = pmapLatLngToMapCoords(point.latLng); + var tx = p.x; + var ty = p.y; var cx = tx; var cy = ty;