Skip to content

Documentation / @interstellar-tools/maps / inverseMercator

Function: inverseMercator() ​

ts
function inverseMercator(
  x: number,
  y: number,
  R: number,
  options?: ProjectionOptionsInterface
): GeographicCoordinatesInterface;

Defined in: projections/mercator.ts:127

Find the point on a sphere for a point on a Mercator map: the inverse of mercator.

φ=arctan⁡sinh⁡yR,λ=λ0+xR

Units

  • Inputs: x, y and R in m, lambda0 in radians.
  • Output: { phi, lambda } in radians, with λ in (−π, π].

Notes

  • Every y has a latitude, so the whole map inverts; the poles are never reached.
  • λ is wrapped to (−π, π]: the map repeats every 2πR east–west.
  • A square map, 2πR on each side, reaches arctan⁡sinh⁡π≈85.0511° north and south: the limit of web map tiles.

Parameters ​

ParameterTypeDescription
xnumberDistance east of the origin in m (finite).
ynumberDistance north of the origin in m (finite).
RnumberRadius R of the sphere in m (finite, > 0).
options?ProjectionOptionsInterfacelambda0, the central meridian (radians, defaults to 0).

Returns ​

GeographicCoordinatesInterface

The point on the sphere, { phi, lambda } in radians.

Throws ​

  • If any input is not a finite number.
  • If R <= 0.

Example ​

ts
// The top of a square web map
inverseMercator(0, Math.PI * 6_378_137, 6_378_137).phi; // ≈ 1.4844 rad, 85.0511°

See ​