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 3.0.0 to 3.0.1

1

CHANGELOG.md

@@ -6,2 +6,3 @@

- Added `bboxToTile`
- Support ES modules

@@ -8,0 +9,0 @@

@@ -765,2 +765,36 @@ 'use strict';

/**
* Get the smallest tile to cover a bbox
*
* @param {Array<number>} bbox BBox
* @returns {Array<number>} tile Tile
* @example
* var tile = bboxToTile([-178, 84, -177, 85])
* //=tile
*/
function bboxToTile (bboxCoords) {
var min = pointToTile(bboxCoords[0], bboxCoords[1], 32);
var max = pointToTile(bboxCoords[2], bboxCoords[3], 32);
var bbox = [min[0], min[1], max[0], max[1]];
var z = getBboxZoom(bbox);
if (z === 0) return [0, 0, 0]
var x = bbox[0] >>> (32 - z);
var y = bbox[1] >>> (32 - z);
return [x, y, z]
}
function getBboxZoom (bbox) {
var MAX_ZOOM = 28;
for (var z = 0; z < MAX_ZOOM; z++) {
var mask = 1 << (32 - (z + 1));
if (((bbox[0] & mask) !== (bbox[2] & mask)) ||
((bbox[1] & mask) !== (bbox[3] & mask))) {
return z
}
}
return MAX_ZOOM
}
exports.initialResolution = initialResolution;

@@ -800,1 +834,2 @@ exports.hash = hash;

exports.longitude = longitude;
exports.bboxToTile = bboxToTile;

3

index.d.ts

@@ -47,2 +47,3 @@ /**

export declare function pointToTile(lnglat: LngLat, zoom: number, validate?: boolean): Tile;
export declare function wrapTile(tile: Tile): Tile;
export declare function wrapTile(tile: Tile): Tile;
export declare function bboxToTile(bbox: BBox): Tile;

@@ -760,1 +760,35 @@ var originShift = 2 * Math.PI * 6378137 / 2.0

}
/**
* Get the smallest tile to cover a bbox
*
* @param {Array<number>} bbox BBox
* @returns {Array<number>} tile Tile
* @example
* var tile = bboxToTile([-178, 84, -177, 85])
* //=tile
*/
export function bboxToTile (bboxCoords) {
var min = pointToTile(bboxCoords[0], bboxCoords[1], 32)
var max = pointToTile(bboxCoords[2], bboxCoords[3], 32)
var bbox = [min[0], min[1], max[0], max[1]]
var z = getBboxZoom(bbox)
if (z === 0) return [0, 0, 0]
var x = bbox[0] >>> (32 - z)
var y = bbox[1] >>> (32 - z)
return [x, y, z]
}
function getBboxZoom (bbox) {
var MAX_ZOOM = 28
for (var z = 0; z < MAX_ZOOM; z++) {
var mask = 1 << (32 - (z + 1))
if (((bbox[0] & mask) !== (bbox[2] & mask)) ||
((bbox[1] & mask) !== (bbox[3] & mask))) {
return z
}
}
return MAX_ZOOM
}
{
"name": "global-mercator",
"version": "3.0.0",
"version": "3.0.1",
"description": "Tools to help with TMS, Quadkey & Google (XYZ) Tiles",

@@ -19,6 +19,6 @@ "repository": {

"scripts": {
"pretest": "standard",
"test": "node -r @std/esm test.js",
"postest": "rollup -f cjs -o global-mercator.js index.js",
"bench": "node -r @std/esm bench.js",
"pretest": "rollup -c rollup.config.js",
"test": "tap test.js --coverage",
"posttest": "standard index.js",
"bench": "node bench.js",
"docs": "documentation readme index.js --shallow --section=API"

@@ -53,14 +53,9 @@ },

"devDependencies": {
"@mapbox/tilebelt": "*",
"@std/esm": "*",
"benchmark": "*",
"documentation": "*",
"rollup": "*",
"standard": "*",
"tape": "*"
"tap": "*"
},
"dependencies": {},
"@std/esm": {
"esm": "js",
"cjs": true
}
"dependencies": {}
}

@@ -74,2 +74,3 @@ # Global Mercator

| [wrapTile(tile)](#wraptile) | Handles tiles which crosses the 180th meridian |
| [bboxToTile(bbox)](#bboxtotile) | Get the smallest tile to cover a bbox |

@@ -660,1 +661,19 @@ ## API

Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** modified longitude
### bboxToTile
Get the smallest tile to cover a bbox
**Parameters**
- `bboxCoords`
- `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)>** BBox
**Examples**
```javascript
var tile = bboxToTile([-178, 84, -177, 85])
//=tile
```
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)>** tile Tile
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