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
.
Install
npm
$ npm install --save global-mercator
web browser (ES5)
<script src="https://unpkg.com/global-mercator/global-mercator.min.js"></script>
Quickstart
var tile = [10, 15, 8]
globalMercator.tileToBBox(tile)
Features
API
hash
Hash tile for unique id key
Parameters
Examples
var id = hash([312, 480, 4])
Returns number hash
bboxToCenter
Converts BBox to Center
Parameters
bbox
BBox [west, south, east, north] coordinates
Examples
var center = bboxToCenter([90, -45, 85, -50])
Returns LngLat center
lngLatToMeters
Converts LngLat coordinates to Meters coordinates.
Parameters
lnglat
LngLat Longitude (Meridians) & Latitude (Parallels) in decimal degrees
Examples
var meters = lngLatToMeters([126, 37])
Returns Meters Meters coordinates
metersToLngLat
Converts Meters coordinates to LngLat coordinates.
Parameters
meters
Meters Meters in Mercator [x, y]
Examples
var lnglat = metersToLngLat([14026255, 4439106])
Returns LngLat LngLat coordinates
metersToPixels
Converts Meters coordinates to Pixels coordinates.
Parameters
meters
Meters Meters in Mercator [x, y]zoom
number Zoom leveltileSize
[number] Tile size (optional, default 256
)
Examples
var pixels = metersToPixels([14026255, 4439106], 13)
Returns Pixels Pixels coordinates
lngLatToTile
Converts LngLat coordinates to TMS Tile.
Parameters
lnglat
LngLat Longitude (Meridians) & Latitude (Parallels) in decimal degreeszoom
number Zoom level
Examples
var tile = lngLatToTile([126, 37], 13)
Returns Tile TMS Tile
lngLatToGoogle
Converts LngLat coordinates to Google (XYZ) Tile.
Parameters
lnglat
LngLat Longitude (Meridians) & Latitude (Parallels) in decimal degreeszoom
number Zoom level
Examples
var google = lngLatToGoogle([126, 37], 13)
Returns Google Google (XYZ) Tile
metersToTile
Converts Meters coordinates to TMS Tile.
Parameters
meters
Meters Meters in Mercator [x, y]zoom
number Zoom level
Examples
var tile = metersToTile([14026255, 4439106], 13)
Returns Tile TMS Tile
pixelsToMeters
Converts Pixels coordinates to Meters coordinates.
Parameters
pixels
Pixels Pixels [x, y, zoom]tileSize
[number] Tile size (optional, default 256
)
Examples
var meters = pixelsToMeters([1782579, 1280877, 13])
Returns Meters Meters coordinates
pixelsToTile
Converts Pixels coordinates to TMS Tile.
Parameters
pixels
Pixels Pixels [x, y, zoom]tileSize
[number] Tile size (optional, default 256
)
Examples
var tile = pixelsToTile([1782579, 1280877, 13])
Returns Tile TMS Tile
tileToBBoxMeters
Converts TMS Tile to bbox in Meters coordinates.
Parameters
tile
Tile Tile [x, y, zoom]x
number TMS Tile Xy
number TMS Tile Yzoom
number Zoom leveltileSize
[number] Tile size (optional, default 256
)
Examples
var bbox = tileToBBoxMeters([6963, 5003, 13])
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
tileToBBox
Converts TMS Tile to bbox in LngLat coordinates.
Parameters
Examples
var bbox = tileToBBox([6963, 5003, 13])
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
googleToBBoxMeters
Converts Google (XYZ) Tile to bbox in Meters coordinates.
Parameters
google
Google Google [x, y, zoom]
Examples
var bbox = googleToBBoxMeters([6963, 3188, 13])
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
googleToBBox
Converts Google (XYZ) Tile to bbox in LngLat coordinates.
Parameters
google
Google Google [x, y, zoom]
Examples
var bbox = googleToBBox([6963, 3188, 13])
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
tileToGoogle
Converts TMS Tile to Google (XYZ) Tile.
Parameters
tile
Tile Tile [x, y, zoom]
Examples
var google = tileToGoogle([6963, 5003, 13])
Returns Google Google (XYZ) Tile
googleToTile
Converts Google (XYZ) Tile to TMS Tile.
Parameters
google
Google Google [x, y, zoom]
Examples
var tile = googleToTile([6963, 3188, 13])
Returns Tile TMS Tile
googleToQuadkey
Converts Google (XYZ) Tile to Quadkey.
Parameters
google
Google Google [x, y, zoom]
Examples
var quadkey = googleToQuadkey([6963, 3188, 13])
Returns string Microsoft's Quadkey schema
tileToQuadkey
Converts TMS Tile to QuadKey.
Parameters
tile
Tile Tile [x, y, zoom]
Examples
var quadkey = tileToQuadkey([6963, 5003, 13])
Returns string Microsoft's Quadkey schema
quadkeyToTile
Converts Quadkey to TMS Tile.
Parameters
quadkey
string Microsoft's Quadkey schema
Examples
var tile = quadkeyToTile('1321102330211')
Returns Tile TMS Tile
quadkeyToGoogle
Converts Quadkey to Google (XYZ) Tile.
Parameters
quadkey
string Microsoft's Quadkey schema
Examples
var google = quadkeyToGoogle('1321102330211')
Returns Google Google (XYZ) Tile
bboxToMeters
Converts BBox from LngLat coordinates to Meters coordinates
Parameters
bbox
BBox extent in [minX, minY, maxX, maxY] order
Examples
var meters = bboxToMeters([ 125, 35, 127, 37 ])
Returns BBox bbox extent in [minX, minY, maxX, maxY] order
validateTile
Validates TMS Tile.
Parameters
tile
Tile Tile [x, y, zoom]
Examples
validateTile([60, 80, 12])
validateTile([60, -43, 5])
validateTile([25, 60, 3])
- Throws Error Will throw an error if TMS Tile is not valid.
Returns Tile TMS Tile
validateZoom
Validates Zoom level
Parameters
Examples
mercator.validateZoom(12)
mercator.validateZoom(-4)
validateZoom(32)
- Throws Error Will throw an error if zoom is not valid.
Returns number zoom Zoom level
validateLngLat
Validates LngLat coordinates
Parameters
lnglat
LngLat Longitude (Meridians) & Latitude (Parallels) in decimal degrees
Examples
validateLngLat([-115, 44])
validateLngLat([-225, 44])
- Throws Error Will throw an error if LngLat is not valid.
Returns LngLat LngLat coordinates
validatePixels
Validates Pixels coordinates
Parameters
pixels
Pixels Pixels [x, y, zoom]x
number Pixels Xy
number Pixels Yzoom
[number] Zoom level
Examples
validatePixels([-115, 44])
- Throws Error Will throw an error if Pixels is not valid.
Returns Pixels Pixels coordinates
maxBBox
Maximum extent of BBox
Parameters
array
(BBox | Array<BBox>) BBox [west, south, east, north]
Examples
var bbox = maxBBox([[-20, -30, 20, 30], [-110, -30, 120, 80]])
Returns BBox Maximum BBox