Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 59x 59x 1x | /** Web Mercator (EPSG:3857), spherical, in metres. */
import { DEG, type LatLon, RAD, WGS84 } from '../../geo/ellipsoid'
export function toWebMercator({ lat, lon }: LatLon): { x: number; y: number } {
const clamped = Math.max(-85.05112878, Math.min(85.05112878, lat))
return {
x: WGS84.a * lon * DEG,
y: WGS84.a * Math.log(Math.tan(Math.PI / 4 + (clamped * DEG) / 2)),
}
}
export function fromWebMercator(x: number, y: number): LatLon {
return {
lat: (2 * Math.atan(Math.exp(y / WGS84.a)) - Math.PI / 2) * RAD,
lon: (x / WGS84.a) * RAD,
}
}
|