You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB
JavaScript

//=====coord about=====
export function lon2tile(lon, z) {
return Math.floor(((lon + 180) / 360) * Math.pow(2, z))
}
export function lat2tile(lat, z) {
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, z)
)
}
export function lon2x(lon, z) {
return ((lon + 180) / 360) * Math.pow(2, z)
}
export function lat2y(lat, z) {
return (
((1 -
Math.log(
Math.tan((lat * Math.PI) / 180) +
1 / Math.cos((lat * Math.PI) / 180)
) /
Math.PI) /
2) *
Math.pow(2, z)
)
}
export function tile2long(x, z) {
return (x / Math.pow(2, z)) * 360 - 180
}
export function tile2lat(y, z) {
var n = Math.PI - (2 * Math.PI * y) / Math.pow(2, z)
return (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))
}
//=========