Last active
June 18, 2020 22:25
-
-
Save sfpgmr/99a3ce3f69791c9cc8997035caa10d0c to your computer and use it in GitHub Desktop.
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
const pi = Math.PI; | |
const e = Math.E; | |
// tile座標とズームレベルから緯度経度を求める | |
function tile2latlon(x, y, z) { | |
const lon = (x / 2.0 ** z) * 360 - 180;// # 経度(東経) | |
const mapy = (y / 2.0 ** z) * 2 * pi - pi; | |
const lat = 2 * Math.atan(e ** (- mapy)) * 180 / pi - 90;// # 緯度(北緯) | |
return { lat: lat, lon: lon }; | |
} | |
// 緯度経度からtile座標を求める | |
function latlon2tile(lat, lon, z) { | |
const x = ((lon / 180 + 1) * 2 ** z / 2) | 0;// # x座標 | |
const y = (((-Math.log(Math.tan((45 + lat / 2) * pi / 180)) + pi) * 2 ** z / (2 * pi))) | 0;// # y座標 | |
return { x: x, y: y }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment