Created
July 2, 2015 07:24
-
-
Save donSchoe/f12fffb3584ee2b9042d to your computer and use it in GitHub Desktop.
epsg4326 latLonToPixels xy
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
// JavaScript | |
// converts lat/lon to pixel x/y at zoom level 0 for 256*256 tile size , inverts y coord | |
function latLonToPixels(lat, lon) { // lat, lon: epsg:4326 | |
var sinLat = Math.sin(lat * Math.PI / 180.0); | |
var pixelX = ((lon + 180) / 360) * 256; | |
var pixelY = (0.5 - Math.log((1 + sinLat) / (1 - sinLat)) / (Math.PI * 4)) * 256; | |
return { x: pixelX, y: pixelY }; // object with .x and .y | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ps. multiplying with
* 256
can be skipped, range[0,1]
is good to work with, too.