global-mercator
Advanced tools
Comparing version 0.2.0 to 0.2.1
117
API.md
@@ -5,3 +5,3 @@ <!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
Converts {LatLng} coordinates to {Meters} coordinates. | ||
Converts [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates to [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -21,7 +21,7 @@ **Parameters** | ||
Returns **[Meters](https://en.wikipedia.org/wiki/Web_Mercator)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Meters coordinates | ||
# metersToLatLng | ||
Converts {Meters} coordinates to {LatLng} coordinates. | ||
Converts [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates to [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -41,7 +41,7 @@ **Parameters** | ||
Returns **[LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** LatLng coordinates | ||
# metersToPixels | ||
Converts {Meters} coordinates to {Pixels}. | ||
Converts [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates to [Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx) coordinates. | ||
@@ -61,7 +61,7 @@ **Parameters** | ||
Returns **[Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Pixels coordinates | ||
# latLngToTile | ||
Converts {LatLng} coordinates to TMS {Tile}. | ||
Converts [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -81,7 +81,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# latLngToGoogle | ||
Converts {LatLng} coordinates to {Google} (XYZ) Tile. | ||
Converts [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates to [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile. | ||
@@ -100,7 +100,7 @@ **Parameters** | ||
Returns **[Google](https://en.wikipedia.org/wiki/Tiled_web_map)** Google Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Google (XYZ) Tile | ||
# metersToTile | ||
Converts {Meters} coordinates to TMS {Tile}. | ||
Converts [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -119,7 +119,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# pixelsToMeters | ||
Converts {Pixels} coordinates to {Meters} coordinates. | ||
Converts [Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx) coordinates to [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -139,7 +139,7 @@ **Parameters** | ||
Returns **[Meters](https://en.wikipedia.org/wiki/Web_Mercator)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Meters coordinates | ||
# pixelsToTile | ||
Converts {Pixels} coordinates to TMS {Tile}. | ||
Converts [Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx) coordinates to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -159,7 +159,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# tileBounds | ||
# tileBbox | ||
Converts TMS {Tile} to bounds in {Meters} coordinates. | ||
Converts TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map) to [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) in [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -175,11 +175,11 @@ **Parameters** | ||
```javascript | ||
tileBounds({ tx: 6963, ty: 5003, zoom: 13 }) | ||
tileBbox({ tx: 6963, ty: 5003, zoom: 13 }) | ||
//= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ] | ||
``` | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order | ||
# tileLatLngBounds | ||
# tileLatLngBbox | ||
Converts TMS {Tile} to bounds in {LatLng} coordinates. | ||
Converts TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map) to [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) in [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -195,11 +195,11 @@ **Parameters** | ||
```javascript | ||
tileLatLngBounds({ tx: 6963, ty: 5003, zoom: 13 }) | ||
tileLatLngBbox({ 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)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order | ||
# googleBounds | ||
# googleBbox | ||
Converts {Google} (XYZ) Tile to bounds in {Meters} coordinates. | ||
Converts [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile to [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) in [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -215,11 +215,11 @@ **Parameters** | ||
```javascript | ||
googleBounds({ x: 6963, y: 3188, zoom: 13 }) | ||
googleBbox({ x: 6963, y: 3188, zoom: 13 }) | ||
//= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ] | ||
``` | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order | ||
# googleLatLngBounds | ||
# googleLatLngBbox | ||
Converts {Google} (XYZ) Tile to bounds in {LatLng} coordinates. | ||
Converts [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile to [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) in [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -235,11 +235,11 @@ **Parameters** | ||
```javascript | ||
googleLatLngBounds({ x: 6963, y: 3188, zoom: 13 }) | ||
googleLatLngBbox({ 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)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[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} to {Google} (XYZ) Tile. | ||
Converts TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map) to [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile. | ||
@@ -259,7 +259,7 @@ **Parameters** | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[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} (XYZ) Tile to TMS {Tile}. | ||
Converts [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -279,7 +279,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# googleQuadkey | ||
Converts {Google} (XYZ) Tile to {Quadkey}. | ||
Converts [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile to [Quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx). | ||
@@ -303,3 +303,3 @@ **Parameters** | ||
Converts TMS {Tile} to {QuadKey}. | ||
Converts TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map) to [QuadKey](QuadKey). | ||
@@ -323,3 +323,3 @@ **Parameters** | ||
Converts {Quadkey} to TMS {Tile}. | ||
Converts [Quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx) to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -337,7 +337,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# quadkeyGoogle | ||
Converts {Quadkey} to {Google} (XYZ) Tile. | ||
Converts [Quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx) to [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile. | ||
@@ -355,8 +355,12 @@ **Parameters** | ||
Returns **[Google](https://en.wikipedia.org/wiki/Tiled_web_map)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Google (XYZ) Tile | ||
# bboxLatLngToMeters | ||
Converts {bbox} from {LatLng} coordinates to {Meters} coordinates | ||
Converts [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) from [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates to [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates | ||
**Parameters** | ||
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** extent in [minX, minY, maxX, maxY] order | ||
**Examples** | ||
@@ -369,7 +373,7 @@ | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order | ||
# validateTile | ||
Validates TMS {Tile}. | ||
Validates TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -381,3 +385,2 @@ **Parameters** | ||
- `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`) | ||
@@ -398,3 +401,3 @@ | ||
Validates {Zoom} level. | ||
Validates [Zoom](http://wiki.openstreetmap.org/wiki/Zoom_levels) level. | ||
@@ -420,3 +423,3 @@ **Parameters** | ||
Validates {Pixels} coordinates. | ||
Validates [Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx) coordinates. | ||
@@ -438,3 +441,3 @@ **Parameters** | ||
Validates {Meters} coordinates. | ||
Validates [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -456,3 +459,3 @@ **Parameters** | ||
Validates {LatLng} coordinates. | ||
Validates [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -474,3 +477,3 @@ **Parameters** | ||
Validates {LngLat} coordinates. | ||
Validates [LngLat](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -490,9 +493,9 @@ **Parameters** | ||
# bounds | ||
# validateBbox | ||
Validates bounds. | ||
Validates [bbox](http://geojson.org/geojson-spec.html#bounding-boxes). | ||
**Parameters** | ||
- `bounds` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** | ||
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** extent in [minX, minY, maxX, maxY] order | ||
@@ -502,6 +505,6 @@ **Examples** | ||
```javascript | ||
validateBounds([ -75, 44, -74, 45 ]) | ||
validateBbox([ -75, 44, -74, 45 ]) | ||
//= [ -75, 44, -74, 45 ] | ||
validateBounds([ -75, 44, -74 ]) | ||
//= Error: [bounds] must be an Array of 4 numbers | ||
validateBbox([ -75, 44, -74 ]) | ||
//= Error: [bbox] must be an Array of 4 numbers | ||
``` | ||
@@ -508,0 +511,0 @@ |
217
index.js
@@ -10,3 +10,3 @@ "use strict"; | ||
/** | ||
* Converts {LatLng} coordinates to {Meters} coordinates. | ||
* Converts {@link LatLng} coordinates to {@link Meters} coordinates. | ||
* | ||
@@ -17,3 +17,3 @@ * @name latLngToMeters | ||
* @param {number} [zoom] | ||
* @returns {Meters} | ||
* @returns {Object} Meters coordinates | ||
* @example | ||
@@ -28,3 +28,3 @@ * latLngToMeters({lat: 37, lng: 126}) | ||
/** | ||
* Converts {Meters} coordinates to {LatLng} coordinates. | ||
* Converts {@link Meters} coordinates to {@link LatLng} coordinates. | ||
* | ||
@@ -35,3 +35,3 @@ * @name metersToLatLng | ||
* @param {number} [zoom] | ||
* @returns {LatLng} | ||
* @returns {Object} LatLng coordinates | ||
* @example | ||
@@ -46,3 +46,3 @@ * metersToLatLng({ mx: 14026255, my: 4439106 }) | ||
/** | ||
* Converts {Meters} coordinates to {Pixels}. | ||
* Converts {@link Meters} coordinates to {@link Pixels} coordinates. | ||
* | ||
@@ -53,3 +53,3 @@ * @name metersToPixels | ||
* @param {number} zoom | ||
* @returns {Pixels} | ||
* @returns {Object} Pixels coordinates | ||
* @example | ||
@@ -64,3 +64,3 @@ * metersToPixels({ mx: 14026255, my: 4439106, zoom: 13 }) | ||
/** | ||
* Converts {LatLng} coordinates to TMS {Tile}. | ||
* Converts {@link LatLng} coordinates to TMS {@link Tile}. | ||
* | ||
@@ -71,3 +71,3 @@ * @name latLngToTile | ||
* @param {number} zoom | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -82,3 +82,3 @@ * latLngToTile({lat: 37, lng: 126, zoom: 13 }) | ||
/** | ||
* Converts {LatLng} coordinates to {Google} (XYZ) Tile. | ||
* Converts {@link LatLng} coordinates to {@link Google} (XYZ) Tile. | ||
* | ||
@@ -88,3 +88,3 @@ * @name latLngToGoogle | ||
* @param {number} lng | ||
* @returns {Google} Google Tile | ||
* @returns {Object} Google (XYZ) Tile | ||
* @example | ||
@@ -99,3 +99,3 @@ * latLngToGoogle({lat: 37, lng: 126, zoom: 13 }) | ||
/** | ||
* Converts {Meters} coordinates to TMS {Tile}. | ||
* Converts {@link Meters} coordinates to TMS {@link Tile}. | ||
* | ||
@@ -105,3 +105,3 @@ * @name metersToTile | ||
* @param {number} my | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -116,3 +116,3 @@ * metersToTile({ mx: 14026255, my: 4439106, zoom: 13 }) | ||
/** | ||
* Converts {Pixels} coordinates to {Meters} coordinates. | ||
* Converts {@link Pixels} coordinates to {@link Meters} coordinates. | ||
* | ||
@@ -123,3 +123,3 @@ * @name pixelsToMeters | ||
* @param {number} zoom | ||
* @returns {Meters} | ||
* @returns {Object} Meters coordinates | ||
* @example | ||
@@ -134,3 +134,3 @@ * pixelsToMeters({ px: 1782579, py: 1280877, zoom: 13 }) | ||
/** | ||
* Converts {Pixels} coordinates to TMS {Tile}. | ||
* Converts {@link Pixels} coordinates to TMS {@link Tile}. | ||
* | ||
@@ -141,3 +141,3 @@ * @name pixelsToTile | ||
* @param {number} zoom | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -152,67 +152,67 @@ * pixelsToTile({ px: 1782579, py: 1280877, zoom: 13 }) | ||
/** | ||
* Converts TMS {Tile} to bounds in {Meters} coordinates. | ||
* Converts TMS {@link Tile} to {@link bbox} in {@link Meters} coordinates. | ||
* | ||
* @name tileBounds | ||
* @name tileBbox | ||
* @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 | ||
* tileBounds({ tx: 6963, ty: 5003, zoom: 13 }) | ||
* tileBbox({ tx: 6963, ty: 5003, zoom: 13 }) | ||
* //= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ] | ||
*/ | ||
function tileBounds(init) { | ||
return mercator.tileBounds(init); | ||
function tileBbox(init) { | ||
return mercator.tileBbox(init); | ||
} | ||
exports.tileBounds = tileBounds; | ||
exports.tileBbox = tileBbox; | ||
/** | ||
* Converts TMS {Tile} to bounds in {LatLng} coordinates. | ||
* Converts TMS {@link Tile} to {@link bbox} in {@link LatLng} coordinates. | ||
* | ||
* @name tileLatLngBounds | ||
* @name tileLatLngBbox | ||
* @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 }) | ||
* tileLatLngBbox({ tx: 6963, ty: 5003, zoom: 13 }) | ||
* //= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ] | ||
*/ | ||
function tileLatLngBounds(init) { | ||
return mercator.tileLatLngBounds(init); | ||
function tileLatLngBbox(init) { | ||
return mercator.tileLatLngBbox(init); | ||
} | ||
exports.tileLatLngBounds = tileLatLngBounds; | ||
exports.tileLatLngBbox = tileLatLngBbox; | ||
/** | ||
* Converts {Google} (XYZ) Tile to bounds in {Meters} coordinates. | ||
* Converts {@link Google} (XYZ) Tile to {@link bbox} in {@link Meters} coordinates. | ||
* | ||
* @name googleBounds | ||
* @name googleBbox | ||
* @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 | ||
* googleBounds({ x: 6963, y: 3188, zoom: 13 }) | ||
* googleBbox({ x: 6963, y: 3188, zoom: 13 }) | ||
* //= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ] | ||
*/ | ||
function googleBounds(init) { | ||
return mercator.googleBounds(init); | ||
function googleBbox(init) { | ||
return mercator.googleBbox(init); | ||
} | ||
exports.googleBounds = googleBounds; | ||
exports.googleBbox = googleBbox; | ||
/** | ||
* Converts {Google} (XYZ) Tile to bounds in {LatLng} coordinates. | ||
* Converts {@link Google} (XYZ) Tile to {@link bbox} in {@link LatLng} coordinates. | ||
* | ||
* @name googleLatLngBounds | ||
* @name googleLatLngBbox | ||
* @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 }) | ||
* googleLatLngBbox({ x: 6963, y: 3188, zoom: 13 }) | ||
* //= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ] | ||
*/ | ||
function googleLatLngBounds(init) { | ||
return mercator.googleLatLngBounds(init); | ||
function googleLatLngBbox(init) { | ||
return mercator.googleLatLngBbox(init); | ||
} | ||
exports.googleLatLngBounds = googleLatLngBounds; | ||
exports.googleLatLngBbox = googleLatLngBbox; | ||
/** | ||
* Converts TMS {Tile} to {Google} (XYZ) Tile. | ||
* Converts TMS {@link Tile} to {@link Google} (XYZ) Tile. | ||
* | ||
@@ -223,3 +223,3 @@ * @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 | ||
@@ -234,3 +234,3 @@ * tileGoogle({ tx: 6963, ty: 5003, zoom: 13 }) | ||
/** | ||
* Converts {Google} (XYZ) Tile to TMS {Tile}. | ||
* Converts {@link Google} (XYZ) Tile to TMS {@link Tile}. | ||
* | ||
@@ -241,3 +241,3 @@ * @name googleTile | ||
* @param {number} zoom | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -252,3 +252,3 @@ * googleTile({ x: 6963, y: 3188, zoom: 13 }) | ||
/** | ||
* Converts {Google} (XYZ) Tile to {Quadkey}. | ||
* Converts {@link Google} (XYZ) Tile to {@link Quadkey}. | ||
* | ||
@@ -269,3 +269,3 @@ * @name googleQuadkey | ||
/** | ||
* Converts TMS {Tile} to {QuadKey}. | ||
* Converts TMS {@link Tile} to {@link QuadKey}. | ||
* | ||
@@ -286,7 +286,7 @@ * @name tileQuadkey | ||
/** | ||
* Converts {Quadkey} to TMS {Tile}. | ||
* Converts {@link Quadkey} to TMS {@link Tile}. | ||
* | ||
* @name quadkeyTile | ||
* @param {string} quadkey | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -301,7 +301,7 @@ * quadkeyTile('1321102330211') | ||
/** | ||
* Converts {Quadkey} to {Google} (XYZ) Tile. | ||
* Converts {@link Quadkey} to {@link Google} (XYZ) Tile. | ||
* | ||
* @name quadkeyGoogle | ||
* @param {string} quadkey | ||
* @returns {Google} | ||
* @returns {Object} Google (XYZ) Tile | ||
* @example | ||
@@ -316,7 +316,7 @@ * quadkeyGoogle('1321102330211') | ||
/** | ||
* Converts {bbox} from {LatLng} coordinates to {Meters} coordinates | ||
* Converts {@link bbox} from {@link LatLng} coordinates to {@link Meters} coordinates | ||
* | ||
* @name bboxLatLngToMeters | ||
* @param {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order | ||
* @returns {Array<number>} {bbox} | ||
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @example | ||
@@ -331,3 +331,5 @@ * bboxLatLngToMeters([ 125, 35, 127, 37 ]) | ||
/** | ||
* Validates TMS {Tile}. | ||
* Validates TMS {@link Tile}. | ||
* | ||
* @name validateTile | ||
* @param {number} tx | ||
@@ -337,4 +339,4 @@ * @param {number} ty | ||
* @param {string} [name=Tile] - name used for debugging message | ||
* @throw Will throw an error if TMS {Tile} is not valid. | ||
* @return {Object} TMS Tile | ||
* @throw Will throw an error if TMS Tile is not valid. | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -363,7 +365,8 @@ * validateTile({tx: 60, ty: 80, zoom: 5}) | ||
/** | ||
* Validates {Zoom} level. | ||
* Validates {@link Zoom} level. | ||
* | ||
* @name validateZoom | ||
* @param {number} Zoom level | ||
* @throw Will throw an error if zoom is not valid. | ||
* @return {number} Zoom level | ||
* @returns {number} Zoom level | ||
* @example | ||
@@ -392,7 +395,8 @@ * validateZoom(12) | ||
/** | ||
* Validates {Pixels} coordinates. | ||
* Validates {@link Pixels} coordinates. | ||
* | ||
* @name validatePixels | ||
* @param {Array<number>} Pixels coordinates | ||
* @throw Will throw an error if {Pixels} is not valid. | ||
* @return {Array<number>} Pixels coordinates | ||
* @throw Will throw an error if Pixels is not valid. | ||
* @returns {Array<number>} Pixels coordinates | ||
* @example | ||
@@ -423,7 +427,8 @@ * validatePixels([-115, 44]) | ||
/** | ||
* Validates {Meters} coordinates. | ||
* Validates {@link Meters} coordinates. | ||
* | ||
* @name validateMeters | ||
* @param {Array<number>} Meters coordinates | ||
* @throw Will throw an error if {Meters} is not valid. | ||
* @return {Array<number>} Meters coordinates | ||
* @throw Will throw an error if Meters is not valid. | ||
* @returns {Array<number>} Meters coordinates | ||
* @example | ||
@@ -466,7 +471,8 @@ * validateMeters([-115, 44]) | ||
/** | ||
* Validates {LatLng} coordinates. | ||
* Validates {@link LatLng} coordinates. | ||
* | ||
* @name validateLatLng | ||
* @param {Array<number>} LatLng coordinates | ||
* @throw Will throw an error if {LatLng} is not valid. | ||
* @return {Array<number>} LatLng coordinates | ||
* @throw Will throw an error if LatLng is not valid. | ||
* @returns {Array<number>} LatLng coordinates | ||
* @example | ||
@@ -482,7 +488,8 @@ * validateLatLng([-115, 44]) | ||
/** | ||
* Validates {LngLat} coordinates. | ||
* Validates {@link LngLat} coordinates. | ||
* | ||
* @name validateLngLat | ||
* @param {Array<number>} LngLat coordinates | ||
* @throw Will throw an error if {LngLat} is not valid. | ||
* @return {Array<number>} LngLat coordinates | ||
* @throw Will throw an error if LngLat is not valid. | ||
* @returns {Array<number>} LngLat coordinates | ||
* @example | ||
@@ -523,16 +530,17 @@ * validateLngLat([-115, 44]) | ||
/** | ||
* Validates bounds. | ||
* @name bounds | ||
* @param {Array<number>} bounds | ||
* @throw Will throw an error if bounds is not valid. | ||
* @returns {Array<number} bounds | ||
* Validates {@link bbox}. | ||
* | ||
* @name validateBbox | ||
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @throw Will throw an error if bbox is not valid. | ||
* @returns {Array<number} bbox extent in [minX, minY, maxX, maxY] order | ||
* @example | ||
* validateBounds([ -75, 44, -74, 45 ]) | ||
* validateBbox([ -75, 44, -74, 45 ]) | ||
* //= [ -75, 44, -74, 45 ] | ||
* validateBounds([ -75, 44, -74 ]) | ||
* //= Error: [bounds] must be an Array of 4 numbers | ||
* validateBbox([ -75, 44, -74 ]) | ||
* //= Error: [bbox] must be an Array of 4 numbers | ||
*/ | ||
function validateBounds(init) { | ||
function validateBbox(init) { | ||
if (init.length !== 4) { | ||
const message = '[bounds] must be an Array of 4 numbers'; | ||
const message = '[bbox] must be an Array of 4 numbers'; | ||
exports.debug.error(message); | ||
@@ -543,5 +551,6 @@ throw new Error(message); | ||
} | ||
exports.validateBounds = validateBounds; | ||
exports.validateBbox = validateBbox; | ||
/** | ||
* Assert undefined items within object. | ||
* | ||
* @name assertUndefined | ||
@@ -632,5 +641,5 @@ * @param {Object} items | ||
this.name = 'GlobalMercator'; | ||
this.bboxLatLngToMeters = (bounds) => { | ||
const min = this.latLngToMeters({ lat: bounds[1], lng: bounds[0] }); | ||
const max = this.latLngToMeters({ lat: bounds[3], lng: bounds[2] }); | ||
this.bboxLatLngToMeters = (bbox) => { | ||
const min = this.latLngToMeters({ lat: bbox[1], lng: bbox[0] }); | ||
const max = this.latLngToMeters({ lat: bbox[3], lng: bbox[2] }); | ||
return [min.mx, min.my, max.mx, max.my]; | ||
@@ -712,9 +721,9 @@ }; | ||
} | ||
tileBounds(init) { | ||
tileBbox(init) { | ||
const { tx, ty, zoom } = new Tile(init); | ||
let min = this.pixelsToMeters({ px: tx * this.TileSize, py: ty * this.TileSize, zoom: zoom }); | ||
let max = this.pixelsToMeters({ px: (tx + 1) * this.TileSize, py: (ty + 1) * this.TileSize, zoom: zoom }); | ||
return validateBounds([min.mx, min.my, max.mx, max.my]); | ||
return validateBbox([min.mx, min.my, max.mx, max.my]); | ||
} | ||
tileLatLngBounds(init) { | ||
tileLatLngBbox(init) { | ||
if (init.zoom === 0) { | ||
@@ -724,14 +733,14 @@ return [-180, -85.05112877980659, 180, 85.05112877980659]; | ||
const { tx, ty, zoom } = new Tile(init); | ||
const [mx1, my1, mx2, my2] = this.tileBounds({ tx: tx, ty: ty, zoom: zoom }); | ||
const [mx1, my1, mx2, my2] = this.tileBbox({ tx: tx, ty: ty, zoom: zoom }); | ||
const min = this.metersToLatLng({ mx: mx1, my: my1, zoom: zoom }); | ||
const max = this.metersToLatLng({ mx: mx2, my: my2, zoom: zoom }); | ||
return validateBounds([min.lng, min.lat, max.lng, max.lat]); | ||
return validateBbox([min.lng, min.lat, max.lng, max.lat]); | ||
} | ||
googleBounds(init) { | ||
googleBbox(init) { | ||
const Tile = this.googleTile(init); | ||
return this.tileBounds(Tile); | ||
return this.tileBbox(Tile); | ||
} | ||
googleLatLngBounds(init) { | ||
googleLatLngBbox(init) { | ||
const Tile = this.googleTile(init); | ||
return this.tileLatLngBounds(Tile); | ||
return this.tileLatLngBbox(Tile); | ||
} | ||
@@ -818,4 +827,4 @@ tileGoogle(init) { | ||
latLngToGoogle: latLngToGoogle, | ||
tileBounds: tileBounds, | ||
tileLatLngBounds: tileLatLngBounds, | ||
tileBbox: tileBbox, | ||
tileLatLngBbox: tileLatLngBbox, | ||
tileGoogle: tileGoogle, | ||
@@ -825,4 +834,4 @@ tileQuadkey: tileQuadkey, | ||
quadkeyTile: quadkeyTile, | ||
googleBounds: googleBounds, | ||
googleLatLngBounds: googleLatLngBounds, | ||
googleBbox: googleBbox, | ||
googleLatLngBbox: googleLatLngBbox, | ||
googleQuadkey: googleQuadkey, | ||
@@ -832,4 +841,4 @@ }; | ||
if (require.main === module) { | ||
// const bounds = bboxLatLngToMeters([ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ]) | ||
// console.log(bounds) | ||
// const bbox = bboxLatLngToMeters([ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ]) | ||
// console.log(bbox) | ||
// const meters = pixelsToMeters({ px: 611669, py: 1342753, zoom: 13 }) | ||
@@ -849,4 +858,4 @@ // console.log(meters) | ||
console.log(latLngToMeters({ lat: 23, lng: 23 })); | ||
console.log(validateBounds([-75, 44, -74])); | ||
console.log(validateBbox([-75, 44, -74])); | ||
} | ||
//# sourceMappingURL=index.js.map |
207
index.ts
@@ -42,3 +42,3 @@ import * as Debug from 'debug' | ||
/** | ||
* Converts {LatLng} coordinates to {Meters} coordinates. | ||
* Converts {@link LatLng} coordinates to {@link Meters} coordinates. | ||
* | ||
@@ -49,3 +49,3 @@ * @name latLngToMeters | ||
* @param {number} [zoom] | ||
* @returns {Meters} | ||
* @returns {Object} Meters coordinates | ||
* @example | ||
@@ -60,3 +60,3 @@ * latLngToMeters({lat: 37, lng: 126}) | ||
/** | ||
* Converts {Meters} coordinates to {LatLng} coordinates. | ||
* Converts {@link Meters} coordinates to {@link LatLng} coordinates. | ||
* | ||
@@ -67,3 +67,3 @@ * @name metersToLatLng | ||
* @param {number} [zoom] | ||
* @returns {LatLng} | ||
* @returns {Object} LatLng coordinates | ||
* @example | ||
@@ -78,3 +78,3 @@ * metersToLatLng({ mx: 14026255, my: 4439106 }) | ||
/** | ||
* Converts {Meters} coordinates to {Pixels}. | ||
* Converts {@link Meters} coordinates to {@link Pixels} coordinates. | ||
* | ||
@@ -85,3 +85,3 @@ * @name metersToPixels | ||
* @param {number} zoom | ||
* @returns {Pixels} | ||
* @returns {Object} Pixels coordinates | ||
* @example | ||
@@ -96,3 +96,3 @@ * metersToPixels({ mx: 14026255, my: 4439106, zoom: 13 }) | ||
/** | ||
* Converts {LatLng} coordinates to TMS {Tile}. | ||
* Converts {@link LatLng} coordinates to TMS {@link Tile}. | ||
* | ||
@@ -103,3 +103,3 @@ * @name latLngToTile | ||
* @param {number} zoom | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -114,3 +114,3 @@ * latLngToTile({lat: 37, lng: 126, zoom: 13 }) | ||
/** | ||
* Converts {LatLng} coordinates to {Google} (XYZ) Tile. | ||
* Converts {@link LatLng} coordinates to {@link Google} (XYZ) Tile. | ||
* | ||
@@ -120,3 +120,3 @@ * @name latLngToGoogle | ||
* @param {number} lng | ||
* @returns {Google} Google Tile | ||
* @returns {Object} Google (XYZ) Tile | ||
* @example | ||
@@ -131,3 +131,3 @@ * latLngToGoogle({lat: 37, lng: 126, zoom: 13 }) | ||
/** | ||
* Converts {Meters} coordinates to TMS {Tile}. | ||
* Converts {@link Meters} coordinates to TMS {@link Tile}. | ||
* | ||
@@ -137,3 +137,3 @@ * @name metersToTile | ||
* @param {number} my | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -148,3 +148,3 @@ * metersToTile({ mx: 14026255, my: 4439106, zoom: 13 }) | ||
/** | ||
* Converts {Pixels} coordinates to {Meters} coordinates. | ||
* Converts {@link Pixels} coordinates to {@link Meters} coordinates. | ||
* | ||
@@ -155,3 +155,3 @@ * @name pixelsToMeters | ||
* @param {number} zoom | ||
* @returns {Meters} | ||
* @returns {Object} Meters coordinates | ||
* @example | ||
@@ -166,3 +166,3 @@ * pixelsToMeters({ px: 1782579, py: 1280877, zoom: 13 }) | ||
/** | ||
* Converts {Pixels} coordinates to TMS {Tile}. | ||
* Converts {@link Pixels} coordinates to TMS {@link Tile}. | ||
* | ||
@@ -173,3 +173,3 @@ * @name pixelsToTile | ||
* @param {number} zoom | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -184,67 +184,67 @@ * pixelsToTile({ px: 1782579, py: 1280877, zoom: 13 }) | ||
/** | ||
* Converts TMS {Tile} to bounds in {Meters} coordinates. | ||
* Converts TMS {@link Tile} to {@link bbox} in {@link Meters} coordinates. | ||
* | ||
* @name tileBounds | ||
* @name tileBbox | ||
* @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 | ||
* tileBounds({ tx: 6963, ty: 5003, zoom: 13 }) | ||
* tileBbox({ tx: 6963, ty: 5003, zoom: 13 }) | ||
* //= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ] | ||
*/ | ||
export function tileBounds(init: Tile) { | ||
return mercator.tileBounds(init) | ||
export function tileBbox(init: Tile) { | ||
return mercator.tileBbox(init) | ||
} | ||
/** | ||
* Converts TMS {Tile} to bounds in {LatLng} coordinates. | ||
* Converts TMS {@link Tile} to {@link bbox} in {@link LatLng} coordinates. | ||
* | ||
* @name tileLatLngBounds | ||
* @name tileLatLngBbox | ||
* @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 }) | ||
* tileLatLngBbox({ tx: 6963, ty: 5003, zoom: 13 }) | ||
* //= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ] | ||
*/ | ||
export function tileLatLngBounds(init: Tile) { | ||
return mercator.tileLatLngBounds(init) | ||
export function tileLatLngBbox(init: Tile) { | ||
return mercator.tileLatLngBbox(init) | ||
} | ||
/** | ||
* Converts {Google} (XYZ) Tile to bounds in {Meters} coordinates. | ||
* Converts {@link Google} (XYZ) Tile to {@link bbox} in {@link Meters} coordinates. | ||
* | ||
* @name googleBounds | ||
* @name googleBbox | ||
* @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 | ||
* googleBounds({ x: 6963, y: 3188, zoom: 13 }) | ||
* googleBbox({ x: 6963, y: 3188, zoom: 13 }) | ||
* //= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ] | ||
*/ | ||
export function googleBounds(init: Google) { | ||
return mercator.googleBounds(init) | ||
export function googleBbox(init: Google) { | ||
return mercator.googleBbox(init) | ||
} | ||
/** | ||
* Converts {Google} (XYZ) Tile to bounds in {LatLng} coordinates. | ||
* Converts {@link Google} (XYZ) Tile to {@link bbox} in {@link LatLng} coordinates. | ||
* | ||
* @name googleLatLngBounds | ||
* @name googleLatLngBbox | ||
* @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 }) | ||
* googleLatLngBbox({ x: 6963, y: 3188, zoom: 13 }) | ||
* //= [ 125.99121093749999, 36.98500309285596, 126.03515625, 37.020098201368135 ] | ||
*/ | ||
export function googleLatLngBounds(init: Google) { | ||
return mercator.googleLatLngBounds(init) | ||
export function googleLatLngBbox(init: Google) { | ||
return mercator.googleLatLngBbox(init) | ||
} | ||
/** | ||
* Converts TMS {Tile} to {Google} (XYZ) Tile. | ||
* Converts TMS {@link Tile} to {@link Google} (XYZ) Tile. | ||
* | ||
@@ -255,3 +255,3 @@ * @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 | ||
@@ -266,3 +266,3 @@ * tileGoogle({ tx: 6963, ty: 5003, zoom: 13 }) | ||
/** | ||
* Converts {Google} (XYZ) Tile to TMS {Tile}. | ||
* Converts {@link Google} (XYZ) Tile to TMS {@link Tile}. | ||
* | ||
@@ -273,3 +273,3 @@ * @name googleTile | ||
* @param {number} zoom | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -284,3 +284,3 @@ * googleTile({ x: 6963, y: 3188, zoom: 13 }) | ||
/** | ||
* Converts {Google} (XYZ) Tile to {Quadkey}. | ||
* Converts {@link Google} (XYZ) Tile to {@link Quadkey}. | ||
* | ||
@@ -301,3 +301,3 @@ * @name googleQuadkey | ||
/** | ||
* Converts TMS {Tile} to {QuadKey}. | ||
* Converts TMS {@link Tile} to {@link QuadKey}. | ||
* | ||
@@ -318,7 +318,7 @@ * @name tileQuadkey | ||
/** | ||
* Converts {Quadkey} to TMS {Tile}. | ||
* Converts {@link Quadkey} to TMS {@link Tile}. | ||
* | ||
* @name quadkeyTile | ||
* @param {string} quadkey | ||
* @returns {Tile} TMS Tile | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -333,7 +333,7 @@ * quadkeyTile('1321102330211') | ||
/** | ||
* Converts {Quadkey} to {Google} (XYZ) Tile. | ||
* Converts {@link Quadkey} to {@link Google} (XYZ) Tile. | ||
* | ||
* @name quadkeyGoogle | ||
* @param {string} quadkey | ||
* @returns {Google} | ||
* @returns {Object} Google (XYZ) Tile | ||
* @example | ||
@@ -348,7 +348,7 @@ * quadkeyGoogle('1321102330211') | ||
/** | ||
* Converts {bbox} from {LatLng} coordinates to {Meters} coordinates | ||
* Converts {@link bbox} from {@link LatLng} coordinates to {@link Meters} coordinates | ||
* | ||
* @name bboxLatLngToMeters | ||
* @param {Array<number>} {bbox} extent in [minX, minY, maxX, maxY] order | ||
* @returns {Array<number>} {bbox} | ||
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @returns {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @example | ||
@@ -363,3 +363,5 @@ * bboxLatLngToMeters([ 125, 35, 127, 37 ]) | ||
/** | ||
* Validates TMS {Tile}. | ||
* Validates TMS {@link Tile}. | ||
* | ||
* @name validateTile | ||
* @param {number} tx | ||
@@ -369,4 +371,4 @@ * @param {number} ty | ||
* @param {string} [name=Tile] - name used for debugging message | ||
* @throw Will throw an error if TMS {Tile} is not valid. | ||
* @return {Object} TMS Tile | ||
* @throw Will throw an error if TMS Tile is not valid. | ||
* @returns {Object} TMS Tile | ||
* @example | ||
@@ -394,7 +396,8 @@ * validateTile({tx: 60, ty: 80, zoom: 5}) | ||
/** | ||
* Validates {Zoom} level. | ||
* Validates {@link Zoom} level. | ||
* | ||
* @name validateZoom | ||
* @param {number} Zoom level | ||
* @throw Will throw an error if zoom is not valid. | ||
* @return {number} Zoom level | ||
* @returns {number} Zoom level | ||
* @example | ||
@@ -422,7 +425,8 @@ * validateZoom(12) | ||
/** | ||
* Validates {Pixels} coordinates. | ||
* Validates {@link Pixels} coordinates. | ||
* | ||
* @name validatePixels | ||
* @param {Array<number>} Pixels coordinates | ||
* @throw Will throw an error if {Pixels} is not valid. | ||
* @return {Array<number>} Pixels coordinates | ||
* @throw Will throw an error if Pixels is not valid. | ||
* @returns {Array<number>} Pixels coordinates | ||
* @example | ||
@@ -453,7 +457,8 @@ * validatePixels([-115, 44]) | ||
/** | ||
* Validates {Meters} coordinates. | ||
* Validates {@link Meters} coordinates. | ||
* | ||
* @name validateMeters | ||
* @param {Array<number>} Meters coordinates | ||
* @throw Will throw an error if {Meters} is not valid. | ||
* @return {Array<number>} Meters coordinates | ||
* @throw Will throw an error if Meters is not valid. | ||
* @returns {Array<number>} Meters coordinates | ||
* @example | ||
@@ -496,7 +501,8 @@ * validateMeters([-115, 44]) | ||
/** | ||
* Validates {LatLng} coordinates. | ||
* Validates {@link LatLng} coordinates. | ||
* | ||
* @name validateLatLng | ||
* @param {Array<number>} LatLng coordinates | ||
* @throw Will throw an error if {LatLng} is not valid. | ||
* @return {Array<number>} LatLng coordinates | ||
* @throw Will throw an error if LatLng is not valid. | ||
* @returns {Array<number>} LatLng coordinates | ||
* @example | ||
@@ -512,7 +518,8 @@ * validateLatLng([-115, 44]) | ||
/** | ||
* Validates {LngLat} coordinates. | ||
* Validates {@link LngLat} coordinates. | ||
* | ||
* @name validateLngLat | ||
* @param {Array<number>} LngLat coordinates | ||
* @throw Will throw an error if {LngLat} is not valid. | ||
* @return {Array<number>} LngLat coordinates | ||
* @throw Will throw an error if LngLat is not valid. | ||
* @returns {Array<number>} LngLat coordinates | ||
* @example | ||
@@ -552,16 +559,17 @@ * validateLngLat([-115, 44]) | ||
/** | ||
* Validates bounds. | ||
* @name bounds | ||
* @param {Array<number>} bounds | ||
* @throw Will throw an error if bounds is not valid. | ||
* @returns {Array<number} bounds | ||
* Validates {@link bbox}. | ||
* | ||
* @name validateBbox | ||
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @throw Will throw an error if bbox is not valid. | ||
* @returns {Array<number} bbox extent in [minX, minY, maxX, maxY] order | ||
* @example | ||
* validateBounds([ -75, 44, -74, 45 ]) | ||
* validateBbox([ -75, 44, -74, 45 ]) | ||
* //= [ -75, 44, -74, 45 ] | ||
* validateBounds([ -75, 44, -74 ]) | ||
* //= Error: [bounds] must be an Array of 4 numbers | ||
* validateBbox([ -75, 44, -74 ]) | ||
* //= Error: [bbox] must be an Array of 4 numbers | ||
*/ | ||
export function validateBounds(init: number[]) { | ||
export function validateBbox(init: number[]) { | ||
if (init.length !== 4) { | ||
const message = '[bounds] must be an Array of 4 numbers' | ||
const message = '[bbox] must be an Array of 4 numbers' | ||
debug.error(message) | ||
@@ -575,2 +583,3 @@ throw new Error(message) | ||
* Assert undefined items within object. | ||
* | ||
* @name assertUndefined | ||
@@ -756,3 +765,3 @@ * @param {Object} items | ||
public tileBounds(init: Tile) { | ||
public tileBbox(init: Tile) { | ||
const {tx, ty, zoom} = new Tile(init) | ||
@@ -762,29 +771,29 @@ let min = this.pixelsToMeters({ px: tx * this.TileSize, py: ty * this.TileSize, zoom }) | ||
return validateBounds([ min.mx, min.my, max.mx, max.my ]) | ||
return validateBbox([ min.mx, min.my, max.mx, max.my ]) | ||
} | ||
public tileLatLngBounds(init: Tile) { | ||
public tileLatLngBbox(init: Tile) { | ||
if (init.zoom === 0) { return [ -180, -85.05112877980659, 180, 85.05112877980659 ] } | ||
const {tx, ty, zoom} = new Tile(init) | ||
const [mx1, my1, mx2, my2] = this.tileBounds({ tx, ty, zoom }) | ||
const [mx1, my1, mx2, my2] = this.tileBbox({ tx, ty, zoom }) | ||
const min = this.metersToLatLng({ mx: mx1, my: my1, zoom }) | ||
const max = this.metersToLatLng({ mx: mx2, my: my2, zoom }) | ||
return validateBounds([ min.lng, min.lat, max.lng, max.lat ]) | ||
return validateBbox([ min.lng, min.lat, max.lng, max.lat ]) | ||
} | ||
public googleBounds(init: Google) { | ||
public googleBbox(init: Google) { | ||
const Tile = this.googleTile(init) | ||
return this.tileBounds(Tile) | ||
return this.tileBbox(Tile) | ||
} | ||
public googleLatLngBounds(init: Google) { | ||
public googleLatLngBbox(init: Google) { | ||
const Tile = this.googleTile(init) | ||
return this.tileLatLngBounds(Tile) | ||
return this.tileLatLngBbox(Tile) | ||
} | ||
public bboxLatLngToMeters = (bounds: number[]): number[] => { | ||
const min = this.latLngToMeters({lat: bounds[1], lng: bounds[0]}) | ||
const max = this.latLngToMeters({lat: bounds[3], lng: bounds[2]}) | ||
public bboxLatLngToMeters = (bbox: number[]): number[] => { | ||
const min = this.latLngToMeters({lat: bbox[1], lng: bbox[0]}) | ||
const max = this.latLngToMeters({lat: bbox[3], lng: bbox[2]}) | ||
return [min.mx, min.my, max.mx, max.my] | ||
@@ -878,4 +887,4 @@ } | ||
latLngToGoogle, | ||
tileBounds, | ||
tileLatLngBounds, | ||
tileBbox, | ||
tileLatLngBbox, | ||
tileGoogle, | ||
@@ -885,4 +894,4 @@ tileQuadkey, | ||
quadkeyTile, | ||
googleBounds, | ||
googleLatLngBounds, | ||
googleBbox, | ||
googleLatLngBbox, | ||
googleQuadkey, | ||
@@ -893,4 +902,4 @@ } | ||
if (require.main === module) { | ||
// const bounds = bboxLatLngToMeters([ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ]) | ||
// console.log(bounds) | ||
// const bbox = bboxLatLngToMeters([ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ]) | ||
// console.log(bbox) | ||
// const meters = pixelsToMeters({ px: 611669, py: 1342753, zoom: 13 }) | ||
@@ -910,3 +919,3 @@ // console.log(meters) | ||
console.log(latLngToMeters({lat: 23, lng: 23})) | ||
console.log(validateBounds([ -75, 44, -74 ])) | ||
console.log(validateBbox([ -75, 44, -74 ])) | ||
} |
{ | ||
"name": "global-mercator", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Global Mercator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
117
README.md
@@ -31,3 +31,3 @@ [![Build Status](https://travis-ci.org/DenisCarriere/global-mercator.svg?branch=master)](https://travis-ci.org/DenisCarriere/global-mercator) | ||
Converts {LatLng} coordinates to {Meters} coordinates. | ||
Converts [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates to [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -47,7 +47,7 @@ **Parameters** | ||
Returns **[Meters](https://en.wikipedia.org/wiki/Web_Mercator)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Meters coordinates | ||
# metersToLatLng | ||
Converts {Meters} coordinates to {LatLng} coordinates. | ||
Converts [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates to [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -67,7 +67,7 @@ **Parameters** | ||
Returns **[LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** LatLng coordinates | ||
# metersToPixels | ||
Converts {Meters} coordinates to {Pixels}. | ||
Converts [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates to [Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx) coordinates. | ||
@@ -87,7 +87,7 @@ **Parameters** | ||
Returns **[Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Pixels coordinates | ||
# latLngToTile | ||
Converts {LatLng} coordinates to TMS {Tile}. | ||
Converts [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -107,7 +107,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# latLngToGoogle | ||
Converts {LatLng} coordinates to {Google} (XYZ) Tile. | ||
Converts [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates to [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile. | ||
@@ -126,7 +126,7 @@ **Parameters** | ||
Returns **[Google](https://en.wikipedia.org/wiki/Tiled_web_map)** Google Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Google (XYZ) Tile | ||
# metersToTile | ||
Converts {Meters} coordinates to TMS {Tile}. | ||
Converts [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -145,7 +145,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# pixelsToMeters | ||
Converts {Pixels} coordinates to {Meters} coordinates. | ||
Converts [Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx) coordinates to [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -165,7 +165,7 @@ **Parameters** | ||
Returns **[Meters](https://en.wikipedia.org/wiki/Web_Mercator)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Meters coordinates | ||
# pixelsToTile | ||
Converts {Pixels} coordinates to TMS {Tile}. | ||
Converts [Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx) coordinates to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -185,7 +185,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# tileBounds | ||
# tileBbox | ||
Converts TMS {Tile} to bounds in {Meters} coordinates. | ||
Converts TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map) to [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) in [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -201,11 +201,11 @@ **Parameters** | ||
```javascript | ||
tileBounds({ tx: 6963, ty: 5003, zoom: 13 }) | ||
tileBbox({ tx: 6963, ty: 5003, zoom: 13 }) | ||
//= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ] | ||
``` | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order | ||
# tileLatLngBounds | ||
# tileLatLngBbox | ||
Converts TMS {Tile} to bounds in {LatLng} coordinates. | ||
Converts TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map) to [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) in [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -221,11 +221,11 @@ **Parameters** | ||
```javascript | ||
tileLatLngBounds({ tx: 6963, ty: 5003, zoom: 13 }) | ||
tileLatLngBbox({ 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)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order | ||
# googleBounds | ||
# googleBbox | ||
Converts {Google} (XYZ) Tile to bounds in {Meters} coordinates. | ||
Converts [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile to [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) in [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -241,11 +241,11 @@ **Parameters** | ||
```javascript | ||
googleBounds({ x: 6963, y: 3188, zoom: 13 }) | ||
googleBbox({ x: 6963, y: 3188, zoom: 13 }) | ||
//= [ 14025277.445990417, 4437016.617897913, 14030169.415800672, 4441908.587708164 ] | ||
``` | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order | ||
# googleLatLngBounds | ||
# googleLatLngBbox | ||
Converts {Google} (XYZ) Tile to bounds in {LatLng} coordinates. | ||
Converts [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile to [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) in [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -261,11 +261,11 @@ **Parameters** | ||
```javascript | ||
googleLatLngBounds({ x: 6963, y: 3188, zoom: 13 }) | ||
googleLatLngBbox({ 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)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[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} to {Google} (XYZ) Tile. | ||
Converts TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map) to [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile. | ||
@@ -285,7 +285,7 @@ **Parameters** | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} extent in [minX, minY, maxX, maxY] order | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[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} (XYZ) Tile to TMS {Tile}. | ||
Converts [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -305,7 +305,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# googleQuadkey | ||
Converts {Google} (XYZ) Tile to {Quadkey}. | ||
Converts [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile to [Quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx). | ||
@@ -329,3 +329,3 @@ **Parameters** | ||
Converts TMS {Tile} to {QuadKey}. | ||
Converts TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map) to [QuadKey](QuadKey). | ||
@@ -349,3 +349,3 @@ **Parameters** | ||
Converts {Quadkey} to TMS {Tile}. | ||
Converts [Quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx) to TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -363,7 +363,7 @@ **Parameters** | ||
Returns **[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)** TMS Tile | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** TMS Tile | ||
# quadkeyGoogle | ||
Converts {Quadkey} to {Google} (XYZ) Tile. | ||
Converts [Quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx) to [Google](https://en.wikipedia.org/wiki/Tiled_web_map) (XYZ) Tile. | ||
@@ -381,8 +381,12 @@ **Parameters** | ||
Returns **[Google](https://en.wikipedia.org/wiki/Tiled_web_map)** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Google (XYZ) Tile | ||
# bboxLatLngToMeters | ||
Converts {bbox} from {LatLng} coordinates to {Meters} coordinates | ||
Converts [bbox](http://geojson.org/geojson-spec.html#bounding-boxes) from [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates to [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates | ||
**Parameters** | ||
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** extent in [minX, minY, maxX, maxY] order | ||
**Examples** | ||
@@ -395,7 +399,7 @@ | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** {bbox} | ||
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** bbox extent in [minX, minY, maxX, maxY] order | ||
# validateTile | ||
Validates TMS {Tile}. | ||
Validates TMS [Tile](https://en.wikipedia.org/wiki/Tiled_web_map). | ||
@@ -407,3 +411,2 @@ **Parameters** | ||
- `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`) | ||
@@ -424,3 +427,3 @@ | ||
Validates {Zoom} level. | ||
Validates [Zoom](http://wiki.openstreetmap.org/wiki/Zoom_levels) level. | ||
@@ -446,3 +449,3 @@ **Parameters** | ||
Validates {Pixels} coordinates. | ||
Validates [Pixels](https://msdn.microsoft.com/en-us/library/bb259689.aspx) coordinates. | ||
@@ -464,3 +467,3 @@ **Parameters** | ||
Validates {Meters} coordinates. | ||
Validates [Meters](https://en.wikipedia.org/wiki/Web_Mercator) coordinates. | ||
@@ -482,3 +485,3 @@ **Parameters** | ||
Validates {LatLng} coordinates. | ||
Validates [LatLng](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -500,3 +503,3 @@ **Parameters** | ||
Validates {LngLat} coordinates. | ||
Validates [LngLat](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinates. | ||
@@ -516,9 +519,9 @@ **Parameters** | ||
# bounds | ||
# validateBbox | ||
Validates bounds. | ||
Validates [bbox](http://geojson.org/geojson-spec.html#bounding-boxes). | ||
**Parameters** | ||
- `bounds` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** | ||
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** extent in [minX, minY, maxX, maxY] order | ||
@@ -528,6 +531,6 @@ **Examples** | ||
```javascript | ||
validateBounds([ -75, 44, -74, 45 ]) | ||
validateBbox([ -75, 44, -74, 45 ]) | ||
//= [ -75, 44, -74, 45 ] | ||
validateBounds([ -75, 44, -74 ]) | ||
//= Error: [bounds] must be an Array of 4 numbers | ||
validateBbox([ -75, 44, -74 ]) | ||
//= Error: [bbox] must be an Array of 4 numbers | ||
``` | ||
@@ -534,0 +537,0 @@ |
42
test.js
@@ -12,4 +12,4 @@ "use strict"; | ||
const PIXELS = { px: 611669, py: 1342753, zoom: 13 }; | ||
const BOUNDS = [-8350592.466098936, 5620873.311978721, -8345700.496288682, 5625765.281788976]; | ||
const BOUNDS_LATLNG = [-75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546]; | ||
const BBOX = [-8350592.466098936, 5620873.311978721, -8345700.496288682, 5625765.281788976]; | ||
const BBOX_LATLNG = [-75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546]; | ||
ava_1.default('latLngToMeters', t => { | ||
@@ -45,9 +45,9 @@ const meters = mercator.latLngToMeters(LATLNG); | ||
}); | ||
ava_1.default('tileBounds', t => { | ||
const bounds = mercator.tileBounds(TILE); | ||
t.deepEqual(bounds.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2))); | ||
ava_1.default('tileBbox', t => { | ||
const bbox = mercator.tileBbox(TILE); | ||
t.deepEqual(bbox.map(i => i.toFixed(2)), BBOX.map(i => i.toFixed(2))); | ||
}); | ||
ava_1.default('tileLatLonBounds', t => { | ||
const bounds = mercator.tileLatLngBounds(TILE); | ||
t.deepEqual(bounds, BOUNDS_LATLNG); | ||
ava_1.default('tileLatLngBbox', t => { | ||
const bbox = mercator.tileLatLngBbox(TILE); | ||
t.deepEqual(bbox, BBOX_LATLNG); | ||
}); | ||
@@ -73,9 +73,9 @@ ava_1.default('tileGoogle', t => { | ||
}); | ||
ava_1.default('googleBounds', t => { | ||
const bounds = mercator.googleBounds(GOOGLE); | ||
t.deepEqual(bounds.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2))); | ||
ava_1.default('googleBbox', t => { | ||
const bbox = mercator.googleBbox(GOOGLE); | ||
t.deepEqual(bbox.map(i => i.toFixed(2)), BBOX.map(i => i.toFixed(2))); | ||
}); | ||
ava_1.default('googleLatLonBounds', t => { | ||
const bounds = mercator.googleLatLngBounds(GOOGLE); | ||
t.deepEqual(bounds, BOUNDS_LATLNG); | ||
ava_1.default('googleLatLonBbox', t => { | ||
const bbox = mercator.googleLatLngBbox(GOOGLE); | ||
t.deepEqual(bbox, BBOX_LATLNG); | ||
}); | ||
@@ -90,7 +90,7 @@ ava_1.default('latLngToGoogle', t => { | ||
}); | ||
ava_1.default('Throws Error Bad Bounds', t => { | ||
t.throws(() => mercator.validateBounds([1]), '[bounds] must be an Array of 4 numbers'); | ||
t.throws(() => mercator.validateBounds([1, 2]), '[bounds] must be an Array of 4 numbers'); | ||
t.throws(() => mercator.validateBounds([1, 2, 3]), '[bounds] must be an Array of 4 numbers'); | ||
t.throws(() => mercator.validateBounds([1, 2, 3, 4, 5]), '[bounds] must be an Array of 4 numbers'); | ||
ava_1.default('Throws Error Bad bbox', t => { | ||
t.throws(() => mercator.validateBbox([1]), '[bbox] must be an Array of 4 numbers'); | ||
t.throws(() => mercator.validateBbox([1, 2]), '[bbox] must be an Array of 4 numbers'); | ||
t.throws(() => mercator.validateBbox([1, 2, 3]), '[bbox] must be an Array of 4 numbers'); | ||
t.throws(() => mercator.validateBbox([1, 2, 3, 4, 5]), '[bbox] must be an Array of 4 numbers'); | ||
}); | ||
@@ -104,4 +104,4 @@ ava_1.default('Throws Error Bad LngLat', t => { | ||
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))); | ||
const bbox = mercator.bboxLatLngToMeters(BBOX_LATLNG); | ||
t.deepEqual(bbox.map(i => i.toFixed(2)), BBOX.map(i => i.toFixed(2))); | ||
}); | ||
@@ -108,0 +108,0 @@ ava_1.default('googleTile', t => { |
42
test.ts
@@ -12,4 +12,4 @@ import test from 'ava' | ||
const PIXELS = { px: 611669, py: 1342753, zoom: 13 } | ||
const BOUNDS = [ -8350592.466098936, 5620873.311978721, -8345700.496288682, 5625765.281788976 ] | ||
const BOUNDS_LATLNG = [ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ] | ||
const BBOX = [ -8350592.466098936, 5620873.311978721, -8345700.496288682, 5625765.281788976 ] | ||
const BBOX_LATLNG = [ -75.01464843750001, 44.99588261816546, -74.97070312499999, 45.02695045318546 ] | ||
@@ -52,10 +52,10 @@ test('latLngToMeters', t => { | ||
test('tileBounds', t => { | ||
const bounds = mercator.tileBounds(TILE) | ||
t.deepEqual(bounds.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2))) | ||
test('tileBbox', t => { | ||
const bbox = mercator.tileBbox(TILE) | ||
t.deepEqual(bbox.map(i => i.toFixed(2)), BBOX.map(i => i.toFixed(2))) | ||
}) | ||
test('tileLatLonBounds', t => { | ||
const bounds = mercator.tileLatLngBounds(TILE) | ||
t.deepEqual(bounds, BOUNDS_LATLNG) | ||
test('tileLatLngBbox', t => { | ||
const bbox = mercator.tileLatLngBbox(TILE) | ||
t.deepEqual(bbox, BBOX_LATLNG) | ||
}) | ||
@@ -87,10 +87,10 @@ | ||
test('googleBounds', t => { | ||
const bounds = mercator.googleBounds(GOOGLE) | ||
t.deepEqual(bounds.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2))) | ||
test('googleBbox', t => { | ||
const bbox = mercator.googleBbox(GOOGLE) | ||
t.deepEqual(bbox.map(i => i.toFixed(2)), BBOX.map(i => i.toFixed(2))) | ||
}) | ||
test('googleLatLonBounds', t => { | ||
const bounds = mercator.googleLatLngBounds(GOOGLE) | ||
t.deepEqual(bounds, BOUNDS_LATLNG) | ||
test('googleLatLonBbox', t => { | ||
const bbox = mercator.googleLatLngBbox(GOOGLE) | ||
t.deepEqual(bbox, BBOX_LATLNG) | ||
}) | ||
@@ -108,7 +108,7 @@ | ||
test('Throws Error Bad Bounds', t => { | ||
t.throws(() => mercator.validateBounds([1]), '[bounds] must be an Array of 4 numbers') | ||
t.throws(() => mercator.validateBounds([1, 2]), '[bounds] must be an Array of 4 numbers') | ||
t.throws(() => mercator.validateBounds([1, 2, 3]), '[bounds] must be an Array of 4 numbers') | ||
t.throws(() => mercator.validateBounds([1, 2, 3, 4, 5]), '[bounds] must be an Array of 4 numbers') | ||
test('Throws Error Bad bbox', t => { | ||
t.throws(() => mercator.validateBbox([1]), '[bbox] must be an Array of 4 numbers') | ||
t.throws(() => mercator.validateBbox([1, 2]), '[bbox] must be an Array of 4 numbers') | ||
t.throws(() => mercator.validateBbox([1, 2, 3]), '[bbox] must be an Array of 4 numbers') | ||
t.throws(() => mercator.validateBbox([1, 2, 3, 4, 5]), '[bbox] must be an Array of 4 numbers') | ||
}) | ||
@@ -124,4 +124,4 @@ | ||
test('bboxLatLngToMeters', t => { | ||
const bbox = mercator.bboxLatLngToMeters(BOUNDS_LATLNG) | ||
t.deepEqual(bbox.map(i => i.toFixed(2)), BOUNDS.map(i => i.toFixed(2))) | ||
const bbox = mercator.bboxLatLngToMeters(BBOX_LATLNG) | ||
t.deepEqual(bbox.map(i => i.toFixed(2)), BBOX.map(i => i.toFixed(2))) | ||
}) | ||
@@ -128,0 +128,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
887019
23330
529