Created
September 9, 2015 11:48
-
-
Save b-g/d8723c10be3ee598e259 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function long2tile(lon,zoom) { | |
return (((lon+180)/360*Math.pow(2,zoom))); | |
} | |
function lat2tile(lat,zoom) { | |
return (((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom))); | |
} | |
function tile2long(x,z) { | |
return (x/Math.pow(2,z)*360-180); | |
} | |
function tile2lat(y,z) { | |
var n=Math.PI-2*Math.PI*y/Math.pow(2,z); | |
return (180/Math.PI*Math.atan(0.5*(Math.exp(n)-Math.exp(-n)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
long2tile and lat2tile should be positive integer
from:
https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Lon..2Flat._to_tile_numbers_2