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 - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

.nyc_output/7d068864ed8440fd791107939adeb7ea.json

337

index.js

@@ -10,3 +10,3 @@ "use strict";

/**
* Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913
* Converts {LatLng} coordinates to {Meters} coordinates.
*

@@ -16,7 +16,7 @@ * @name latLngToMeters

* @param {number} lng
* @param {number} zoom (Optional)
* @param {number} [zoom]
* @returns {Meters}
* @example
* latLngToMeters({lat: 45, lng: 90})
* //=> Meters { mx: 10018754.171394622, my: 5621521.486192067 }
* latLngToMeters({lat: 37, lng: 126})
* //= Meters { mx: 14026255.83995247, my: 4439106.787250587 }
*/

@@ -28,3 +28,3 @@ function latLngToMeters(init) {

/**
* Converts XY point from Spherical Mercator EPSG:900913 to lat/lng in WGS84 Datum
* Converts {Meters} coordinates to {LatLng} coordinates.
*

@@ -34,7 +34,7 @@ * @name metersToLatLng

* @param {number} my
* @param {number} zoom (Optional)
* @param {number} [zoom]
* @returns {LatLng}
* @example
* metersToLatLng({mx: 10000000, my: 5500000})
* //=> LatLng { lat: 44.2228902348575, lng: 89.83152841195214 }
* metersToLatLng({ mx: 14026255, my: 4439106 })
* //= LatLng { lat: 36.99999435205559, lng: 125.99999245457859 }
*/

@@ -46,3 +46,3 @@ function metersToLatLng(init) {

/**
* Converts EPSG:900913 to pyramid pixel coordinates in given zoom level
* Converts {Meters} coordinates to {Pixels}.
*

@@ -55,4 +55,4 @@ * @name metersToPixels

* @example
* metersToPixels({mx: 10000000, my: 5500000, zoom: 13})
* //=> Pixels { px: 1571882.5818671728, py: 1336394.6200269451, zoom: 13 }
* metersToPixels({ mx: 14026255, my: 4439106, zoom: 13 })
* //= Pixels { px: 1782579.1560447346, py: 1280877.3387406059, zoom: 13 }
*/

@@ -64,3 +64,3 @@ function metersToPixels(init) {

/**
* Returns Tile for given latlng coordinates
* Converts {LatLng} coordinates to TMS {Tile}.
*

@@ -71,6 +71,6 @@ * @name latLngToTile

* @param {number} zoom
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* latLngToTile({lat: 45, lng: 90, zoom: 5})
* //=> Tile { tx: 23, ty: 20, zoom: 5 }
* latLngToTile({lat: 37, lng: 126, zoom: 13 })
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/

@@ -82,3 +82,3 @@ function latLngToTile(init) {

/**
* Returns Google Tile for given latlng coordinates
* Converts {LatLng} coordinates to {Google} (XYZ) Tile.
*

@@ -90,4 +90,4 @@ * @name latLngToGoogle

* @example
* latLngToGoogle({lat: 45, lng: 90, zoom: 5})
* //=> Google { x: 23, y: 11, zoom: 5 }
* latLngToGoogle({lat: 37, lng: 126, zoom: 13 })
* //= Google { x: 6963, y: 3188, zoom: 13 }
*/

@@ -99,3 +99,3 @@ function latLngToGoogle(init) {

/**
* Returns Tile for given mercator coordinates
* Converts {Meters} coordinates to TMS {Tile}.
*

@@ -105,6 +105,6 @@ * @name metersToTile

* @param {number} my
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* metersToTile({mx: 10000000, my: 5500000, zoom: 5})
* //=> Tile { tx: 23, ty: 20, zoom: 5 }
* metersToTile({ mx: 14026255, my: 4439106, zoom: 13 })
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/

@@ -116,3 +116,3 @@ function metersToTile(init) {

/**
* Converts pixel coordinates in given zoom level of pyramid to EPSG:900913
* Converts {Pixels} coordinates to {Meters} coordinates.
*

@@ -124,2 +124,5 @@ * @name pixelsToMeters

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

@@ -131,3 +134,3 @@ function pixelsToMeters(init) {

/**
* Returns a Tile covering region in given pixel coordinates
* Converts {Pixels} coordinates to TMS {Tile}.
*

@@ -138,3 +141,6 @@ * @name pixelsToTile

* @param {number} zoom
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* pixelsToTile({ px: 1782579, py: 1280877, zoom: 13 })
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/

@@ -146,3 +152,3 @@ function pixelsToTile(init) {

/**
* Returns bounds of the given Tile in EPSG:900913 coordinates
* Converts TMS {Tile} to bounds in {Meters} coordinates.
*

@@ -153,3 +159,6 @@ * @name tileBounds

* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* tileBounds({ tx: 6963, ty: 5003, zoom: 13 })
* //= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ]
*/

@@ -161,16 +170,19 @@ function tileBounds(init) {

/**
* Returns bounds of the given Tile in EPSG:900913 coordinates
* Converts TMS {Tile} to bounds in {LatLng} coordinates.
*
* @name tileLatLonBounds
* @name tileLatLngBounds
* @param {number} tx
* @param {number} ty
* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* tileLatLngBounds({ tx: 6963, ty: 5003, zoom: 13 })
* //= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ]
*/
function tileLatLonBounds(init) {
return mercator.tileLatLonBounds(init);
function tileLatLngBounds(init) {
return mercator.tileLatLngBounds(init);
}
exports.tileLatLonBounds = tileLatLonBounds;
exports.tileLatLngBounds = tileLatLngBounds;
/**
* Converts Google Tile system in Mercator bounds (Meters)
* Converts {Google} (XYZ) Tile to bounds in {Meters} coordinates.
*

@@ -181,3 +193,6 @@ * @name googleBounds

* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* googleBounds({ x: 6963, y: 3188, zoom: 13 })
* //= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ]
*/

@@ -189,16 +204,19 @@ function googleBounds(init) {

/**
* Converts Google Tile system in LatLng bounds (degrees)
* Converts {Google} (XYZ) Tile to bounds in {LatLng} coordinates.
*
* @name googleLatLonBounds
* @name googleLatLngBounds
* @param {number} x
* @param {number} y
* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* googleLatLngBounds({ x: 6963, y: 3188, zoom: 13 })
* //= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ]
*/
function googleLatLonBounds(init) {
return mercator.googleLatLonBounds(init);
function googleLatLngBounds(init) {
return mercator.googleLatLngBounds(init);
}
exports.googleLatLonBounds = googleLatLonBounds;
exports.googleLatLngBounds = googleLatLngBounds;
/**
* Converts TMS Tile coordinates to Google Tile coordinates
* Converts TMS {Tile} to {Google} (XYZ) Tile.
*

@@ -209,3 +227,6 @@ * @name tileGoogle

* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* tileGoogle({ tx: 6963, ty: 5003, zoom: 13 })
* //= Google { x: 6963, y: 3188, zoom: 13 }
*/

@@ -217,3 +238,3 @@ function tileGoogle(init) {

/**
* Converts Google Tile coordinates to TMS Tile coordinates
* Converts {Google} (XYZ) Tile to TMS {Tile}.
*

@@ -224,3 +245,6 @@ * @name googleTile

* @param {number} zoom
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* googleTile({ x: 6963, y: 3188, zoom: 13 })
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/

@@ -232,84 +256,88 @@ function googleTile(init) {

/**
* Converts Google Tile coordinates to Microsoft QuadKey
* Converts {Google} (XYZ) Tile to {Quadkey}.
*
* @name googleQuadKey
* @name googleQuadkey
* @param {number} x
* @param {number} y
* @param {number} zoom
* @returns {quadkey}
* @returns {string} Quadkey
* @example
* googleQuadkey({ x: 6963, y: 3188, zoom: 13 })
* //= '1321102330211'
*/
function googleQuadKey(init) {
return mercator.googleQuadKey(init);
function googleQuadkey(init) {
return mercator.googleQuadkey(init);
}
exports.googleQuadKey = googleQuadKey;
exports.googleQuadkey = googleQuadkey;
/**
* Converts TMS Tile coordinates to Microsoft QuadKey
* Converts TMS {Tile} to {QuadKey}.
*
* @name tileQuadKey
* @name tileQuadkey
* @param {number} tx
* @param {number} ty
* @param {number} zoom
* @returns {quadkey}
* @returns {string} Quadkey
* @example
* tileQuadkey({ tx: 6963, ty: 5003, zoom: 13 })
* //= '1321102330211'
*/
function tileQuadKey(init) {
return mercator.tileQuadKey(init);
function tileQuadkey(init) {
return mercator.tileQuadkey(init);
}
exports.tileQuadKey = tileQuadKey;
exports.tileQuadkey = tileQuadkey;
/**
* Converts QuadKey to TMS Tile coordinates
* Converts {Quadkey} to TMS {Tile}.
*
* @name quadKeyTile
* @name quadkeyTile
* @param {string} quadkey
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* quadkeyTile('1321102330211')
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/
function quadKeyTile(quadkey) {
return mercator.quadKeyTile(quadkey);
function quadkeyTile(quadkey) {
return mercator.quadkeyTile(quadkey);
}
exports.quadKeyTile = quadKeyTile;
exports.quadkeyTile = quadkeyTile;
/**
* Converts QuadKey to Google Tile
* Converts {Quadkey} to {Google} (XYZ) Tile.
*
* @name quadKeyGoogle
* @name quadkeyGoogle
* @param {string} quadkey
* @returns {Google}
* @example
* quadkeyGoogle('1321102330211')
* //= Google { x: 6963, y: 3188, zoom: 13 }
*/
function quadKeyGoogle(quadkey) {
return mercator.quadKeyGoogle(quadkey);
function quadkeyGoogle(quadkey) {
return mercator.quadkeyGoogle(quadkey);
}
exports.quadKeyGoogle = quadKeyGoogle;
exports.quadkeyGoogle = quadkeyGoogle;
/**
* Converts bounds from LatLng to Meters
* Converts {bbox} from {LatLng} coordinates to {Meters} coordinates
*
* @name boundsLatLngToMeters
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} bounds
*/
function boundsLatLngToMeters(bounds) {
return mercator.boundsLatLngToMeters(bounds);
}
exports.boundsLatLngToMeters = boundsLatLngToMeters;
/**
* Validate Undefined
* @name validateUndefined
* @param {string} name
* @param {Object} items
* @name bboxLatLngToMeters
* @param {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox}
* @example
* validateUndefined('Meters', Object)
* bboxLatLngToMeters([ 125, 35, 127, 37 ])
* //= [ 13914936.349159198, 4163881.1440642904, 14137575.330745745, 4439106.787250587 ]
*/
function validateUndefined(items, name) {
for (let key of lodash_1.keys(items)) {
if (lodash_1.isUndefined(items[key])) {
const message = (name) ? `${name} <${key}> is required` : `<${key}> is required`;
exports.debug.error(message);
throw new Error(message);
}
}
function bboxLatLngToMeters(bbox) {
return mercator.bboxLatLngToMeters(bbox);
}
exports.validateUndefined = validateUndefined;
exports.bboxLatLngToMeters = bboxLatLngToMeters;
/**
* Validates Tile
* @name validateTile
* Validates TMS {Tile}.
* @param {number} tx
* @param {number} ty
* @param {number} zoom
* @param {string} [name=Tile] - name used for debugging message
* @throw Will throw an error if TMS {Tile} is not valid.
* @return {Object} TMS Tile
* @example
* const tile = validateTile({tx: 60, ty: 80, zoom: 5})
* 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
*/

@@ -333,7 +361,14 @@ function validateTile(init, name = 'Tile') {

/**
* Validates Zoom
* Validates {Zoom} level.
* @name validateZoom
* @param {number} Zoom level
* @throw Will throw an error if zoom is not valid.
* @return {number} Zoom level
* @example
* const zoom = validateZoom(12)
* validateZoom(12)
* //= 12
* validateZoom(-4)
* //= Error: <zoom> cannot be less than 1
* validateZoom(30)
* //= Error: <zoom> cannot be greater than 23
*/

@@ -355,6 +390,9 @@ function validateZoom(zoom, name) {

/**
* Validates Pixels
* Validates {Pixels} coordinates.
* @name validatePixels
* @param {Array<number>} Pixels coordinates
* @throw Will throw an error if {Pixels} is not valid.
* @return {Array<number>} Pixels coordinates
* @example
* const pixels = validatePixels([-115, 44])
* validatePixels([-115, 44])
* //= [-115, 44]

@@ -383,6 +421,9 @@ */

/**
* Validates Meters
* Validates {Meters} coordinates.
* @name validateMeters
* @param {Array<number>} Meters coordinates
* @throw Will throw an error if {Meters} is not valid.
* @return {Array<number>} Meters coordinates
* @example
* const meters = validateMeters([-115, 44])
* validateMeters([-115, 44])
* //= [-115, 44]

@@ -423,4 +464,7 @@ */

/**
* Validates LatLng
* Validates {LatLng} coordinates.
* @name validateLatLng
* @param {Array<number>} LatLng coordinates
* @throw Will throw an error if {LatLng} is not valid.
* @return {Array<number>} LatLng coordinates
* @example

@@ -436,4 +480,7 @@ * validateLatLng([-115, 44])

/**
* Validates LngLat
* Validates {LngLat} coordinates.
* @name validateLngLat
* @param {Array<number>} LngLat coordinates
* @throw Will throw an error if {LngLat} is not valid.
* @return {Array<number>} LngLat coordinates
* @example

@@ -474,7 +521,12 @@ * validateLngLat([-115, 44])

/**
* Validates bounds
* Validates bounds.
* @name bounds
* @param {Array<number>} bounds
* @throw Will throw an error if bounds is not valid.
* @returns {Array<number} bounds
* @example
* const bounds = validateBounds([ -75, 44, -74, 45 ])
* validateBounds([ -75, 44, -74, 45 ])
* //= [ -75, 44, -74, 45 ]
* validateBounds([ -75, 44, -74 ])
* //= Error: [bounds] must be an Array of 4 numbers
*/

@@ -490,2 +542,26 @@ function validateBounds(init) {

exports.validateBounds = validateBounds;
/**
* Assert undefined items within object.
* @name assertUndefined
* @param {Object} items
* @param {string} [name] - name used for debugging message
* @throw Will throw an error if any item in Object is undefined.
* @returns {Object} items
* @example
* assertUndefined({foo: 'bar'})
* //= {foo: 'bar'}
* assertUndefined({foo: undefined})
* //= Error: <foo> is required
*/
function assertUndefined(items, name) {
for (let key of lodash_1.keys(items)) {
if (lodash_1.isUndefined(items[key])) {
const message = (name) ? `${name} <${key}> is required` : `<${key}> is required`;
exports.debug.error(message);
throw new Error(message);
}
}
return items;
}
exports.assertUndefined = assertUndefined;
class Google {

@@ -497,3 +573,3 @@ constructor(init) {

this.zoom = zoom;
validateUndefined(this, 'Google');
assertUndefined(this, 'Google');
}

@@ -508,3 +584,3 @@ }

this.zoom = zoom;
validateUndefined(this, 'Tile');
assertUndefined(this, 'Tile');
validateTile(this);

@@ -522,3 +598,3 @@ }

}
validateUndefined(this, 'Pixels');
assertUndefined(this, 'Pixels');
validatePixels([px, py]);

@@ -536,3 +612,3 @@ }

}
validateUndefined(this, 'Meters');
assertUndefined(this, 'Meters');
validateMeters([mx, my]);

@@ -550,3 +626,3 @@ }

}
validateUndefined(this, 'LatLng');
assertUndefined(this, 'LatLng');
validateLatLng([lat, lng]);

@@ -559,3 +635,3 @@ }

this.name = 'GlobalMercator';
this.boundsLatLngToMeters = (bounds) => {
this.bboxLatLngToMeters = (bounds) => {
const min = this.latLngToMeters({ lat: bounds[1], lng: bounds[0] });

@@ -645,3 +721,3 @@ const max = this.latLngToMeters({ lat: bounds[3], lng: bounds[2] });

}
tileLatLonBounds(init) {
tileLatLngBounds(init) {
if (init.zoom === 0) {

@@ -660,5 +736,5 @@ return [-180, -85.05112877980659, 180, 85.05112877980659];

}
googleLatLonBounds(init) {
googleLatLngBounds(init) {
const Tile = this.googleTile(init);
return this.tileLatLonBounds(Tile);
return this.tileLatLngBounds(Tile);
}

@@ -680,8 +756,8 @@ tileGoogle(init) {

}
googleQuadKey(init) {
googleQuadkey(init) {
const Tile = this.googleTile(init);
return this.tileQuadKey(Tile);
return this.tileQuadkey(Tile);
}
tileQuadKey(init) {
// Zoom 0 does not exist for QuadKey
tileQuadkey(init) {
// Zoom 0 does not exist for Quadkey
if (init.zoom === 0) {

@@ -706,7 +782,7 @@ return '';

}
quadKeyTile(quadkey) {
const Google = this.quadKeyGoogle(quadkey);
quadkeyTile(quadkey) {
const Google = this.quadkeyGoogle(quadkey);
return this.googleTile(Google);
}
quadKeyGoogle(quadkey) {
quadkeyGoogle(quadkey) {
let x = 0;

@@ -731,3 +807,3 @@ let y = 0;

default:
throw new Error('Invalid QuadKey digit sequence');
throw new Error('Invalid Quadkey digit sequence');
}

@@ -749,14 +825,14 @@ });

tileBounds: tileBounds,
tileLatLonBounds: tileLatLonBounds,
tileLatLngBounds: tileLatLngBounds,
tileGoogle: tileGoogle,
tileQuadKey: tileQuadKey,
quadKeyGoogle: quadKeyGoogle,
quadKeyTile: quadKeyTile,
tileQuadkey: tileQuadkey,
quadkeyGoogle: quadkeyGoogle,
quadkeyTile: quadkeyTile,
googleBounds: googleBounds,
googleLatLonBounds: googleLatLonBounds,
googleQuadKey: googleQuadKey,
googleLatLngBounds: googleLatLngBounds,
googleQuadkey: googleQuadkey,
};
/* istanbul ignore next */
if (require.main === module) {
// const bounds = boundsLatLngToMeters([ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ])
// const bounds = bboxLatLngToMeters([ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ])
// console.log(bounds)

@@ -772,3 +848,3 @@ // const meters = pixelsToMeters({ px: 611669, py: 1342753, zoom: 13 })

// validatePixels([200000, 150000, 1])
// validateUndefined({x: null})
// assertUndefined({x: null})
// console.log(metersToLatLng({mx: 10018754.171394622, my: 5621521.486192067}))

@@ -778,3 +854,4 @@ // console.log(metersToPixels({mx: 10000000, my: 5500000, zoom: 13}))

console.log(latLngToMeters({ lat: 23, lng: 23 }));
console.log(validateBounds([-75, 44, -74]));
}
//# sourceMappingURL=index.js.map

@@ -42,3 +42,3 @@ import * as Debug from 'debug'

/**
* Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913
* Converts {LatLng} coordinates to {Meters} coordinates.
*

@@ -48,7 +48,7 @@ * @name latLngToMeters

* @param {number} lng
* @param {number} zoom (Optional)
* @param {number} [zoom]
* @returns {Meters}
* @example
* latLngToMeters({lat: 45, lng: 90})
* //=> Meters { mx: 10018754.171394622, my: 5621521.486192067 }
* latLngToMeters({lat: 37, lng: 126})
* //= Meters { mx: 14026255.83995247, my: 4439106.787250587 }
*/

@@ -60,3 +60,3 @@ export function latLngToMeters(init: InterfaceLatLng) {

/**
* Converts XY point from Spherical Mercator EPSG:900913 to lat/lng in WGS84 Datum
* Converts {Meters} coordinates to {LatLng} coordinates.
*

@@ -66,7 +66,7 @@ * @name metersToLatLng

* @param {number} my
* @param {number} zoom (Optional)
* @param {number} [zoom]
* @returns {LatLng}
* @example
* metersToLatLng({mx: 10000000, my: 5500000})
* //=> LatLng { lat: 44.2228902348575, lng: 89.83152841195214 }
* metersToLatLng({ mx: 14026255, my: 4439106 })
* //= LatLng { lat: 36.99999435205559, lng: 125.99999245457859 }
*/

@@ -78,3 +78,3 @@ export function metersToLatLng(init: InterfaceMeters) {

/**
* Converts EPSG:900913 to pyramid pixel coordinates in given zoom level
* Converts {Meters} coordinates to {Pixels}.
*

@@ -87,4 +87,4 @@ * @name metersToPixels

* @example
* metersToPixels({mx: 10000000, my: 5500000, zoom: 13})
* //=> Pixels { px: 1571882.5818671728, py: 1336394.6200269451, zoom: 13 }
* metersToPixels({ mx: 14026255, my: 4439106, zoom: 13 })
* //= Pixels { px: 1782579.1560447346, py: 1280877.3387406059, zoom: 13 }
*/

@@ -96,3 +96,3 @@ export function metersToPixels(init: InterfaceMeters) {

/**
* Returns Tile for given latlng coordinates
* Converts {LatLng} coordinates to TMS {Tile}.
*

@@ -103,6 +103,6 @@ * @name latLngToTile

* @param {number} zoom
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* latLngToTile({lat: 45, lng: 90, zoom: 5})
* //=> Tile { tx: 23, ty: 20, zoom: 5 }
* latLngToTile({lat: 37, lng: 126, zoom: 13 })
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/

@@ -114,3 +114,3 @@ export function latLngToTile(init: InterfaceLatLng) {

/**
* Returns Google Tile for given latlng coordinates
* Converts {LatLng} coordinates to {Google} (XYZ) Tile.
*

@@ -122,4 +122,4 @@ * @name latLngToGoogle

* @example
* latLngToGoogle({lat: 45, lng: 90, zoom: 5})
* //=> Google { x: 23, y: 11, zoom: 5 }
* latLngToGoogle({lat: 37, lng: 126, zoom: 13 })
* //= Google { x: 6963, y: 3188, zoom: 13 }
*/

@@ -131,3 +131,3 @@ export function latLngToGoogle(init: InterfaceLatLng) {

/**
* Returns Tile for given mercator coordinates
* Converts {Meters} coordinates to TMS {Tile}.
*

@@ -137,6 +137,6 @@ * @name metersToTile

* @param {number} my
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* metersToTile({mx: 10000000, my: 5500000, zoom: 5})
* //=> Tile { tx: 23, ty: 20, zoom: 5 }
* metersToTile({ mx: 14026255, my: 4439106, zoom: 13 })
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/

@@ -148,3 +148,3 @@ export function metersToTile(init: Meters) {

/**
* Converts pixel coordinates in given zoom level of pyramid to EPSG:900913
* Converts {Pixels} coordinates to {Meters} coordinates.
*

@@ -156,2 +156,5 @@ * @name pixelsToMeters

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

@@ -163,3 +166,3 @@ export function pixelsToMeters(init: Pixels) {

/**
* Returns a Tile covering region in given pixel coordinates
* Converts {Pixels} coordinates to TMS {Tile}.
*

@@ -170,3 +173,6 @@ * @name pixelsToTile

* @param {number} zoom
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* pixelsToTile({ px: 1782579, py: 1280877, zoom: 13 })
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/

@@ -178,3 +184,3 @@ export function pixelsToTile(init: Pixels) {

/**
* Returns bounds of the given Tile in EPSG:900913 coordinates
* Converts TMS {Tile} to bounds in {Meters} coordinates.
*

@@ -185,3 +191,6 @@ * @name tileBounds

* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* tileBounds({ tx: 6963, ty: 5003, zoom: 13 })
* //= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ]
*/

@@ -193,16 +202,19 @@ export function tileBounds(init: Tile) {

/**
* Returns bounds of the given Tile in EPSG:900913 coordinates
* Converts TMS {Tile} to bounds in {LatLng} coordinates.
*
* @name tileLatLonBounds
* @name tileLatLngBounds
* @param {number} tx
* @param {number} ty
* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* tileLatLngBounds({ tx: 6963, ty: 5003, zoom: 13 })
* //= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ]
*/
export function tileLatLonBounds(init: Tile) {
return mercator.tileLatLonBounds(init)
export function tileLatLngBounds(init: Tile) {
return mercator.tileLatLngBounds(init)
}
/**
* Converts Google Tile system in Mercator bounds (Meters)
* Converts {Google} (XYZ) Tile to bounds in {Meters} coordinates.
*

@@ -213,3 +225,6 @@ * @name googleBounds

* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* googleBounds({ x: 6963, y: 3188, zoom: 13 })
* //= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ]
*/

@@ -221,16 +236,19 @@ export function googleBounds(init: Google) {

/**
* Converts Google Tile system in LatLng bounds (degrees)
* Converts {Google} (XYZ) Tile to bounds in {LatLng} coordinates.
*
* @name googleLatLonBounds
* @name googleLatLngBounds
* @param {number} x
* @param {number} y
* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* googleLatLngBounds({ x: 6963, y: 3188, zoom: 13 })
* //= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ]
*/
export function googleLatLonBounds(init: Google) {
return mercator.googleLatLonBounds(init)
export function googleLatLngBounds(init: Google) {
return mercator.googleLatLngBounds(init)
}
/**
* Converts TMS Tile coordinates to Google Tile coordinates
* Converts TMS {Tile} to {Google} (XYZ) Tile.
*

@@ -241,3 +259,6 @@ * @name tileGoogle

* @param {number} zoom
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @example
* tileGoogle({ tx: 6963, ty: 5003, zoom: 13 })
* //= Google { x: 6963, y: 3188, zoom: 13 }
*/

@@ -249,3 +270,3 @@ export function tileGoogle(init: Tile) {

/**
* Converts Google Tile coordinates to TMS Tile coordinates
* Converts {Google} (XYZ) Tile to TMS {Tile}.
*

@@ -256,3 +277,6 @@ * @name googleTile

* @param {number} zoom
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* googleTile({ x: 6963, y: 3188, zoom: 13 })
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/

@@ -264,84 +288,88 @@ export function googleTile(init: Google) {

/**
* Converts Google Tile coordinates to Microsoft QuadKey
* Converts {Google} (XYZ) Tile to {Quadkey}.
*
* @name googleQuadKey
* @name googleQuadkey
* @param {number} x
* @param {number} y
* @param {number} zoom
* @returns {quadkey}
* @returns {string} Quadkey
* @example
* googleQuadkey({ x: 6963, y: 3188, zoom: 13 })
* //= '1321102330211'
*/
export function googleQuadKey(init: Google) {
return mercator.googleQuadKey(init)
export function googleQuadkey(init: Google) {
return mercator.googleQuadkey(init)
}
/**
* Converts TMS Tile coordinates to Microsoft QuadKey
* Converts TMS {Tile} to {QuadKey}.
*
* @name tileQuadKey
* @name tileQuadkey
* @param {number} tx
* @param {number} ty
* @param {number} zoom
* @returns {quadkey}
* @returns {string} Quadkey
* @example
* tileQuadkey({ tx: 6963, ty: 5003, zoom: 13 })
* //= '1321102330211'
*/
export function tileQuadKey(init: Tile) {
return mercator.tileQuadKey(init)
export function tileQuadkey(init: Tile) {
return mercator.tileQuadkey(init)
}
/**
* Converts QuadKey to TMS Tile coordinates
* Converts {Quadkey} to TMS {Tile}.
*
* @name quadKeyTile
* @name quadkeyTile
* @param {string} quadkey
* @returns {Tile}
* @returns {Tile} TMS Tile
* @example
* quadkeyTile('1321102330211')
* //= Tile { tx: 6963, ty: 5003, zoom: 13 }
*/
export function quadKeyTile(quadkey: string) {
return mercator.quadKeyTile(quadkey)
export function quadkeyTile(quadkey: string) {
return mercator.quadkeyTile(quadkey)
}
/**
* Converts QuadKey to Google Tile
* Converts {Quadkey} to {Google} (XYZ) Tile.
*
* @name quadKeyGoogle
* @name quadkeyGoogle
* @param {string} quadkey
* @returns {Google}
* @example
* quadkeyGoogle('1321102330211')
* //= Google { x: 6963, y: 3188, zoom: 13 }
*/
export function quadKeyGoogle(quadkey: string) {
return mercator.quadKeyGoogle(quadkey)
export function quadkeyGoogle(quadkey: string) {
return mercator.quadkeyGoogle(quadkey)
}
/**
* Converts bounds from LatLng to Meters
* Converts {bbox} from {LatLng} coordinates to {Meters} coordinates
*
* @name boundsLatLngToMeters
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} bounds
*/
export function boundsLatLngToMeters(bounds: number[]): number[] {
return mercator.boundsLatLngToMeters(bounds)
}
/**
* Validate Undefined
* @name validateUndefined
* @param {string} name
* @param {Object} items
* @name bboxLatLngToMeters
* @param {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order
* @returns {Array<number>} {bbox}
* @example
* validateUndefined('Meters', Object)
* bboxLatLngToMeters([ 125, 35, 127, 37 ])
* //= [ 13914936.349159198, 4163881.1440642904, 14137575.330745745, 4439106.787250587 ]
*/
export function validateUndefined(items: any, name?: string) {
for (let key of keys(items)) {
if (isUndefined(items[key])) {
const message = (name) ? `${ name } <${ key }> is required` : `<${ key }> is required`
debug.error(message)
throw new Error(message)
}
}
export function bboxLatLngToMeters(bbox: number[]): number[] {
return mercator.bboxLatLngToMeters(bbox)
}
/**
* Validates Tile
* @name validateTile
* Validates TMS {Tile}.
* @param {number} tx
* @param {number} ty
* @param {number} zoom
* @param {string} [name=Tile] - name used for debugging message
* @throw Will throw an error if TMS {Tile} is not valid.
* @return {Object} TMS Tile
* @example
* const tile = validateTile({tx: 60, ty: 80, zoom: 5})
* 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
*/

@@ -364,7 +392,14 @@ export function validateTile(init: InterfaceTile, name = 'Tile') {

/**
* Validates Zoom
* Validates {Zoom} level.
* @name validateZoom
* @param {number} Zoom level
* @throw Will throw an error if zoom is not valid.
* @return {number} Zoom level
* @example
* const zoom = validateZoom(12)
* validateZoom(12)
* //= 12
* validateZoom(-4)
* //= Error: <zoom> cannot be less than 1
* validateZoom(30)
* //= Error: <zoom> cannot be greater than 23
*/

@@ -385,6 +420,9 @@ export function validateZoom(zoom: number, name?: string) {

/**
* Validates Pixels
* Validates {Pixels} coordinates.
* @name validatePixels
* @param {Array<number>} Pixels coordinates
* @throw Will throw an error if {Pixels} is not valid.
* @return {Array<number>} Pixels coordinates
* @example
* const pixels = validatePixels([-115, 44])
* validatePixels([-115, 44])
* //= [-115, 44]

@@ -413,6 +451,9 @@ */

/**
* Validates Meters
* Validates {Meters} coordinates.
* @name validateMeters
* @param {Array<number>} Meters coordinates
* @throw Will throw an error if {Meters} is not valid.
* @return {Array<number>} Meters coordinates
* @example
* const meters = validateMeters([-115, 44])
* validateMeters([-115, 44])
* //= [-115, 44]

@@ -453,4 +494,7 @@ */

/**
* Validates LatLng
* Validates {LatLng} coordinates.
* @name validateLatLng
* @param {Array<number>} LatLng coordinates
* @throw Will throw an error if {LatLng} is not valid.
* @return {Array<number>} LatLng coordinates
* @example

@@ -466,4 +510,7 @@ * validateLatLng([-115, 44])

/**
* Validates LngLat
* Validates {LngLat} coordinates.
* @name validateLngLat
* @param {Array<number>} LngLat coordinates
* @throw Will throw an error if {LngLat} is not valid.
* @return {Array<number>} LngLat coordinates
* @example

@@ -503,7 +550,12 @@ * validateLngLat([-115, 44])

/**
* Validates bounds
* Validates bounds.
* @name bounds
* @param {Array<number>} bounds
* @throw Will throw an error if bounds is not valid.
* @returns {Array<number} bounds
* @example
* const bounds = validateBounds([ -75, 44, -74, 45 ])
* validateBounds([ -75, 44, -74, 45 ])
* //= [ -75, 44, -74, 45 ]
* validateBounds([ -75, 44, -74 ])
* //= Error: [bounds] must be an Array of 4 numbers
*/

@@ -519,2 +571,26 @@ export function validateBounds(init: number[]) {

/**
* Assert undefined items within object.
* @name assertUndefined
* @param {Object} items
* @param {string} [name] - name used for debugging message
* @throw Will throw an error if any item in Object is undefined.
* @returns {Object} items
* @example
* assertUndefined({foo: 'bar'})
* //= {foo: 'bar'}
* assertUndefined({foo: undefined})
* //= Error: <foo> is required
*/
export function assertUndefined(items: any, name?: string) {
for (let key of keys(items)) {
if (isUndefined(items[key])) {
const message = (name) ? `${ name } <${ key }> is required` : `<${ key }> is required`
debug.error(message)
throw new Error(message)
}
}
return items
}
export class Google {

@@ -530,3 +606,3 @@ public x: number

this.zoom = zoom
validateUndefined(this, 'Google')
assertUndefined(this, 'Google')
}

@@ -545,3 +621,3 @@ }

this.zoom = zoom
validateUndefined(this, 'Tile')
assertUndefined(this, 'Tile')
validateTile(this)

@@ -561,3 +637,3 @@ }

if (!isUndefined(zoom)) { this.zoom = zoom }
validateUndefined(this, 'Pixels')
assertUndefined(this, 'Pixels')
validatePixels([px, py])

@@ -577,3 +653,3 @@ }

if (!isUndefined(zoom)) { this.zoom = zoom }
validateUndefined(this, 'Meters')
assertUndefined(this, 'Meters')
validateMeters([mx, my])

@@ -593,3 +669,3 @@ }

if (!isUndefined(init.zoom)) { this.zoom = init.zoom }
validateUndefined(this, 'LatLng')
assertUndefined(this, 'LatLng')
validateLatLng([lat, lng])

@@ -691,3 +767,3 @@ }

public tileLatLonBounds(init: Tile) {
public tileLatLngBounds(init: Tile) {
if (init.zoom === 0) { return [ -180, -85.05112877980659, 180, 85.05112877980659 ] }

@@ -708,8 +784,8 @@

public googleLatLonBounds(init: Google) {
public googleLatLngBounds(init: Google) {
const Tile = this.googleTile(init)
return this.tileLatLonBounds(Tile)
return this.tileLatLngBounds(Tile)
}
public boundsLatLngToMeters = (bounds: number[]): number[] => {
public bboxLatLngToMeters = (bounds: number[]): number[] => {
const min = this.latLngToMeters({lat: bounds[1], lng: bounds[0]})

@@ -738,9 +814,9 @@ const max = this.latLngToMeters({lat: bounds[3], lng: bounds[2]})

public googleQuadKey(init: Google) {
public googleQuadkey(init: Google) {
const Tile = this.googleTile(init)
return this.tileQuadKey(Tile)
return this.tileQuadkey(Tile)
}
public tileQuadKey(init: Tile) {
// Zoom 0 does not exist for QuadKey
public tileQuadkey(init: Tile) {
// Zoom 0 does not exist for Quadkey
if (init.zoom === 0) { return '' }

@@ -763,8 +839,8 @@

public quadKeyTile(quadkey: string) {
const Google = this.quadKeyGoogle(quadkey)
public quadkeyTile(quadkey: string) {
const Google = this.quadkeyGoogle(quadkey)
return this.googleTile(Google)
}
public quadKeyGoogle(quadkey: string) {
public quadkeyGoogle(quadkey: string) {
let x: number = 0

@@ -791,3 +867,3 @@ let y: number = 0

default:
throw new Error('Invalid QuadKey digit sequence')
throw new Error('Invalid Quadkey digit sequence')
}

@@ -809,10 +885,10 @@ })

tileBounds,
tileLatLonBounds,
tileLatLngBounds,
tileGoogle,
tileQuadKey,
quadKeyGoogle,
quadKeyTile,
tileQuadkey,
quadkeyGoogle,
quadkeyTile,
googleBounds,
googleLatLonBounds,
googleQuadKey,
googleLatLngBounds,
googleQuadkey,
}

@@ -822,3 +898,3 @@

if (require.main === module) {
// const bounds = boundsLatLngToMeters([ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ])
// const bounds = bboxLatLngToMeters([ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ])
// console.log(bounds)

@@ -834,3 +910,3 @@ // const meters = pixelsToMeters({ px: 611669, py: 1342753, zoom: 13 })

// validatePixels([200000, 150000, 1])
// validateUndefined({x: null})
// assertUndefined({x: null})
// console.log(metersToLatLng({mx: 10018754.171394622, my: 5621521.486192067}))

@@ -840,2 +916,3 @@ // console.log(metersToPixels({mx: 10000000, my: 5500000, zoom: 13}))

console.log(latLngToMeters({lat: 23, lng: 23}))
console.log(validateBounds([ -75, 44, -74 ]))
}
{
"name": "global-mercator",
"version": "0.1.7",
"version": "0.2.0",
"description": "Global Mercator",

@@ -8,3 +8,3 @@ "main": "index.js",

"docs": "npm run build && npm run documentation",
"documentation": "./node_modules/documentation/bin/documentation.js build index.js -f md > README.md",
"documentation": "./node_modules/documentation/bin/documentation.js build index.js -f md -c documentation.yml > API.md && cat HEADER.md API.md > README.md",
"typings": "./node_modules/typings/dist/bin.js install",

@@ -11,0 +11,0 @@ "test": "npm run build && npm run ava && npm run lint",

@@ -1,3 +0,10 @@

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
[![Build Status](https://travis-ci.org/DenisCarriere/global-mercator.svg?branch=master)](https://travis-ci.org/DenisCarriere/global-mercator)
[![Coverage Status](https://coveralls.io/repos/github/DenisCarriere/global-mercator/badge.svg?branch=master)](https://coveralls.io/github/DenisCarriere/global-mercator?branch=master)
# 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

@@ -14,12 +21,13 @@

```javascript
// Load all functions
import * as mercator from 'global-mercator'
// Load a single function
import { latLngToMeters } from 'global-mercator'
```
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
# latLngToMeters
Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913
Converts {LatLng} coordinates to {Meters} coordinates.

@@ -30,3 +38,3 @@ **Parameters**

- `lng` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `zoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** (Optional)
- `zoom` **\[[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]**

@@ -36,11 +44,11 @@ **Examples**

```javascript
latLngToMeters({lat: 45, lng: 90})
//=> Meters { mx: 10018754.171394622, my: 5621521.486192067 }
latLngToMeters({lat: 37, lng: 126})
//= Meters { mx: 14026255.83995247, my: 4439106.787250587 }
```
Returns **Meters**
Returns **[Meters](https://en.wikipedia.org/wiki/Web_Mercator)**
# metersToLatLng
Converts XY point from Spherical Mercator EPSG:900913 to lat/lng in WGS84 Datum
Converts {Meters} coordinates to {LatLng} coordinates.

@@ -51,3 +59,3 @@ **Parameters**

- `my` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `zoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** (Optional)
- `zoom` **\[[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]**

@@ -57,11 +65,11 @@ **Examples**

```javascript
metersToLatLng({mx: 10000000, my: 5500000})
//=> LatLng { lat: 44.2228902348575, lng: 89.83152841195214 }
metersToLatLng({ mx: 14026255, my: 4439106 })
//= LatLng { lat: 36.99999435205559, lng: 125.99999245457859 }
```
Returns **LatLng**
Returns **[LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System)**
# metersToPixels
Converts EPSG:900913 to pyramid pixel coordinates in given zoom level
Converts {Meters} coordinates to {Pixels}.

@@ -77,11 +85,11 @@ **Parameters**

```javascript
metersToPixels({mx: 10000000, my: 5500000, zoom: 13})
//=> Pixels { px: 1571882.5818671728, py: 1336394.6200269451, zoom: 13 }
metersToPixels({ mx: 14026255, my: 4439106, zoom: 13 })
//= Pixels { px: 1782579.1560447346, py: 1280877.3387406059, zoom: 13 }
```
Returns **Pixels**
Returns **[Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx)**
# latLngToTile
Returns Tile for given latlng coordinates
Converts {LatLng} coordinates to TMS {Tile}.

@@ -97,11 +105,11 @@ **Parameters**

```javascript
latLngToTile({lat: 45, lng: 90, zoom: 5})
//=> Tile { tx: 23, ty: 20, zoom: 5 }
latLngToTile({lat: 37, lng: 126, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
```
Returns **Tile**
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile
# latLngToGoogle
Returns Google Tile for given latlng coordinates
Converts {LatLng} coordinates to {Google} (XYZ) Tile.

@@ -116,11 +124,11 @@ **Parameters**

```javascript
latLngToGoogle({lat: 45, lng: 90, zoom: 5})
//=> Google { x: 23, y: 11, zoom: 5 }
latLngToGoogle({lat: 37, lng: 126, zoom: 13 })
//= Google { x: 6963, y: 3188, zoom: 13 }
```
Returns **Google** Google Tile
Returns **[Google](https://en.wikipedia.org/wiki/Tiled_web_map)** Google Tile
# metersToTile
Returns Tile for given mercator coordinates
Converts {Meters} coordinates to TMS {Tile}.

@@ -135,11 +143,11 @@ **Parameters**

```javascript
metersToTile({mx: 10000000, my: 5500000, zoom: 5})
//=> Tile { tx: 23, ty: 20, zoom: 5 }
metersToTile({ mx: 14026255, my: 4439106, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
```
Returns **Tile**
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile
# pixelsToMeters
Converts pixel coordinates in given zoom level of pyramid to EPSG:900913
Converts {Pixels} coordinates to {Meters} coordinates.

@@ -152,7 +160,14 @@ **Parameters**

Returns **Meters**
**Examples**
```javascript
pixelsToMeters({ px: 1782579, py: 1280877, zoom: 13 })
//= Meters { mx: 14026252.018101055, my: 4439099.526918683, zoom: 13 }
```
Returns **[Meters](https://en.wikipedia.org/wiki/Web_Mercator)**
# pixelsToTile
Returns a Tile covering region in given pixel coordinates
Converts {Pixels} coordinates to TMS {Tile}.

@@ -165,7 +180,14 @@ **Parameters**

Returns **Tile**
**Examples**
```javascript
pixelsToTile({ px: 1782579, py: 1280877, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
```
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile
# tileBounds
Returns bounds of the given Tile in EPSG:900913 coordinates
Converts TMS {Tile} to bounds in {Meters} coordinates.

@@ -178,8 +200,15 @@ **Parameters**

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order
**Examples**
# tileLatLonBounds
```javascript
tileBounds({ tx: 6963, ty: 5003, zoom: 13 })
//= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ]
```
Returns bounds of the given Tile in EPSG:900913 coordinates
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order
# tileLatLngBounds
Converts TMS {Tile} to bounds in {LatLng} coordinates.
**Parameters**

@@ -191,7 +220,14 @@

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order
**Examples**
```javascript
tileLatLngBounds({ tx: 6963, ty: 5003, zoom: 13 })
//= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ]
```
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order
# googleBounds
Converts Google Tile system in Mercator bounds (Meters)
Converts {Google} (XYZ) Tile to bounds in {Meters} coordinates.

@@ -204,8 +240,15 @@ **Parameters**

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order
**Examples**
# googleLatLonBounds
```javascript
googleBounds({ x: 6963, y: 3188, zoom: 13 })
//= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ]
```
Converts Google Tile system in LatLng bounds (degrees)
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order
# googleLatLngBounds
Converts {Google} (XYZ) Tile to bounds in {LatLng} coordinates.
**Parameters**

@@ -217,7 +260,14 @@

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order
**Examples**
```javascript
googleLatLngBounds({ x: 6963, y: 3188, zoom: 13 })
//= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ]
```
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order
# tileGoogle
Converts TMS Tile coordinates to Google Tile coordinates
Converts TMS {Tile} to {Google} (XYZ) Tile.

@@ -230,7 +280,14 @@ **Parameters**

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order
**Examples**
```javascript
tileGoogle({ tx: 6963, ty: 5003, zoom: 13 })
//= Google { x: 6963, y: 3188, zoom: 13 }
```
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order
# googleTile
Converts Google Tile coordinates to TMS Tile coordinates
Converts {Google} (XYZ) Tile to TMS {Tile}.

@@ -243,8 +300,15 @@ **Parameters**

Returns **Tile**
**Examples**
# googleQuadKey
```javascript
googleTile({ x: 6963, y: 3188, zoom: 13 })
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
```
Converts Google Tile coordinates to Microsoft QuadKey
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile
# googleQuadkey
Converts {Google} (XYZ) Tile to {Quadkey}.
**Parameters**

@@ -256,8 +320,15 @@

Returns **quadkey**
**Examples**
# tileQuadKey
```javascript
googleQuadkey({ x: 6963, y: 3188, zoom: 13 })
//= '1321102330211'
```
Converts TMS Tile coordinates to Microsoft QuadKey
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Quadkey
# tileQuadkey
Converts TMS {Tile} to {QuadKey}.
**Parameters**

@@ -269,8 +340,15 @@

Returns **quadkey**
**Examples**
# quadKeyTile
```javascript
tileQuadkey({ tx: 6963, ty: 5003, zoom: 13 })
//= '1321102330211'
```
Converts QuadKey to TMS Tile coordinates
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Quadkey
# quadkeyTile
Converts {Quadkey} to TMS {Tile}.
**Parameters**

@@ -280,32 +358,31 @@

Returns **Tile**
**Examples**
# quadKeyGoogle
```javascript
quadkeyTile('1321102330211')
//= Tile { tx: 6963, ty: 5003, zoom: 13 }
```
Converts QuadKey to Google Tile
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile
**Parameters**
# quadkeyGoogle
- `quadkey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
Converts {Quadkey} to {Google} (XYZ) Tile.
Returns **Google**
# boundsLatLngToMeters
Converts bounds from LatLng to Meters
**Parameters**
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** extent in [minX, minY, maxX, maxY] order
- `quadkey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bounds
**Examples**
# validateUndefined
```javascript
quadkeyGoogle('1321102330211')
//= Google { x: 6963, y: 3188, zoom: 13 }
```
Validate Undefined
Returns **[Google](https://en.wikipedia.org/wiki/Tiled_web_map)**
**Parameters**
# bboxLatLngToMeters
- `name` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `items` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
Converts {bbox} from {LatLng} coordinates to {Meters} coordinates

@@ -315,53 +392,94 @@ **Examples**

```javascript
validateUndefined('Meters', Object)
bboxLatLngToMeters([ 125, 35, 127, 37 ])
//= [ 13914936.349159198, 4163881.1440642904, 14137575.330745745, 4439106.787250587 ]
```
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox}
# validateTile
Validates Tile
Validates TMS {Tile}.
**Parameters**
- `tx` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `ty` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `zoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `init`
- `name` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** name used for debugging message (optional, default `Tile`)
**Examples**
```javascript
const tile = validateTile({tx: 60, ty: 80, zoom: 5})
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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile
# validateZoom
Validates Zoom
Validates {Zoom} level.
**Parameters**
- `Zoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** level
**Examples**
```javascript
const zoom = validateZoom(12)
validateZoom(12)
//= 12
validateZoom(-4)
//= Error: <zoom> cannot be less than 1
validateZoom(30)
//= Error: <zoom> cannot be greater than 23
```
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Zoom level
# validatePixels
Validates Pixels
Validates {Pixels} coordinates.
**Parameters**
- `Pixels` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** coordinates
**Examples**
```javascript
const pixels = validatePixels([-115, 44])
validatePixels([-115, 44])
//= [-115, 44]
```
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** Pixels coordinates
# validateMeters
Validates Meters
Validates {Meters} coordinates.
**Parameters**
- `Meters` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** coordinates
**Examples**
```javascript
const meters = validateMeters([-115, 44])
validateMeters([-115, 44])
//= [-115, 44]
```
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** Meters coordinates
# validateLatLng
Validates LatLng
Validates {LatLng} coordinates.
**Parameters**
- `LatLng` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** coordinates
**Examples**

@@ -374,6 +492,12 @@

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** LatLng coordinates
# validateLngLat
Validates LngLat
Validates {LngLat} coordinates.
**Parameters**
- `LngLat` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** coordinates
**Examples**

@@ -386,11 +510,39 @@

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** LngLat coordinates
# bounds
Validates bounds
Validates bounds.
**Parameters**
- `bounds` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>**
**Examples**
```javascript
const bounds = validateBounds([ -75, 44, -74, 45 ])
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**
- `items` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `name` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** name used for debugging message
**Examples**
```javascript
assertUndefined({foo: 'bar'})
//= {foo: 'bar'}
assertUndefined({foo: undefined})
//= Error: <foo> is required
```
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** items

@@ -49,3 +49,3 @@ "use strict";

ava_1.default('tileLatLonBounds', t => {
const bounds = mercator.tileLatLonBounds(TILE);
const bounds = mercator.tileLatLngBounds(TILE);
t.deepEqual(bounds, BOUNDS_LATLNG);

@@ -57,16 +57,16 @@ });

});
ava_1.default('tileQuadKey', t => {
const quadkey = mercator.tileQuadKey(TILE);
ava_1.default('tileQuadkey', t => {
const quadkey = mercator.tileQuadkey(TILE);
t.deepEqual(quadkey, QUADKEY);
});
ava_1.default('quadKeyGoogle', t => {
const google = mercator.quadKeyGoogle(QUADKEY);
const google = mercator.quadkeyGoogle(QUADKEY);
t.deepEqual(google, lodash_1.pick(GOOGLE, ['x', 'y', 'zoom']));
});
ava_1.default('quadKeyTile', t => {
const tile = mercator.quadKeyTile(QUADKEY);
const tile = mercator.quadkeyTile(QUADKEY);
t.deepEqual(tile, lodash_1.pick(TILE, ['tx', 'ty', 'zoom']));
});
ava_1.default('Throws Error quadKeyTile', t => {
t.throws(() => mercator.quadKeyTile(QUADKEY_BAD), 'Invalid QuadKey digit sequence');
ava_1.default('Throws Error quadkeyTile', t => {
t.throws(() => mercator.quadkeyTile(QUADKEY_BAD), 'Invalid Quadkey digit sequence');
});

@@ -78,3 +78,3 @@ ava_1.default('googleBounds', t => {

ava_1.default('googleLatLonBounds', t => {
const bounds = mercator.googleLatLonBounds(GOOGLE);
const bounds = mercator.googleLatLngBounds(GOOGLE);
t.deepEqual(bounds, BOUNDS_LATLNG);

@@ -87,3 +87,3 @@ });

ava_1.default('googleQuadKey', t => {
const quadkey = mercator.googleQuadKey(GOOGLE);
const quadkey = mercator.googleQuadkey(GOOGLE);
t.deepEqual(quadkey, QUADKEY);

@@ -103,5 +103,5 @@ });

});
ava_1.default('boundsLatLngToMeters', t => {
const bounds = mercator.boundsLatLngToMeters(BOUNDS_LATLNG);
t.deepEqual(bounds.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2)));
ava_1.default('bboxLatLngToMeters', t => {
const bbox = mercator.bboxLatLngToMeters(BOUNDS_LATLNG);
t.deepEqual(bbox.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2)));
});

@@ -145,3 +145,3 @@ ava_1.default('googleTile', t => {

ava_1.default('validateUndefined', t => {
t.throws(() => mercator.validateUndefined({ x: undefined }), '<x> is required');
t.throws(() => mercator.assertUndefined({ x: undefined }), '<x> is required');
});

@@ -148,0 +148,0 @@ ava_1.default('metersToPixels missing zoom', t => {

@@ -57,3 +57,3 @@ import test from 'ava'

test('tileLatLonBounds', t => {
const bounds = mercator.tileLatLonBounds(TILE)
const bounds = mercator.tileLatLngBounds(TILE)
t.deepEqual(bounds, BOUNDS_LATLNG)

@@ -67,4 +67,4 @@ })

test('tileQuadKey', t => {
const quadkey = mercator.tileQuadKey(TILE)
test('tileQuadkey', t => {
const quadkey = mercator.tileQuadkey(TILE)
t.deepEqual(quadkey, QUADKEY)

@@ -74,3 +74,3 @@ })

test('quadKeyGoogle', t => {
const google = mercator.quadKeyGoogle(QUADKEY)
const google = mercator.quadkeyGoogle(QUADKEY)
t.deepEqual(google, pick(GOOGLE, ['x', 'y', 'zoom']))

@@ -80,8 +80,8 @@ })

test('quadKeyTile', t => {
const tile = mercator.quadKeyTile(QUADKEY)
const tile = mercator.quadkeyTile(QUADKEY)
t.deepEqual(tile, pick(TILE, ['tx', 'ty', 'zoom']))
})
test('Throws Error quadKeyTile', t => {
t.throws(() => mercator.quadKeyTile(QUADKEY_BAD), 'Invalid QuadKey digit sequence')
test('Throws Error quadkeyTile', t => {
t.throws(() => mercator.quadkeyTile(QUADKEY_BAD), 'Invalid Quadkey digit sequence')
})

@@ -95,3 +95,3 @@

test('googleLatLonBounds', t => {
const bounds = mercator.googleLatLonBounds(GOOGLE)
const bounds = mercator.googleLatLngBounds(GOOGLE)
t.deepEqual(bounds, BOUNDS_LATLNG)

@@ -106,3 +106,3 @@ })

test('googleQuadKey', t => {
const quadkey = mercator.googleQuadKey(GOOGLE)
const quadkey = mercator.googleQuadkey(GOOGLE)
t.deepEqual(quadkey, QUADKEY)

@@ -125,5 +125,5 @@ })

test('boundsLatLngToMeters', t => {
const bounds = mercator.boundsLatLngToMeters(BOUNDS_LATLNG)
t.deepEqual(bounds.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2)))
test('bboxLatLngToMeters', t => {
const bbox = mercator.bboxLatLngToMeters(BOUNDS_LATLNG)
t.deepEqual(bbox.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2)))
})

@@ -176,3 +176,3 @@

test('validateUndefined', t => {
t.throws(() => mercator.validateUndefined({x: undefined}), '<x> is required')
t.throws(() => mercator.assertUndefined({x: undefined}), '<x> is required')
})

@@ -179,0 +179,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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