@turf/bbox-polygon 7.0.0-alpha.2 → 7.1.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -9
- package/dist/cjs/index.cjs +28 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +26 -0
- package/dist/{js → esm}/index.d.ts +6 -3
- package/dist/esm/index.js +28 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +29 -24
- package/dist/es/index.js +0 -35
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -38
package/README.md
CHANGED
|
@@ -41,26 +41,21 @@ Returns **[Feature][6]<[Polygon][7]>** a Polygon representation of the bounding
|
|
|
41
41
|
|
|
42
42
|
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
43
43
|
|
|
44
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
45
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
46
|
-
./scripts/generate-readmes in the turf project. -->
|
|
44
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
47
45
|
|
|
48
46
|
---
|
|
49
47
|
|
|
50
|
-
This module is part of the [Turfjs project](
|
|
51
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
52
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
53
|
-
PRs and issues.
|
|
48
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
54
49
|
|
|
55
50
|
### Installation
|
|
56
51
|
|
|
57
|
-
Install this module individually:
|
|
52
|
+
Install this single module individually:
|
|
58
53
|
|
|
59
54
|
```sh
|
|
60
55
|
$ npm install @turf/bbox-polygon
|
|
61
56
|
```
|
|
62
57
|
|
|
63
|
-
Or install the
|
|
58
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
64
59
|
|
|
65
60
|
```sh
|
|
66
61
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
|
+
var _helpers = require('@turf/helpers');
|
|
3
|
+
function bboxPolygon(bbox, options = {}) {
|
|
4
|
+
const west = Number(bbox[0]);
|
|
5
|
+
const south = Number(bbox[1]);
|
|
6
|
+
const east = Number(bbox[2]);
|
|
7
|
+
const north = Number(bbox[3]);
|
|
8
|
+
if (bbox.length === 6) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"@turf/bbox-polygon does not support BBox with 6 positions"
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const lowLeft = [west, south];
|
|
14
|
+
const topLeft = [west, north];
|
|
15
|
+
const topRight = [east, north];
|
|
16
|
+
const lowRight = [east, south];
|
|
17
|
+
return _helpers.polygon.call(void 0,
|
|
18
|
+
[[lowLeft, lowRight, topRight, topLeft, lowLeft]],
|
|
19
|
+
options.properties,
|
|
20
|
+
{ bbox, id: options.id }
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
var turf_bbox_polygon_default = bboxPolygon;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.bboxPolygon = bboxPolygon; exports.default = turf_bbox_polygon_default;
|
|
28
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AACA,SAAS,eAAmB;AAmB5B,SAAS,YACP,MACA,UAGI,CAAC,GACgB;AAIrB,QAAM,OAAO,OAAO,KAAK,CAAC,CAAC;AAC3B,QAAM,QAAQ,OAAO,KAAK,CAAC,CAAC;AAC5B,QAAM,OAAO,OAAO,KAAK,CAAC,CAAC;AAC3B,QAAM,QAAQ,OAAO,KAAK,CAAC,CAAC;AAE5B,MAAI,KAAK,WAAW,GAAG;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,CAAC,MAAM,KAAK;AAC5B,QAAM,UAAU,CAAC,MAAM,KAAK;AAC5B,QAAM,WAAW,CAAC,MAAM,KAAK;AAC7B,QAAM,WAAW,CAAC,MAAM,KAAK;AAE7B,SAAO;AAAA,IACL,CAAC,CAAC,SAAS,UAAU,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,QAAQ;AAAA,IACR,EAAE,MAAM,IAAI,QAAQ,GAAG;AAAA,EACzB;AACF;AAGA,IAAO,4BAAQ","sourcesContent":["import { BBox, Feature, Polygon, GeoJsonProperties } from \"geojson\";\nimport { polygon, Id } from \"@turf/helpers\";\n\n/**\n * Takes a bbox and returns an equivalent {@link Polygon|polygon}.\n *\n * @name bboxPolygon\n * @param {BBox} bbox extent in [minX, minY, maxX, maxY] order\n * @param {Object} [options={}] Optional parameters\n * @param {Properties} [options.properties={}] Translate properties to Polygon\n * @param {string|number} [options.id={}] Translate Id to Polygon\n * @returns {Feature<Polygon>} a Polygon representation of the bounding box\n * @example\n * var bbox = [0, 0, 10, 10];\n *\n * var poly = turf.bboxPolygon(bbox);\n *\n * //addToMap\n * var addToMap = [poly]\n */\nfunction bboxPolygon<P extends GeoJsonProperties = GeoJsonProperties>(\n bbox: BBox,\n options: {\n properties?: P;\n id?: Id;\n } = {}\n): Feature<Polygon, P> {\n // Convert BBox positions to Numbers\n // No performance loss for including Number()\n // https://github.com/Turfjs/turf/issues/1119\n const west = Number(bbox[0]);\n const south = Number(bbox[1]);\n const east = Number(bbox[2]);\n const north = Number(bbox[3]);\n\n if (bbox.length === 6) {\n throw new Error(\n \"@turf/bbox-polygon does not support BBox with 6 positions\"\n );\n }\n\n const lowLeft = [west, south];\n const topLeft = [west, north];\n const topRight = [east, north];\n const lowRight = [east, south];\n\n return polygon(\n [[lowLeft, lowRight, topRight, topLeft, lowLeft]],\n options.properties,\n { bbox, id: options.id }\n );\n}\n\nexport { bboxPolygon };\nexport default bboxPolygon;\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GeoJsonProperties, BBox, Feature, Polygon } from 'geojson';
|
|
2
|
+
import { Id } from '@turf/helpers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Takes a bbox and returns an equivalent {@link Polygon|polygon}.
|
|
6
|
+
*
|
|
7
|
+
* @name bboxPolygon
|
|
8
|
+
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
|
|
9
|
+
* @param {Object} [options={}] Optional parameters
|
|
10
|
+
* @param {Properties} [options.properties={}] Translate properties to Polygon
|
|
11
|
+
* @param {string|number} [options.id={}] Translate Id to Polygon
|
|
12
|
+
* @returns {Feature<Polygon>} a Polygon representation of the bounding box
|
|
13
|
+
* @example
|
|
14
|
+
* var bbox = [0, 0, 10, 10];
|
|
15
|
+
*
|
|
16
|
+
* var poly = turf.bboxPolygon(bbox);
|
|
17
|
+
*
|
|
18
|
+
* //addToMap
|
|
19
|
+
* var addToMap = [poly]
|
|
20
|
+
*/
|
|
21
|
+
declare function bboxPolygon<P extends GeoJsonProperties = GeoJsonProperties>(bbox: BBox, options?: {
|
|
22
|
+
properties?: P;
|
|
23
|
+
id?: Id;
|
|
24
|
+
}): Feature<Polygon, P>;
|
|
25
|
+
|
|
26
|
+
export { bboxPolygon, bboxPolygon as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BBox, Feature, Polygon
|
|
2
|
-
import { Id } from
|
|
1
|
+
import { GeoJsonProperties, BBox, Feature, Polygon } from 'geojson';
|
|
2
|
+
import { Id } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Takes a bbox and returns an equivalent {@link Polygon|polygon}.
|
|
5
6
|
*
|
|
@@ -17,7 +18,9 @@ import { Id } from "@turf/helpers";
|
|
|
17
18
|
* //addToMap
|
|
18
19
|
* var addToMap = [poly]
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
declare function bboxPolygon<P extends GeoJsonProperties = GeoJsonProperties>(bbox: BBox, options?: {
|
|
21
22
|
properties?: P;
|
|
22
23
|
id?: Id;
|
|
23
24
|
}): Feature<Polygon, P>;
|
|
25
|
+
|
|
26
|
+
export { bboxPolygon, bboxPolygon as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import { polygon } from "@turf/helpers";
|
|
3
|
+
function bboxPolygon(bbox, options = {}) {
|
|
4
|
+
const west = Number(bbox[0]);
|
|
5
|
+
const south = Number(bbox[1]);
|
|
6
|
+
const east = Number(bbox[2]);
|
|
7
|
+
const north = Number(bbox[3]);
|
|
8
|
+
if (bbox.length === 6) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"@turf/bbox-polygon does not support BBox with 6 positions"
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const lowLeft = [west, south];
|
|
14
|
+
const topLeft = [west, north];
|
|
15
|
+
const topRight = [east, north];
|
|
16
|
+
const lowRight = [east, south];
|
|
17
|
+
return polygon(
|
|
18
|
+
[[lowLeft, lowRight, topRight, topLeft, lowLeft]],
|
|
19
|
+
options.properties,
|
|
20
|
+
{ bbox, id: options.id }
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
var turf_bbox_polygon_default = bboxPolygon;
|
|
24
|
+
export {
|
|
25
|
+
bboxPolygon,
|
|
26
|
+
turf_bbox_polygon_default as default
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { BBox, Feature, Polygon, GeoJsonProperties } from \"geojson\";\nimport { polygon, Id } from \"@turf/helpers\";\n\n/**\n * Takes a bbox and returns an equivalent {@link Polygon|polygon}.\n *\n * @name bboxPolygon\n * @param {BBox} bbox extent in [minX, minY, maxX, maxY] order\n * @param {Object} [options={}] Optional parameters\n * @param {Properties} [options.properties={}] Translate properties to Polygon\n * @param {string|number} [options.id={}] Translate Id to Polygon\n * @returns {Feature<Polygon>} a Polygon representation of the bounding box\n * @example\n * var bbox = [0, 0, 10, 10];\n *\n * var poly = turf.bboxPolygon(bbox);\n *\n * //addToMap\n * var addToMap = [poly]\n */\nfunction bboxPolygon<P extends GeoJsonProperties = GeoJsonProperties>(\n bbox: BBox,\n options: {\n properties?: P;\n id?: Id;\n } = {}\n): Feature<Polygon, P> {\n // Convert BBox positions to Numbers\n // No performance loss for including Number()\n // https://github.com/Turfjs/turf/issues/1119\n const west = Number(bbox[0]);\n const south = Number(bbox[1]);\n const east = Number(bbox[2]);\n const north = Number(bbox[3]);\n\n if (bbox.length === 6) {\n throw new Error(\n \"@turf/bbox-polygon does not support BBox with 6 positions\"\n );\n }\n\n const lowLeft = [west, south];\n const topLeft = [west, north];\n const topRight = [east, north];\n const lowRight = [east, south];\n\n return polygon(\n [[lowLeft, lowRight, topRight, topLeft, lowLeft]],\n options.properties,\n { bbox, id: options.id }\n );\n}\n\nexport { bboxPolygon };\nexport default bboxPolygon;\n"],"mappings":";AACA,SAAS,eAAmB;AAmB5B,SAAS,YACP,MACA,UAGI,CAAC,GACgB;AAIrB,QAAM,OAAO,OAAO,KAAK,CAAC,CAAC;AAC3B,QAAM,QAAQ,OAAO,KAAK,CAAC,CAAC;AAC5B,QAAM,OAAO,OAAO,KAAK,CAAC,CAAC;AAC3B,QAAM,QAAQ,OAAO,KAAK,CAAC,CAAC;AAE5B,MAAI,KAAK,WAAW,GAAG;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,CAAC,MAAM,KAAK;AAC5B,QAAM,UAAU,CAAC,MAAM,KAAK;AAC5B,QAAM,WAAW,CAAC,MAAM,KAAK;AAC7B,QAAM,WAAW,CAAC,MAAM,KAAK;AAE7B,SAAO;AAAA,IACL,CAAC,CAAC,SAAS,UAAU,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,QAAQ;AAAA,IACR,EAAE,MAAM,IAAI,QAAQ,GAAG;AAAA,EACzB;AACF;AAGA,IAAO,4BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/bbox-polygon",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0-alpha.7+0ce6ecca0",
|
|
4
4
|
"description": "turf bbox-polygon module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,42 +23,47 @@
|
|
|
23
23
|
"extent",
|
|
24
24
|
"bbox"
|
|
25
25
|
],
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/cjs/index.cjs",
|
|
28
|
+
"module": "dist/esm/index.js",
|
|
29
|
+
"types": "dist/esm/index.d.ts",
|
|
28
30
|
"exports": {
|
|
29
31
|
"./package.json": "./package.json",
|
|
30
32
|
".": {
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/esm/index.d.ts",
|
|
35
|
+
"default": "./dist/esm/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/cjs/index.d.cts",
|
|
39
|
+
"default": "./dist/cjs/index.cjs"
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
},
|
|
36
|
-
"types": "dist/js/index.d.ts",
|
|
37
43
|
"sideEffects": false,
|
|
38
44
|
"files": [
|
|
39
45
|
"dist"
|
|
40
46
|
],
|
|
41
47
|
"scripts": {
|
|
42
|
-
"bench": "tsx bench.
|
|
43
|
-
"build": "
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"test": "npm-run-all test:*",
|
|
48
|
-
"test:tape": "tsx test.js"
|
|
48
|
+
"bench": "tsx bench.ts",
|
|
49
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
50
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
51
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
52
|
+
"test:tape": "tsx test.ts"
|
|
49
53
|
},
|
|
50
54
|
"devDependencies": {
|
|
51
|
-
"@types/
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
55
|
+
"@types/benchmark": "^2.1.5",
|
|
56
|
+
"@types/tape": "^4.2.32",
|
|
57
|
+
"benchmark": "^2.1.4",
|
|
58
|
+
"npm-run-all": "^4.1.5",
|
|
59
|
+
"tape": "^5.7.2",
|
|
60
|
+
"tsup": "^8.0.1",
|
|
61
|
+
"tsx": "^4.6.2",
|
|
62
|
+
"typescript": "^5.2.2"
|
|
58
63
|
},
|
|
59
64
|
"dependencies": {
|
|
60
|
-
"@turf/helpers": "^7.
|
|
61
|
-
"tslib": "^2.
|
|
65
|
+
"@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
|
|
66
|
+
"tslib": "^2.6.2"
|
|
62
67
|
},
|
|
63
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
|
|
64
69
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { polygon } from "@turf/helpers";
|
|
2
|
-
/**
|
|
3
|
-
* Takes a bbox and returns an equivalent {@link Polygon|polygon}.
|
|
4
|
-
*
|
|
5
|
-
* @name bboxPolygon
|
|
6
|
-
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
|
|
7
|
-
* @param {Object} [options={}] Optional parameters
|
|
8
|
-
* @param {Properties} [options.properties={}] Translate properties to Polygon
|
|
9
|
-
* @param {string|number} [options.id={}] Translate Id to Polygon
|
|
10
|
-
* @returns {Feature<Polygon>} a Polygon representation of the bounding box
|
|
11
|
-
* @example
|
|
12
|
-
* var bbox = [0, 0, 10, 10];
|
|
13
|
-
*
|
|
14
|
-
* var poly = turf.bboxPolygon(bbox);
|
|
15
|
-
*
|
|
16
|
-
* //addToMap
|
|
17
|
-
* var addToMap = [poly]
|
|
18
|
-
*/
|
|
19
|
-
export default function bboxPolygon(bbox, options = {}) {
|
|
20
|
-
// Convert BBox positions to Numbers
|
|
21
|
-
// No performance loss for including Number()
|
|
22
|
-
// https://github.com/Turfjs/turf/issues/1119
|
|
23
|
-
const west = Number(bbox[0]);
|
|
24
|
-
const south = Number(bbox[1]);
|
|
25
|
-
const east = Number(bbox[2]);
|
|
26
|
-
const north = Number(bbox[3]);
|
|
27
|
-
if (bbox.length === 6) {
|
|
28
|
-
throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");
|
|
29
|
-
}
|
|
30
|
-
const lowLeft = [west, south];
|
|
31
|
-
const topLeft = [west, north];
|
|
32
|
-
const topRight = [east, north];
|
|
33
|
-
const lowRight = [east, south];
|
|
34
|
-
return polygon([[lowLeft, lowRight, topRight, topLeft, lowLeft]], options.properties, { bbox, id: options.id });
|
|
35
|
-
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const helpers_1 = require("@turf/helpers");
|
|
4
|
-
/**
|
|
5
|
-
* Takes a bbox and returns an equivalent {@link Polygon|polygon}.
|
|
6
|
-
*
|
|
7
|
-
* @name bboxPolygon
|
|
8
|
-
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
|
|
9
|
-
* @param {Object} [options={}] Optional parameters
|
|
10
|
-
* @param {Properties} [options.properties={}] Translate properties to Polygon
|
|
11
|
-
* @param {string|number} [options.id={}] Translate Id to Polygon
|
|
12
|
-
* @returns {Feature<Polygon>} a Polygon representation of the bounding box
|
|
13
|
-
* @example
|
|
14
|
-
* var bbox = [0, 0, 10, 10];
|
|
15
|
-
*
|
|
16
|
-
* var poly = turf.bboxPolygon(bbox);
|
|
17
|
-
*
|
|
18
|
-
* //addToMap
|
|
19
|
-
* var addToMap = [poly]
|
|
20
|
-
*/
|
|
21
|
-
function bboxPolygon(bbox, options = {}) {
|
|
22
|
-
// Convert BBox positions to Numbers
|
|
23
|
-
// No performance loss for including Number()
|
|
24
|
-
// https://github.com/Turfjs/turf/issues/1119
|
|
25
|
-
const west = Number(bbox[0]);
|
|
26
|
-
const south = Number(bbox[1]);
|
|
27
|
-
const east = Number(bbox[2]);
|
|
28
|
-
const north = Number(bbox[3]);
|
|
29
|
-
if (bbox.length === 6) {
|
|
30
|
-
throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");
|
|
31
|
-
}
|
|
32
|
-
const lowLeft = [west, south];
|
|
33
|
-
const topLeft = [west, north];
|
|
34
|
-
const topRight = [east, north];
|
|
35
|
-
const lowRight = [east, south];
|
|
36
|
-
return helpers_1.polygon([[lowLeft, lowRight, topRight, topLeft, lowLeft]], options.properties, { bbox, id: options.id });
|
|
37
|
-
}
|
|
38
|
-
exports.default = bboxPolygon;
|