# sphericalmercator

> Transformations between the Web Mercator projection and Latitude Longitude coordinates

Latest version **1.0.5** (published 2016-04-12) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install sphericalmercator
pnpm add sphericalmercator
yarn add sphericalmercator
bun add sphericalmercator
```

Provides the commands `xyz`, `bbox`, `to4326`, `to900913`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2016-04-12 |
| First published | 2011-06-24 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 288 |
| Author | MapBox |
| Maintainers | aaronlidman, ajashton, ansis, bsudekum, camilleanne, dnomadb, dthompson, gretacb, ian29, ianshward, ingalls, jfirebaugh, jrpruit1, karenzshea, kkaefer, lbud, lxbarth, mapbox-admin, mateov, miccolis, mikemorris, morganherlocker, mourner, nickidlugash, rclark, samanbb, sgillies, springmeyer, tmcw, tristen, willwhite, yhahn |
| Keywords | map, projection, transformations |

## Links

- npm: https://www.npmjs.com/package/sphericalmercator
- Repository: https://github.com/mapbox/node-sphericalmercator
- Homepage: https://github.com/mapbox/node-sphericalmercator#readme
- Issues: https://github.com/mapbox/node-sphericalmercator/issues
- npm.io page: https://npm.io/package/sphericalmercator

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2016-04-12
- 1.0.4 — 2015-09-25
- 1.0.3 — 2014-12-13
- 1.0.2 — 2012-07-31
- 1.0.1 — 2011-08-03
- 1.0.0 — 2011-06-24

## README

[![Build Status](https://secure.travis-ci.org/mapbox/node-sphericalmercator.svg?branch=master)](http://travis-ci.org/mapbox/node-sphericalmercator)

`node-sphericalmercator` provides projection math for converting between
mercator meters, screen pixels (of 256x256 or configurable-size tiles), and
latitude/longitude.

Compatible with nodejs packages and in-browser.

## Installation

`npm install sphericalmercator`

## API

Some datatypes are assumed to be arrays: `ll` is `[lon, lat]`, `xy` and `px` are
`[x, y]`.

```javascript
// By default, precomputes up to z30
var merc = new SphericalMercator({
    size: 256
});
```

### `px(ll, zoom)`

Convert lon, lat to screen pixel x, y from 0, 0 origin, at a certain zoom level.
The inverse of `ll`

### `ll(px, zoom)`

Convert screen pixel value to lon, lat, at a certain zoom level. The inverse
of `px`

### `bbox(x, y, zoom, tms_style, srs)`

Convert tile xyz value to bbox of the form `[w, s, e, n]`

* `x` {Number} x (longitude) number.
* `y` {Number} y (latitude) number.
* `zoom` {Number} zoom.
* `tms_style` {Boolean} whether to compute using tms-style. (optional, default false)
* `srs` {String} projection for resulting bbox (WGS84|900913). (optional, default WGS84)

Returns bbox array of values in form `[w, s, e, n]`.

### `xyz(bbox, zoom, tms_style, srs)`

Convert bbox to xyz bounds

* `bbox` {Number} bbox in the form `[w, s, e, n]`.
* `zoom` {Number} zoom.
* `tms_style` {Boolean} whether to compute using tms-style. (optional, default false)
* `srs` {String} projection of input bbox (WGS84|900913). (optional, default WGS84)

Returns {Object} XYZ bounds containing minX, maxX, minY, maxY properties.

### `convert(bbox, to)`

Convert bbox from 900913 to WGS84 or vice versa

* `bbox` {Number} bbox in the form `[w, s, e, n]`.
* `to` {String} projection of resulting bbox (WGS84|900913). (optional, default WGS84)

Returns bbox array of values in form `[w, s, e, n]`.

### `forward(ll)`

Convert lon, lat values to mercator x, y

### `inverse(xy)`

Convert mercator x, y values to lon, lat

## See Also

* [mercantile](https://github.com/sgillies/mercantile) provides similar utilities for projection and tile math in Python

---
_Source: https://npm.io/package/sphericalmercator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
