Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
sphericalmercator
Advanced tools
Transformations between the Web Mercator projection and Latitude Longitude coordinates
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.
npm install sphericalmercator
Some datatypes are assumed to be arrays: ll
is [lon, lat]
, xy
and px
are
[x, y]
.
// 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
v1.0.5
.xyz()
are negative, set them to zeroFAQs
Transformations between the Web Mercator projection and Latitude Longitude coordinates
The npm package sphericalmercator receives a total of 732 weekly downloads. As such, sphericalmercator popularity was classified as not popular.
We found that sphericalmercator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 32 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.