Last active
April 24, 2017 13:52
-
-
Save ayozebarrera/65b255412465eb56ced7c0e7ed9b914d to your computer and use it in GitHub Desktop.
Coordinates to 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
// http://tile.openstreetmap.org/z/x/y.png | |
// example: http://tile.openstreetmap.org/12/2225/2367.png | |
lon2tile = (lon, zoom) => { | |
return (Math.floor((lon+180)/360*Math.pow(2,zoom))); | |
}; | |
lat2tile = (lat, zoom) => { | |
return (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))); | |
}; | |
coords2title = (lon, lat, zoom) => { | |
return { | |
z: zoom, | |
x: this.lon2tile(lon, zoom), | |
y: this.lat2tile(lat, zoom) | |
} | |
} | |
parseOpenStreetMapUrl = (geo) => { | |
return `http://tile.openstreetmap.org/${geo.z}/${geo.x}/${geo.y}.png` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment