Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
global-mercator
Advanced tools
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
Using npm:
$ npm install --save global-mercator
In Node.js:
import * as mercator from 'global-mercator'
import { latLngToMeters } from 'global-mercator'
Converts LatLng coordinates to Meters coordinates.
Parameters
lat
number Latitude (Parallels) in decimal degreeslng
number Longitude (Meridians) in decimal degreeszoom
[number] Zoom levelExamples
latLngToMeters({lat: 37, lng: 126})
//= Meters { mx: 14026255.83995247, my: 4439106.787250587 }
Returns Object Meters coordinates
Converts Meters coordinates to LatLng coordinates.
Parameters
mx
number Longitudes (Meridians) in metersmy
number Latitudes (Parallels) in decimal degreeszoom
[number] Zoom levelExamples
metersToLatLng({ mx: 14026255, my: 4439106 })
//= LatLng { lat: 36.99999435205559, lng: 125.99999245457859 }
Returns Object LatLng coordinates
Converts Meters coordinates to Pixels coordinates.
Parameters
mx
number Longitudes (Meridians) in metersmy
number Latitudes (Parallels) in decimal degreeszoom
number Zoom levelExamples
metersToPixels({ mx: 14026255, my: 4439106, zoom: 13 })
//= Pixels { px: 1782579.1560447346, py: 1280877.3387406059, zoom: 13 }
Returns Object Pixels coordinates
Converts LatLng coordinates to TMS Tile.
Parameters
lat
number Latitude (Parallels) in decimal degreeslng
number Longitude (Meridians) in decimal degreeszoom
number Zoom levelExamples
latLngToTile({lat: 37, lng: 126, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
Returns Object TMS Tile
Converts LatLng coordinates to Google (XYZ) Tile.
Parameters
lat
number Latitude (Parallels) in decimal degreeslng
number Longitude (Meridians) in decimal degreeszoom
number Zoom levelExamples
latLngToGoogle({lat: 37, lng: 126, zoom: 13 })
//= Google { x: 6963, y: 3188, zoom: 13 }
Returns Object Google (XYZ) Tile
Converts Meters coordinates to TMS Tile.
Parameters
mx
number Longitudes (Meridians) in metersmy
number Latitudes (Parallels) in decimal degreeszoom
number Zoom levelExamples
metersToTile({ mx: 14026255, my: 4439106, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
Returns Object TMS Tile
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 Object Meters coordinates
Converts Pixels coordinates to TMS Tile.
Parameters
Examples
pixelsToTile({ px: 1782579, py: 1280877, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
Returns Object TMS Tile
Converts TMS Tile to bbox in Meters coordinates.
Parameters
Examples
tileBbox({ 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
Converts TMS Tile to bbox in LatLng coordinates.
Parameters
Examples
tileLatLngBbox({ 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
Converts Google (XYZ) Tile to bbox in Meters coordinates.
Parameters
Examples
googleBbox({ 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
Converts Google (XYZ) Tile to bbox in LatLng coordinates.
Parameters
Examples
googleLatLngBbox({ 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
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
Converts Google (XYZ) Tile to TMS Tile.
Parameters
Examples
googleTile({ x: 6963, y: 3188, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
Returns Object TMS Tile
Converts Google (XYZ) Tile to Quadkey.
Parameters
Examples
googleQuadkey({ x: 6963, y: 3188, zoom: 13 })
//= '1321102330211'
Returns string Microsoft's Quadkey schema
Parameters
Examples
tileQuadkey({ tx: 6963, ty: 5003, zoom: 13 })
//= '1321102330211'
Returns string Microsoft's Quadkey schema
Parameters
quadkey
string Microsoft's Quadkey schemaExamples
quadkeyTile('1321102330211')
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
Returns Object TMS Tile
Converts Quadkey to Google (XYZ) Tile.
Parameters
quadkey
string Microsoft's Quadkey schemaExamples
quadkeyGoogle('1321102330211')
//= Google { x: 6963, y: 3188, zoom: 13 }
Returns Object Google (XYZ) Tile
Converts bbox from LatLng coordinates to Meters coordinates
Parameters
Examples
bboxLatLngToMeters([ 125, 35, 127, 37 ])
//= [ 13914936.349159198, 4163881.1440642904, 14137575.330745745, 4439106.787250587 ]
Returns Array<number> bbox extent in [minX, minY, maxX, maxY] order
Retrieve resolution based on zoom level
Parameters
zoom
number zoom levelExamples
const res = resolution(13)
//=res
Returns number resolution
Validates TMS Tile.
Parameters
tx
number TMS Tile Xty
number TMS Tile Yzoom
number Zoom levelname
[string] name used for debugging message (optional, default Tile
)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
Validates Zoom level.
Parameters
zoom
number Zoom levelExamples
validateZoom(12)
//= 12
validateZoom(-4)
//= Error: <zoom> cannot be less than 0
validateZoom(32)
//= Error: <zoom> cannot be greater than 30
Returns number zoom Zoom level
Validates Pixels coordinates.
Parameters
Examples
validatePixels([-115, 44])
//= [-115, 44]
Returns Array<number> Pixels coordinates
Validates Meters coordinates.
Parameters
Examples
validateMeters([-115, 44])
//= [-115, 44]
Returns Array<number> Meters coordinates
Validates LatLng coordinates.
Parameters
Examples
validateLatLng([60, -125])
//= [60, -125]
validateLatLng([140, -125])
//= Error: LatLng [lat] must be within -90 to 90 degrees
Returns Array<number> LatLng coordinates
Validates LngLat coordinates.
Parameters
Examples
validateLngLat([-115, 44])
//= [-115, 44]
validateLngLat([-225, 44])
//= Error: LatLng [lng] must be within -180 to 180 degrees
Returns Array<number> LngLat coordinates
Validates bbox.
Parameters
Examples
validateBbox([ -75, 44, -74, 45 ])
//= [ -75, 44, -74, 45 ]
validateBbox([ -75, 44, -74 ])
//= Error: [bbox] must be an Array of 4 numbers
Returns Array<number> bbox extent in [minX, minY, maxX, maxY] order
Assert undefined items within object.
Parameters
Examples
assertUndefined({foo: 'bar'})
//= {foo: 'bar'}
assertUndefined({foo: undefined})
//= Error: <foo> is required
Returns Object items
Google (XYZ) Tile
Properties
TMS Tile
Properties
Pixels coordinates
Properties
Meters coordinates
Properties
mx
number Longitudes (Meridians) in metersmy
number Latitudes (Parallels) in decimal degreeszoom
number Zoom levelLatLng coordinates
Properties
FAQs
Tools to help with TMS, Quadkey & Google (XYZ) Tiles
The npm package global-mercator receives a total of 1,045 weekly downloads. As such, global-mercator popularity was classified as popular.
We found that global-mercator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.