Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

global-mercator

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

global-mercator

Global Mercator

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
967
decreased by-16.42%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status

Global Mercator

A set of tools geospatial tools to help with TMS, Google (XYZ) Tiles.

This library is insipered by GDAL2Tiles, Google Summer of Code 2007 & 2008

Installation

Using npm:

$ npm install --save global-mercator

In Node.js:

                     
import * as mercator from 'global-mercator'

                         
import { latLngToMeters } from 'global-mercator'

latLngToMeters

Converts {LatLng} coordinates to {Meters} coordinates.

Parameters

Examples

latLngToMeters({lat: 37, lng: 126})
//= Meters { mx: 14026255.83995247, my: 4439106.787250587 }

Returns Meters

metersToLatLng

Converts {Meters} coordinates to {LatLng} coordinates.

Parameters

Examples

metersToLatLng({ mx: 14026255, my: 4439106 })
//= LatLng { lat: 36.99999435205559, lng: 125.99999245457859 }

Returns LatLng

metersToPixels

Converts {Meters} coordinates to {Pixels}.

Parameters

Examples

metersToPixels({ mx: 14026255, my: 4439106, zoom: 13 })
//= Pixels { px: 1782579.1560447346, py: 1280877.3387406059, zoom: 13 }

Returns Pixels

latLngToTile

Converts {LatLng} coordinates to TMS {Tile}.

Parameters

Examples

latLngToTile({lat: 37, lng: 126, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }

Returns Tile TMS Tile

latLngToGoogle

Converts {LatLng} coordinates to {Google} (XYZ) Tile.

Parameters

Examples

latLngToGoogle({lat: 37, lng: 126, zoom: 13 })
//= Google { x: 6963, y: 3188, zoom: 13 }

Returns Google Google Tile

metersToTile

Converts {Meters} coordinates to TMS {Tile}.

Parameters

Examples

metersToTile({ mx: 14026255, my: 4439106, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }

Returns Tile TMS Tile

pixelsToMeters

Converts {Pixels} coordinates to {Meters} coordinates.

Parameters

Examples

pixelsToMeters({ px: 1782579, py: 1280877, zoom: 13 })
//= Meters { mx: 14026252.018101055, my: 4439099.526918683, zoom: 13 }

Returns Meters

pixelsToTile

Converts {Pixels} coordinates to TMS {Tile}.

Parameters

Examples

pixelsToTile({ px: 1782579, py: 1280877, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }

Returns Tile TMS Tile

tileBounds

Converts TMS {Tile} to bounds in {Meters} coordinates.

Parameters

Examples

tileBounds({ tx: 6963, ty: 5003, zoom: 13 })
//= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ]

Returns Array<number> {bbox} extent in [minX, minY, maxX, maxY] order

tileLatLngBounds

Converts TMS {Tile} to bounds in {LatLng} coordinates.

Parameters

Examples

tileLatLngBounds({ tx: 6963, ty: 5003, zoom: 13 })
//= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ]

Returns Array<number> {bbox} extent in [minX, minY, maxX, maxY] order

googleBounds

Converts {Google} (XYZ) Tile to bounds in {Meters} coordinates.

Parameters

Examples

googleBounds({ x: 6963, y: 3188, zoom: 13 })
//= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ]

Returns Array<number> {bbox} extent in [minX, minY, maxX, maxY] order

googleLatLngBounds

Converts {Google} (XYZ) Tile to bounds in {LatLng} coordinates.

Parameters

Examples

googleLatLngBounds({ x: 6963, y: 3188, zoom: 13 })
//= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ]

Returns Array<number> {bbox} extent in [minX, minY, maxX, maxY] order

tileGoogle

Converts TMS {Tile} to {Google} (XYZ) Tile.

Parameters

Examples

tileGoogle({ tx: 6963, ty: 5003, zoom: 13 })
//= Google { x: 6963, y: 3188, zoom: 13 }

Returns Array<number> {bbox} extent in [minX, minY, maxX, maxY] order

googleTile

Converts {Google} (XYZ) Tile to TMS {Tile}.

Parameters

Examples

googleTile({ x: 6963, y: 3188, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }

Returns Tile TMS Tile

googleQuadkey

Converts {Google} (XYZ) Tile to {Quadkey}.

Parameters

Examples

googleQuadkey({ x: 6963, y: 3188, zoom: 13 })
//= '1321102330211'

Returns string Quadkey

tileQuadkey

Converts TMS {Tile} to {QuadKey}.

Parameters

Examples

tileQuadkey({ tx: 6963, ty: 5003, zoom: 13 })
//= '1321102330211'

Returns string Quadkey

quadkeyTile

Converts {Quadkey} to TMS {Tile}.

Parameters

Examples

quadkeyTile('1321102330211')
//= Tile { tx: 6963, ty: 5003, zoom: 13 }

Returns Tile TMS Tile

quadkeyGoogle

Converts {Quadkey} to {Google} (XYZ) Tile.

Parameters

Examples

quadkeyGoogle('1321102330211')
//= Google { x: 6963, y: 3188, zoom: 13 }

Returns Google

bboxLatLngToMeters

Converts {bbox} from {LatLng} coordinates to {Meters} coordinates

Examples

bboxLatLngToMeters([ 125, 35, 127, 37 ])
//= [ 13914936.349159198, 4163881.1440642904, 14137575.330745745, 4439106.787250587 ]

Returns Array<number> {bbox}

validateTile

Validates TMS {Tile}.

Parameters

Examples

validateTile({tx: 60, ty: 80, zoom: 5})
//= {tx: 60, ty: 80, zoom: 5}
validateTile({tx: 60, ty: -43, zoom: 5})
//= Error: Tile <ty> must not be less than 0

Returns Object TMS Tile

validateZoom

Validates {Zoom} level.

Parameters

Examples

validateZoom(12)
//= 12
validateZoom(-4)
//= Error: <zoom> cannot be less than 1
validateZoom(30)
//= Error: <zoom> cannot be greater than 23

Returns number Zoom level

validatePixels

Validates {Pixels} coordinates.

Parameters

Examples

validatePixels([-115, 44])
//= [-115, 44]

Returns Array<number> Pixels coordinates

validateMeters

Validates {Meters} coordinates.

Parameters

Examples

validateMeters([-115, 44])
//= [-115, 44]

Returns Array<number> Meters coordinates

validateLatLng

Validates {LatLng} coordinates.

Parameters

Examples

validateLatLng([-115, 44])
//= [-115, 44]

Returns Array<number> LatLng coordinates

validateLngLat

Validates {LngLat} coordinates.

Parameters

Examples

validateLngLat([-115, 44])
//= [-115, 44]

Returns Array<number> LngLat coordinates

bounds

Validates bounds.

Parameters

Examples

validateBounds([ -75, 44, -74, 45 ])
//= [ -75, 44, -74, 45 ]
validateBounds([ -75, 44, -74 ])
//= Error: [bounds] must be an Array of 4 numbers

assertUndefined

Assert undefined items within object.

Parameters

Examples

assertUndefined({foo: 'bar'})
//= {foo: 'bar'}
assertUndefined({foo: undefined})
//= Error: <foo> is required

Returns Object items

FAQs

Package last updated on 22 Sep 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc