Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
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.
Another great simplistic tile library is tilebelt
.
$ npm install --save global-mercator
import { tileToBBox } from 'global-mercator'
const tile = [10, 15, 8] // x, y, zoom
tileToBBox(tile)
// [ -165.937, -82.853, -164.531, -82.676 ]
Function | Description |
---|---|
lngLatToMeters(LngLat) | Converts LngLat coordinates to Meters coordinates. |
metersToLngLat(Meters) | Converts Meters coordinates to LngLat coordinates. |
metersToPixels(Meters, zoom) | Converts Meters coordinates to Pixels coordinates. |
lngLatToTile(LngLat, zoom) | Converts LngLat coordinates to TMS Tile. |
lngLatToGoogle(LngLat, zoom) | Converts LngLat coordinates to Google (XYZ) Tile. |
metersToTile(Meters, zoom) | Converts Meters coordinates to TMS Tile. |
pixelsToMeters(Pixels) | Converts Pixels coordinates to Meters coordinates. |
pixelsToTile(Pixels) | Converts Pixels coordinates to TMS Tile. |
tileToBBoxMeters(tile) | Converts TMS Tile to bbox in Meters coordinates. |
tileToBBox(tile) | Converts TMS Tile to bbox in LngLat coordinates. |
googleToBBoxMeters(google) | Converts Google (XYZ) Tile to bbox in Meters coordinates. |
googleToBBox(google) | Converts Google (XYZ) Tile to bbox in LngLat coordinates. |
tileToGoogle(tile) | Converts TMS Tile to Google (XYZ) Tile. |
googleToTile(google) | Converts Google (XYZ) Tile to TMS Tile. |
googleToQuadkey(google) | Converts Google (XYZ) Tile to Quadkey. |
tileToQuadkey(tile) | Converts TMS Tile to QuadKey. |
quadkeyToTile(quadkey) | Converts Quadkey to TMS Tile. |
quadkeyToGoogle(quadkey) | Converts Quadkey to Google (XYZ) Tile. |
bboxToMeters(bbox) | Converts BBox from LngLat coordinates to Meters coordinates |
grid(BBox, minZoom, maxZoom) | Creates an Iterator of Tiles from a given BBox |
gridBulk(BBox, minZoom, maxZoom, size) | Creates a bulk Iterator of Tiles from a given BBox |
gridLevels(BBox, minZoom, maxZoom) | Creates a grid level pattern of arrays |
gridCount(BBox, minZoom, maxZoom) | Counts the total amount of tiles from a given BBox |
Hash for Map ID
Parameters
tile
Tile [x, y, z]Examples
const id = hash([312, 480, 4])
//=5728
Returns number hash
Converts BBox to Center
Parameters
bbox
BBox [west, south, east, north] coordinatesExamples
const center = bboxToCenter([90, -45, 85, -50])
//= [ 87.5, -47.5 ]
Returns LngLat center
Converts LngLat coordinates to Meters coordinates.
Parameters
lnglat
LngLat Longitude (Meridians) & Latitude (Parallels) in decimal degreesExamples
const meters = lngLatToMeters([126, 37])
//=[ 14026255.8, 4439106.7 ]
Returns Meters Meters coordinates
Converts Meters coordinates to LngLat coordinates.
Parameters
meters
Meters Meters in Mercator [x, y]Examples
const lnglat = metersToLngLat([14026255, 4439106])
//=[ 126, 37 ]
Returns LngLat LngLat coordinates
Converts Meters coordinates to Pixels coordinates.
Parameters
meters
Meters Meters in Mercator [x, y]zoom
number Zoom levelExamples
const pixels = metersToPixels([14026255, 4439106], 13)
//=[ 1782579.1, 1280877.3, 13 ]
Returns Pixels Pixels coordinates
Converts LngLat coordinates to TMS Tile.
Parameters
lnglat
LngLat Longitude (Meridians) & Latitude (Parallels) in decimal degreeszoom
number Zoom levelExamples
const tile = lngLatToTile([126, 37], 13)
//=[ 6963, 5003, 13 ]
Returns Tile TMS Tile
Converts LngLat coordinates to Google (XYZ) Tile.
Parameters
lnglat
LngLat Longitude (Meridians) & Latitude (Parallels) in decimal degreeszoom
number Zoom levelExamples
const google = lngLatToGoogle([126, 37], 13)
//=[ 6963, 3188, 13 ]
Returns Google Google (XYZ) Tile
Converts Meters coordinates to TMS Tile.
Parameters
meters
Meters Meters in Mercator [x, y]zoom
number Zoom levelExamples
const tile = metersToTile([14026255, 4439106], 13)
//=[ 6963, 5003, 13 ]
Returns Tile TMS Tile
Converts Pixels coordinates to Meters coordinates.
Parameters
pixels
Pixels Pixels [x, y, zoom]Examples
const meters = pixelsToMeters([1782579, 1280877, 13])
//=[ 14026252.0, 4439099.5 ]
Returns Meters Meters coordinates
Converts Pixels coordinates to TMS Tile.
Parameters
pixels
Pixels Pixels [x, y, zoom]Examples
const tile = pixelsToTile([1782579, 1280877, 13])
//=[ 6963, 5003, 13 ]
Returns Tile TMS Tile
Converts TMS Tile to bbox in Meters coordinates.
Parameters
Examples
const bbox = tileToBBoxMeters([6963, 5003, 13])
//=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
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])
//=[ 125.991, 36.985, 126.035, 37.020 ]
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]Examples
const bbox = googleToBBoxMeters([6963, 3188, 13])
//=[ 14025277.4, 4437016.6, 14030169.4, 4441908.5 ]
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]Examples
const bbox = googleToBBox([6963, 3188, 13])
//=[ 125.991, 36.985, 126.035, 37.020 ]
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
Converts TMS Tile to Google (XYZ) Tile.
Parameters
tile
Tile Tile [x, y, zoom]Examples
const google = tileToGoogle([6963, 5003, 13])
//=[ 6963, 3188, 13 ]
Returns Google Google (XYZ) Tile
Converts Google (XYZ) Tile to TMS Tile.
Parameters
google
Google Google [x, y, zoom]Examples
const tile = googleToTile([6963, 3188, 13])
//=[ 6963, 5003, 13 ]
Returns Tile TMS Tile
Converts Google (XYZ) Tile to Quadkey.
Parameters
google
Google Google [x, y, zoom]Examples
const quadkey = googleToQuadkey([6963, 3188, 13])
//='1321102330211'
Returns string Microsoft's Quadkey schema
Parameters
tile
Tile Tile [x, y, zoom]Examples
const quadkey = tileToQuadkey([6963, 5003, 13])
//='1321102330211'
Returns string Microsoft's Quadkey schema
Parameters
quadkey
string Microsoft's Quadkey schemaExamples
const tile = quadkeyToTile('1321102330211')
//=[ 6963, 5003, 13 ]
Returns Tile TMS Tile
Converts Quadkey to Google (XYZ) Tile.
Parameters
quadkey
string Microsoft's Quadkey schemaExamples
const google = quadkeyToGoogle('1321102330211')
//=[ 6963, 3188, 13 ]
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 ])
//=[ 13914936.3, 4163881.1, 14137575.3, 4439106.7 ]
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
Creates an Iterator of Tiles from a given BBox
Parameters
bbox
BBox extent in [minX, minY, maxX, maxY] orderminZoom
number Minimum ZoommaxZoom
number Maximum ZoomExamples
const iterable = grid([-180.0, -90.0, 180, 90], 3, 8)
const {value, done} = iterable.next()
//=value
//=done
Returns Iterator<Tile> Iterable Tiles from BBox
Creates a bulk Iterator of Tiles from a given BBox
Parameters
bbox
BBox extent in [minX, minY, maxX, maxY] orderminZoom
number Minimum ZoommaxZoom
number Maximum Zoomsize
number Maximum size for bulk TilesExamples
const grid = gridBulk([-180.0, -90.0, 180, 90], 3, 8, 5000)
const {value, done} = grid.next()
//=value
//=done
Returns Iterator<Array<Tile>> Bulk iterable Tiles from BBox
Creates a grid level pattern of arrays
Parameters
bbox
BBox extent in [minX, minY, maxX, maxY] orderminZoom
number Minimum ZoommaxZoom
number Maximum ZoomExamples
const levels = gridLevels([-180.0, -90.0, 180, 90], 3, 8)
//=levels
Returns Array<GridLevel> Grid Level
Counts the total amount of tiles from a given BBox
Parameters
bbox
BBox extent in [minX, minY, maxX, maxY] orderminZoom
number Minimum ZoommaxZoom
number Maximum ZoomExamples
const count = gridCount([-180.0, -90.0, 180, 90], 3, 8)
//=563136
Returns number Total tiles from BBox
Validates TMS Tile.
Parameters
tile
Tile Tile [x, y, zoom]Examples
validateTile([60, 80, 12])
//=[60, 80, 12]
validateTile([60, -43, 5])
//= Error: Tile <y> must not be less than 0
validateTile([25, 60, 3])
//= Error: Illegal parameters for tile
Returns Tile TMS Tile
Validates Zoom level.
Parameters
zoom
number Zoom levelExamples
mercator.validateZoom(12)
//=12
mercator.validateZoom(-4)
//= Error: <zoom> cannot be less than 0
validateZoom(32)
//= Error: <zoom> cannot be greater than 30
Returns number zoom Zoom level
Validates LngLat coordinates.
Parameters
lnglat
LngLat Longitude (Meridians) & Latitude (Parallels) in decimal degreesExamples
validateLngLat([-115, 44])
//= [ -115, 44 ]
validateLngLat([-225, 44])
//= Error: LngLat [lng] must be within -180 to 180 degrees
Returns LngLat LngLat coordinates
Validates Pixels coordinates.
Parameters
Examples
validatePixels([-115, 44])
Returns Pixels Pixels coordinates
1.7.0 - 2017-01-24
FAQs
Tools to help with TMS, Quadkey & Google (XYZ) Tiles
The npm package global-mercator receives a total of 741 weekly downloads. As such, global-mercator popularity was classified as not 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.