Created
August 26, 2013 18:56
-
-
Save ksnabb/6345157 to your computer and use it in GitHub Desktop.
CoffeeSript version of counting tile x y z or coordinates from tile x y z.
This file contains 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
long2tile = (lon, zoom) -> | |
Math.floor (lon + 180) / 360 * Math.pow(2, zoom) | |
lat2tile = (lat, zoom) -> | |
Math.floor (1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, zoom) | |
tile2long = (x, z) -> | |
x / Math.pow(2, z) * 360 - 180 | |
tile2lat = (y, z) -> | |
n = Math.PI - 2 * Math.PI * y / Math.pow(2, z) | |
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