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 LngLat coordinates to Meters coordinates.
Parameters
lnglat
LngLat LngLat [lng, lat, zoom]lng
number Longitude (Meridians) in decimal degreeslat
number Latitude (Parallels) in decimal degreeszoom
number Zoom levelExamples
const meters = lngLatToMeters([37, 126, 13])
//=meters
Returns Meters Meters coordinates
Converts Meters coordinates to LngLat coordinates.
Parameters
meters
Meters Meters [x, y, zoom]x
number Longitudes (Meridians) in metersy
number Latitudes (Parallels) in decimal degreeszoom
number Zoom levelExamples
const lnglat = metersToLngLat([14026255, 4439106, 13])
//=lnglat
Returns LngLat LngLat coordinates
Converts Meters coordinates to Pixels coordinates.
Parameters
meters
Meters Meters [x, y, zoom]x
number Longitudes (Meridians) in metersy
number Latitudes (Parallels) in decimal degreeszoom
number Zoom levelExamples
const pixels = metersToPixels([14026255, 4439106, 13])
//=pixels
Returns Pixels Pixels coordinates
Converts LngLat coordinates to TMS Tile.
Parameters
lnglat
LngLat LngLat [lng, lat, zoom]lng
number Longitude (Meridians) in decimal degreeslat
number Latitude (Parallels) in decimal degreeszoom
number Zoom levelExamples
const tile = lngLatToTile([37, 126, 13])
//=tile
Returns Tile TMS Tile
Converts LngLat coordinates to Google (XYZ) Tile.
Parameters
lnglat
LngLat LngLat [lng, lat, zoom]lng
number Longitude (Meridians) in decimal degreeslat
number Latitude (Parallels) in decimal degreeszoom
number Zoom levelExamples
const google = lngLatToGoogle({lat: 37, lng: 126, zoom: 13 })
//=google
Returns Google Google (XYZ) Tile
Converts Meters coordinates to TMS Tile.
Parameters
meters
Meters Meters [x, y, zoom]x
number Longitudes (Meridians) in metersy
number Latitudes (Parallels) in decimal degreeszoom
number Zoom levelExamples
const tile = metersToTile([14026255, 4439106, 13])
//=tile
Returns Tile TMS Tile
Converts Pixels coordinates to Meters coordinates.
Parameters
Examples
const meters = pixelsToMeters([1782579, 1280877, 13])
//=meters
Returns Meters Meters coordinates
Converts Pixels coordinates to TMS Tile.
Parameters
Examples
const tile = pixelsToTile([1782579, 1280877, 13])
//=tile
Returns Tile TMS Tile
Converts TMS Tile to bbox in Meters coordinates.
Parameters
Examples
const bbox = tileToBBoxMeters([6963, 5003, 13])
//=bbox
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
Converts TMS Tile to bbox in LngLat coordinates.
Parameters
Examples
const bbox = tileToBBox([6963, 5003, 13])
//=bbox
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
Converts Google (XYZ) Tile to bbox in Meters coordinates.
Parameters
google
Google Google [x, y, zoom]x
number Google (XYZ) Tile Xy
number Google (XYZ) Tile Yzoom
number Zoom levelExamples
const bbox = googleToBBoxMeters([6963, 3188, 13])
//=bbox
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
Converts Google (XYZ) Tile to bbox in LngLat coordinates.
Parameters
google
Google Google [x, y, zoom]x
number Google (XYZ) Tile Xy
number Google (XYZ) Tile Yzoom
number Zoom levelExamples
const bbox = googleToBBox([6963, 3188, 13])
//=bbox
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
Converts TMS Tile to Google (XYZ) Tile.
Parameters
Examples
const google = tileToGoogle([6963, 5003, 13])
//=google
Returns Google Google (XYZ) Tile
Converts Google (XYZ) Tile to TMS Tile.
Parameters
google
Google Google [x, y, zoom]x
number Google (XYZ) Tile Xy
number Google (XYZ) Tile Yzoom
number Zoom levelExamples
const tile = googleToTile([6963, 3188, 13])
//=tile
Returns Tile TMS Tile
Converts Google (XYZ) Tile to Quadkey.
Parameters
google
Google Google [x, y, zoom]x
number Google (XYZ) Tile Xy
number Google (XYZ) Tile Yzoom
number Zoom levelExamples
const quadkey = googleToQuadkey([6963, 3188, 13])
//=quadkey
Returns string Microsoft's Quadkey schema
Parameters
Examples
const quadkey = tileToQuadkey([6963, 5003, 13])
//=quadkey
Returns string Microsoft's Quadkey schema
Parameters
quadkey
string Microsoft's Quadkey schemaExamples
const tile = quadkeyToTile('1321102330211')
//=tile
Returns Tile TMS Tile
Converts Quadkey to Google (XYZ) Tile.
Parameters
quadkey
string Microsoft's Quadkey schemaExamples
const google = quadkeyToGoogle('1321102330211')
//=google
Returns Google Google (XYZ) Tile
Converts BBox from LngLat coordinates to Meters coordinates
Parameters
bbox
BBox extent in [minX, minY, maxX, maxY] orderExamples
const meters = bboxToMeters([ 125, 35, 127, 37 ])
//=meters
Returns BBox 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
Examples
validateTile([60, 80, 5])
validateTile([60, -43, 5])
//= Error: Tile <y> must not be less than 0
Returns Tile TMS Tile
Validates Zoom level.
Parameters
zoom
number Zoom levelExamples
validateZoom(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 Pixels Pixels coordinates
Validates Meters coordinates.
Parameters
meters
Meters Meters [x, y, zoom]x
number Longitudes (Meridians) in metersy
number Latitudes (Parallels) in decimal degreeszoom
[number] Zoom levelExamples
validateMeters([-115, 44])
//= [-115, 44]
Returns Meters Meters coordinates
Validates LngLat coordinates.
Parameters
lnglat
LngLat LngLat [lng, lat, zoom]lng
number Longitude (Meridians) in decimal degreeslat
number Latitude (Parallels) in decimal degreeszoom
[number] Zoom levelExamples
validateLngLat([-115, 44])
//= [-115, 44]
validateLngLat([-225, 44])
//= Error: LngLat [lng] must be within -180 to 180 degrees
Returns LngLat LngLat coordinates
Generate an integer Array containing an arithmetic progression.
A port of the native Python range()
function.
See the Python documentation.
Parameters
Examples
range(20)
range(10, 20)
range(20, 10, -1)
1.0.0 - 2016-10-01
First Stable release was created
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.