1.2.0 • Published 3 years ago

@mapbox/sphericalmercator v1.2.0

Weekly downloads
35,954
License
-
Repository
github
Last release
3 years ago

Build Status

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 @mapbox/sphericalmercator

API

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,
    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, 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 provides similar utilities for projection and tile math in Python
@everything-registry/sub-chunk-579weathervweatherv-devwmsyymapyymap-geov@gluedigital/tileserver-gl@gluedigital/tileserver-gl-light@gruppe-adler/maps-frontend-utils@mapeo/map-server@mapwhit/mbtiles@mapbox/carmen@mapbox/carmen-private@mapbox/abaculus@mapbox/geo-viewport@mapbox/geojson-thumbnail@mapbox/happytiff@mapbox/search-js-web@mapbox/tilelive@mapbox/tilelive-bridge@mapbox/tilelive-overlay@mapbox/tilelive-vector@mapbox/mvt-fixtures@mapbox/quilt@mapbox/mapnik-omnivore@mapbox/mbtilestileserver-gltileserver-gl-lighttileserver-gl-light-customtilesplashtilestrata-kothictilestrata-postgis-geojson-tilestilestrata-postgresqltilelive-browsertilelive-httptilelive-leveldbtiled-map-service-for-mapboxtilelive-streamingtilelive-blendthree-mapbox-satellitethree-mapsharedstreetstesseratapalcatlterrain-navigatorterrain-rgb-queryslevomat-tileserver-gl-lightsensingx-node-mbtilessumbal-tileserver-glvarsom-observationvector-tiles-generator@kortxyz/ogcapi-gpkg@kalisio/krawler@kartotherian/tilelive-bridge@kartotherian/tilelive-overlay@kartotherian/tilelive-vector@kartotherian/abaculus@geolonia/gsi-mbtiles-tool@gisatcz/ptr-mapselevation-rgb-to-contour@line45/elevation-profiler@nickpeihl/tileserver-gl@nickpeihl/tileserver-gl-light@infinitebrahmanuniverse/nolb-_map@karasushin/mbtilesidlyind-fnd-geo-viewport@inspirock/tileserver-gl@jdesboeufs/tileserver-gl@jdesboeufs/tileserver-gl-light@silverbulletdev/geo-viewport@beyondtracks/mapbox-gl-raster-tile-splitter@beyondtracks/mapbox-gl-raster-tile-bifurcate@bigemap/mbtiles@sodra/vtencdec@sob-a3/maps-frontend-utilslandcover-vectors@urdeveloper/tilelive@zenithmaps/maplibre_wrappercarmenchiitilermbtiles-extracts@acalcutt/tileserver-gl-light@acalcutt/tileserver-glnode-mbtilescadastre-vtmaplarge-google@wikimedia/abaculusmaptalks-mbtilelayermaptalks.tiflayermaptalks.tileclusterlayer@webgeodatavore/tileserver-gl-light@wikimedia/tilelive-overlay@wikimedia/tilelive-vectormapbox-gl-arcgis-tiled-map-servicelist-tiles@varsom/observation-components@aerisweather/abaculus@alvarcarto/mosaic@carto/cartonik
1.2.0

3 years ago

1.2.0-dev

3 years ago

1.1.0

6 years ago

1.0.5

7 years ago