2.0.0 • Published 9 months ago

@mapbox/sphericalmercator v2.0.0

Weekly downloads
35,954
License
-
Repository
github
Last release
9 months ago

Run tests

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.

See also

  • tilebelt provides ZXY tile math utilities in javascript
  • mercantile provides similar utilities for projection and tile math in Python

Installation

npm install @mapbox/sphericalmercator

API

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

import { SphericalMercator } from '@mapbox/sphericalmercator';

// By default, precomputes up to z30
const merc = new SphericalMercator({
  size: 256,
  antimeridian: true
});

px(ll, zoom)

Convert lon, lat to screen pixel x, y from 0, 0 origin, at a certain zoom level. The inverse of ll. If antimeridian: true is passed on initialization of the SphericalMercator object, this method will support converting longitude values up to 360°.

ll(px, zoom)

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

bbox(x, y, zoom, tmsStyle, 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.
  • tmsStyle {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, tmsStyle, srs)

Convert bbox to xyz bounds

  • bbox {Number} bbox in the form [w, s, e, n].
  • zoom {Number} zoom.
  • tmsStyle {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

Developing

npm ci          # install
npm test        # run tests
npm run format  # format files with prettier
@everything-registry/sub-chunk-579tapalcatlterrain-navigatorterrain-rgb-querywmsweathervweatherv-devsumbal-tileserver-glthree-mapthree-mapbox-satellitevarsom-observation@dmitrymin/eventmapper-commongeovis-map-serverstyled-map-packagetesseratiled-map-service-for-mapboxtilelive-streamingtilelive-blendtilelive-browsertilelive-httptilelive-leveldbtilestrata-kothictilestrata-postgis-geojson-tilestilestrata-postgresqltileserver-gltileserver-gl-lighttileserver-gl-light-customtilesplash@alvarcarto/mosaic@aerisweather/abaculus@beyondtracks/mapbox-gl-raster-tile-bifurcate@beyondtracks/mapbox-gl-raster-tile-splitter@bigemap/mbtiles@carto/cartonik@acalcutt/tileserver-gl@acalcutt/tileserver-gl-light@dhis2/maps-glyymapyymap-geovvector-tiles-generator@gruppe-adler/maps-frontend-utils@idmwx/idmui-gl@idmwx/idmui-gl2@idmwx/idmui-gl2-h5@idmwx/idmui-gl3@geolonia/gsi-mbtiles-tool@gisatcz/ptr-maps@gluedigital/tileserver-gl@gluedigital/tileserver-gl-light@infinitebrahmanuniverse/nolb-_map@inspirock/tileserver-gl@kortxyz/ogcapi-gpkg@line45/elevation-profiler@mapbox/carmen@mapbox/carmen-private@mapbox/happytiff@mapbox/search-js-web@mapbox/tilelive@mapbox/tilelive-bridge@mapbox/tilelive-overlay@mapbox/tilelive-vector@mapbox/geo-viewport@mapbox/geojson-thumbnail@mapbox/abaculus@mapbox/quilt@mapwhit/mbtiles@nickpeihl/tileserver-gl@nickpeihl/tileserver-gl-light@mapbox/mapnik-omnivore@mapbox/mbtiles@mapbox/mvt-fixtures@mapeo/map-server@kalisio/krawler@kartotherian/tilelive-bridge@kartotherian/tilelive-overlay@kartotherian/tilelive-vector@kartotherian/abaculus@karasushin/mbtiles@jdesboeufs/tileserver-gl-light@jdesboeufs/tileserver-gl@opengis/bi@opengis/gis-serverosmlintobservation-componentspbf-basic-rendersensingx-node-mbtilesnkm-mapbox-mapnode-mbtilesnode-mbtilesv123pengubinsharedstreetsslevomat-tileserver-gl-lightidlyind-fnd-geo-viewporthigurumalist-tilesmapbox-gl-arcgis-tiled-map-servicemaptalks.tiflayermaptalks.tileclusterlayermaptalks-mbtilelayer
2.0.0-dev.1

9 months ago

2.0.0

9 months ago

1.2.0

4 years ago

1.2.0-dev

4 years ago

1.1.0

7 years ago

1.0.5

9 years ago