Created
June 15, 2021 23:47
-
-
Save spite/051604efd1d971ab4b6ef1bc1ae2636e to your computer and use it in GitHub Desktop.
zoom - lat -lon to mapzen/tilezen tile
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
function getTileFromLatLon(zoom, lat, lon) { | |
const width = Math.pow(2, zoom); | |
const height = Math.pow(2, zoom); | |
const latRad = (lat * Math.PI) / 180; | |
const x = ~~((width * (lon + 180)) / 360); | |
const y = ~~(((1 - Math.asinh(Math.tan(latRad)) / Math.PI) / 2.0) * height); | |
return {zoom, x, y}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment