New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

to
1.2.1

.nyc_output/0f5004da1eb01495c4e35fa9302a90cb.json

6

HEADER.md

@@ -63,2 +63,6 @@ [![Build Status](https://travis-ci.org/DenisCarriere/global-mercator.svg?branch=master)](https://travis-ci.org/DenisCarriere/global-mercator)

| quadkeyToGoogle(quadkey) | Converts Quadkey to Google (XYZ) Tile.
| bboxToMeters(bbox) | Converts BBox from LngLat coordinates to Meters coordinates
| bboxToMeters(bbox) | Converts BBox from LngLat coordinates to Meters coordinates
| grid | Creates an Iterator of Tiles from a given BBox
| gridBulk | Creates a bulk Iterator of Tiles from a given BBox
| gridLevels | Creates a grid level pattern of arrays
| gridCount | Counts the total amount of tiles from a given BBox

@@ -407,2 +407,103 @@ "use strict";

/**
* Creates an Iterator of Tiles from a given BBox
*
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} minZoom Minimum Zoom
* @param {number} maxZoom Maximum Zoom
* @returns {IterableIterator<Tile>} Iterable Tiles from BBox
* @example
* const iterable = grid([-180.0, -90.0, 180, 90], 3, 8)
* //=iterable
*/
function* grid(bbox, minZoom, maxZoom) {
for (const [tile_columns, tile_rows, zoom] of gridLevels(bbox, minZoom, maxZoom)) {
for (const tile_row of tile_rows) {
for (const tile_column of tile_columns) {
yield [tile_column, tile_row, zoom];
}
}
}
}
exports.grid = grid;
/**
* Creates a bulk Iterator of Tiles from a given BBox
*
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} minZoom Minimum Zoom
* @param {number} maxZoom Maximum Zoom
* @param {number} size Maximum size of Tile[]
* @returns {IterableIterator<Tile[]>} Bulk iterable Tiles from BBox
* @example
* const iterable = gridBulk([-180.0, -90.0, 180, 90], 3, 8, 5000)
* //=iterable
*/
function* gridBulk(bbox, minZoom, maxZoom, size) {
const iterable = grid(bbox, minZoom, maxZoom);
let container = [];
let i = 0;
while (true) {
i++;
const { value, done } = iterable.next();
if (value) {
container.push(value);
}
if (i % size === 0) {
yield container;
container = [];
}
if (done) {
yield container;
break;
}
}
}
exports.gridBulk = gridBulk;
/**
* Creates a grid level pattern of arrays
*
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} minZoom Minimum Zoom
* @param {number} maxZoom Maximum Zoom
* @returns {GridLevel[]} Grid Level
* @example
* const count = gridLevels([-180.0, -90.0, 180, 90], 3, 8)
* //=count
*/
function gridLevels(bbox, minZoom, maxZoom) {
const levels = [];
for (let zoom of range(minZoom, maxZoom + 1)) {
let [x1, y1, x2, y2] = bbox;
let t1 = lngLatToTile([x1, y1, zoom]);
let t2 = lngLatToTile([x2, y2, zoom]);
let minty = Math.min(t1[1], t2[1]);
let maxty = Math.max(t1[1], t2[1]);
let mintx = Math.min(t1[0], t2[0]);
let maxtx = Math.max(t1[0], t2[0]);
const tile_rows = range(minty, maxty + 1);
const tile_columns = range(mintx, maxtx + 1);
levels.push([tile_columns, tile_rows, zoom]);
}
return levels;
}
exports.gridLevels = gridLevels;
/**
* Counts the total amount of tiles from a given BBox
*
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} minZoom Minimum Zoom
* @param {number} maxZoom Maximum Zoom
* @returns {number} Total tiles from BBox
* @example
* const count = gridCount([-180.0, -90.0, 180, 90], 3, 8)
* //=count
*/
function gridCount(bbox, minZoom, maxZoom) {
let count = 0;
for (const [tile_columns, tile_rows] of gridLevels(bbox, minZoom, maxZoom)) {
count += tile_rows.length * tile_columns.length;
}
return count;
}
exports.gridCount = gridCount;
/**
* Retrieve resolution based on zoom level

@@ -583,24 +684,2 @@ *

exports.range = range;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
lngLatToMeters,
metersToLngLat,
metersToPixels,
lngLatToTile,
lngLatToGoogle,
metersToTile,
pixelsToMeters,
pixelsToTile,
tileToBBoxMeters,
tileToBBox,
googleToBBoxMeters,
googleToBBox,
tileToGoogle,
googleToTile,
googleToQuadkey,
tileToQuadkey,
quadkeyToTile,
quadkeyToGoogle,
bboxToMeters,
};
//# sourceMappingURL=index.js.map

@@ -33,2 +33,6 @@ export const tileSize = 256

export type Quadkey = string
/**
* GridLevel [tile_rows, tile_columns, zoom]
*/
export type GridLevel = [number[], number[], number]

@@ -431,2 +435,101 @@ /**

/**
* Creates an Iterator of Tiles from a given BBox
*
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} minZoom Minimum Zoom
* @param {number} maxZoom Maximum Zoom
* @returns {IterableIterator<Tile>} Iterable Tiles from BBox
* @example
* const iterable = grid([-180.0, -90.0, 180, 90], 3, 8)
* //=iterable
*/
export function * grid(bbox: BBox, minZoom: number, maxZoom: number): IterableIterator<Tile> {
for (const [tile_columns, tile_rows, zoom] of gridLevels(bbox, minZoom, maxZoom)) {
for (const tile_row of tile_rows) {
for (const tile_column of tile_columns) {
yield [tile_column, tile_row, zoom]
}
}
}
}
/**
* Creates a bulk Iterator of Tiles from a given BBox
*
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} minZoom Minimum Zoom
* @param {number} maxZoom Maximum Zoom
* @param {number} size Maximum size of Tile[]
* @returns {IterableIterator<Tile[]>} Bulk iterable Tiles from BBox
* @example
* const iterable = gridBulk([-180.0, -90.0, 180, 90], 3, 8, 5000)
* //=iterable
*/
export function * gridBulk(bbox: BBox, minZoom: number, maxZoom: number, size: number): IterableIterator<Tile[]> {
const iterable = grid(bbox, minZoom, maxZoom)
let container: Tile[] = []
let i = 0
while (true) {
i ++
const { value, done } = iterable.next()
if (value) { container.push(value) }
if (i % size === 0) {
yield container
container = []
}
if (done) {
yield container
break
}
}
}
/**
* Creates a grid level pattern of arrays
*
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} minZoom Minimum Zoom
* @param {number} maxZoom Maximum Zoom
* @returns {GridLevel[]} Grid Level
* @example
* const count = gridLevels([-180.0, -90.0, 180, 90], 3, 8)
* //=count
*/
export function gridLevels(bbox: BBox, minZoom: number, maxZoom: number): GridLevel[] {
const levels: GridLevel[] = []
for (let zoom of range(minZoom, maxZoom + 1)) {
let [x1, y1, x2, y2] = bbox
let t1 = lngLatToTile([x1, y1, zoom])
let t2 = lngLatToTile([x2, y2, zoom])
let minty = Math.min(t1[1], t2[1])
let maxty = Math.max(t1[1], t2[1])
let mintx = Math.min(t1[0], t2[0])
let maxtx = Math.max(t1[0], t2[0])
const tile_rows: number[] = range(minty, maxty + 1)
const tile_columns: number[] = range(mintx, maxtx + 1)
levels.push([tile_columns, tile_rows, zoom])
}
return levels
}
/**
* Counts the total amount of tiles from a given BBox
*
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} minZoom Minimum Zoom
* @param {number} maxZoom Maximum Zoom
* @returns {number} Total tiles from BBox
* @example
* const count = gridCount([-180.0, -90.0, 180, 90], 3, 8)
* //=count
*/
export function gridCount(bbox: BBox, minZoom: number, maxZoom: number): number {
let count = 0
for (const [tile_columns, tile_rows] of gridLevels(bbox, minZoom, maxZoom)) {
count += tile_rows.length * tile_columns.length
}
return count
}
/**
* Retrieve resolution based on zoom level

@@ -605,23 +708,1 @@ *

}
export default {
lngLatToMeters,
metersToLngLat,
metersToPixels,
lngLatToTile,
lngLatToGoogle,
metersToTile,
pixelsToMeters,
pixelsToTile,
tileToBBoxMeters,
tileToBBox,
googleToBBoxMeters,
googleToBBox,
tileToGoogle,
googleToTile,
googleToQuadkey,
tileToQuadkey,
quadkeyToTile,
quadkeyToGoogle,
bboxToMeters,
}

2

package.json
{
"name": "global-mercator",
"version": "1.1.1",
"version": "1.2.1",
"description": "Tools to help with TMS, Quadkey & Google (XYZ) Tiles",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -63,3 +63,7 @@ [![Build Status](https://travis-ci.org/DenisCarriere/global-mercator.svg?branch=master)](https://travis-ci.org/DenisCarriere/global-mercator)

| quadkeyToGoogle(quadkey) | Converts Quadkey to Google (XYZ) Tile.
| bboxToMeters(bbox) | Converts BBox from LngLat coordinates to Meters coordinates<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
| bboxToMeters(bbox) | Converts BBox from LngLat coordinates to Meters coordinates
| grid | Creates an Iterator of Tiles from a given BBox
| gridBulk | Creates a bulk Iterator of Tiles from a given BBox
| gridLevels | Creates a grid level pattern of arrays
| gridCount | Counts the total amount of tiles from a given BBox<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

@@ -437,2 +441,79 @@ # lngLatToMeters

# grid
Creates an Iterator of Tiles from a given BBox
**Parameters**
- `bbox` **[BBox](http://geojson.org/geojson-spec.html#bounding-boxes)** extent in [minX, minY, maxX, maxY] order
- `minZoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Minimum Zoom
- `maxZoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Maximum Zoom
**Examples**
```javascript
const iterable = grid([-180.0, -90.0, 180, 90], 3, 8)
//=iterable
```
Returns **IterableIterator&lt;[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)>** Iterable Tiles from BBox
# gridBulk
Creates a bulk Iterator of Tiles from a given BBox
**Parameters**
- `bbox` **[BBox](http://geojson.org/geojson-spec.html#bounding-boxes)** extent in [minX, minY, maxX, maxY] order
- `minZoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Minimum Zoom
- `maxZoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Maximum Zoom
- `size` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Maximum size of Tile\[]
**Examples**
```javascript
const iterable = gridBulk([-180.0, -90.0, 180, 90], 3, 8, 5000)
//=iterable
```
Returns **IterableIterator&lt;[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Tile](https://en.wikipedia.org/wiki/Tiled_web_map)>>** Bulk iterable Tiles from BBox
# gridLevels
Creates a grid level pattern of arrays
**Parameters**
- `bbox` **[BBox](http://geojson.org/geojson-spec.html#bounding-boxes)** extent in [minX, minY, maxX, maxY] order
- `minZoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Minimum Zoom
- `maxZoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Maximum Zoom
**Examples**
```javascript
const count = gridLevels([-180.0, -90.0, 180, 90], 3, 8)
//=count
```
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;GridLevel>** Grid Level
# gridCount
Counts the total amount of tiles from a given BBox
**Parameters**
- `bbox` **[BBox](http://geojson.org/geojson-spec.html#bounding-boxes)** extent in [minX, minY, maxX, maxY] order
- `minZoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Minimum Zoom
- `maxZoom` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Maximum Zoom
**Examples**
```javascript
const count = gridCount([-180.0, -90.0, 180, 90], 3, 8)
//=count
```
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Total tiles from BBox
# resolution

@@ -439,0 +520,0 @@

@@ -134,2 +134,25 @@ "use strict";

});
ava_1.default('grid', t => {
const iterable = mercator.grid([-180.0, -90.0, 180, 90], 3, 21);
t.deepEqual(iterable.next().value, [0, 0, 3]);
});
ava_1.default('gridBulk', t => {
const iterable = mercator.gridBulk([-180.0, -90.0, 180, 90], 3, 5, 5);
while (true) {
const { value, done } = iterable.next();
if (done) {
break;
}
t.deepEqual(typeof value, typeof []);
}
t.pass();
});
ava_1.default('gridCount', t => {
const count = mercator.gridCount([-180.0, -90.0, 180, 90], 3, 21);
t.deepEqual(count, 37773648480704);
});
ava_1.default('gridLevels', t => {
const levels = mercator.gridLevels([-180.0, -90.0, 180, 90], 3, 21);
t.deepEqual(levels.length, 19);
});
//# sourceMappingURL=test.js.map

@@ -162,1 +162,26 @@ import test from 'ava'

})
test('grid', t => {
const iterable = mercator.grid([-180.0, -90.0, 180, 90], 3, 21)
t.deepEqual(iterable.next().value, [0, 0, 3])
})
test('gridBulk', t => {
const iterable = mercator.gridBulk([-180.0, -90.0, 180, 90], 3, 5, 5)
while (true) {
const { value, done } = iterable.next()
if (done) { break }
t.deepEqual(typeof value, typeof [])
}
t.pass()
})
test('gridCount', t => {
const count = mercator.gridCount([-180.0, -90.0, 180, 90], 3, 21)
t.deepEqual(count, 37773648480704)
})
test('gridLevels', t => {
const levels = mercator.gridLevels([-180.0, -90.0, 180, 90], 3, 21)
t.deepEqual(levels.length, 19)
})
{
/*
* Possible values:
* - the name of a built-in config
* - the name of an NPM module which has a "main" file that exports a config object
* - a relative path to a JSON file
*/
"extends": "tslint:latest",
"rules": {
/*
* Any rules specified here will override those from the base config we are extending
*/
"semicolon": [true, "never"],

@@ -20,10 +11,6 @@ "no-constructor-vars": true,

"max-line-length": [true, 150],
"no-console": [false]
"no-console": [false],
"interface-name": [false]
},
"rulesDirectory": [
/*
* A list of relative or absolute paths to directories that contain custom rules.
* See the Custom Rules documentation below for more details.
*/
]
"rulesDirectory": [ ]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet