@turf/bbox-polygon 6.4.0 → 7.0.0-alpha.0
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 +8 -7
- package/dist/es/index.js +10 -11
- package/dist/js/index.d.ts +3 -2
- package/dist/js/index.js +11 -12
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
|
|
7
7
|
Takes a bbox and returns an equivalent [polygon][1].
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- `options.properties` **Properties** Translate properties to Polygon (optional, default `{}`)
|
|
14
|
-
- `options.id` **([string][4] \| [number][5])** Translate Id to Polygon (optional, default `{}`)
|
|
11
|
+
* `bbox` **[BBox][2]** extent in \[minX, minY, maxX, maxY] order
|
|
12
|
+
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
|
|
15
13
|
|
|
16
|
-
**
|
|
14
|
+
* `options.properties` **Properties** Translate properties to Polygon (optional, default `{}`)
|
|
15
|
+
* `options.id` **([string][4] | [number][5])** Translate Id to Polygon (optional, default `{}`)
|
|
16
|
+
|
|
17
|
+
### Examples
|
|
17
18
|
|
|
18
19
|
```javascript
|
|
19
20
|
var bbox = [0, 0, 10, 10];
|
|
@@ -24,7 +25,7 @@ var poly = turf.bboxPolygon(bbox);
|
|
|
24
25
|
var addToMap = [poly]
|
|
25
26
|
```
|
|
26
27
|
|
|
27
|
-
Returns **[Feature][6]
|
|
28
|
+
Returns **[Feature][6]<[Polygon][7]>** a Polygon representation of the bounding box
|
|
28
29
|
|
|
29
30
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
30
31
|
|
package/dist/es/index.js
CHANGED
|
@@ -16,21 +16,20 @@ import { polygon } from "@turf/helpers";
|
|
|
16
16
|
* //addToMap
|
|
17
17
|
* var addToMap = [poly]
|
|
18
18
|
*/
|
|
19
|
-
export default function bboxPolygon(bbox, options) {
|
|
20
|
-
if (options === void 0) { options = {}; }
|
|
19
|
+
export default function bboxPolygon(bbox, options = {}) {
|
|
21
20
|
// Convert BBox positions to Numbers
|
|
22
21
|
// No performance loss for including Number()
|
|
23
22
|
// https://github.com/Turfjs/turf/issues/1119
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const west = Number(bbox[0]);
|
|
24
|
+
const south = Number(bbox[1]);
|
|
25
|
+
const east = Number(bbox[2]);
|
|
26
|
+
const north = Number(bbox[3]);
|
|
28
27
|
if (bbox.length === 6) {
|
|
29
28
|
throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return polygon([[lowLeft, lowRight, topRight, topLeft, lowLeft]], options.properties, { bbox
|
|
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 });
|
|
36
35
|
}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BBox, Feature,
|
|
1
|
+
import { BBox, Feature, Polygon, GeoJsonProperties } from "geojson";
|
|
2
|
+
import { Id } from "@turf/helpers";
|
|
2
3
|
/**
|
|
3
4
|
* Takes a bbox and returns an equivalent {@link Polygon|polygon}.
|
|
4
5
|
*
|
|
@@ -16,7 +17,7 @@ import { BBox, Feature, Id, Polygon, Properties } from "@turf/helpers";
|
|
|
16
17
|
* //addToMap
|
|
17
18
|
* var addToMap = [poly]
|
|
18
19
|
*/
|
|
19
|
-
export default function bboxPolygon<P =
|
|
20
|
+
export default function bboxPolygon<P = GeoJsonProperties>(bbox: BBox, options?: {
|
|
20
21
|
properties?: P;
|
|
21
22
|
id?: Id;
|
|
22
23
|
}): Feature<Polygon, P>;
|
package/dist/js/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const helpers_1 = require("@turf/helpers");
|
|
4
4
|
/**
|
|
5
5
|
* Takes a bbox and returns an equivalent {@link Polygon|polygon}.
|
|
6
6
|
*
|
|
@@ -18,22 +18,21 @@ var helpers_1 = require("@turf/helpers");
|
|
|
18
18
|
* //addToMap
|
|
19
19
|
* var addToMap = [poly]
|
|
20
20
|
*/
|
|
21
|
-
function bboxPolygon(bbox, options) {
|
|
22
|
-
if (options === void 0) { options = {}; }
|
|
21
|
+
function bboxPolygon(bbox, options = {}) {
|
|
23
22
|
// Convert BBox positions to Numbers
|
|
24
23
|
// No performance loss for including Number()
|
|
25
24
|
// https://github.com/Turfjs/turf/issues/1119
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const west = Number(bbox[0]);
|
|
26
|
+
const south = Number(bbox[1]);
|
|
27
|
+
const east = Number(bbox[2]);
|
|
28
|
+
const north = Number(bbox[3]);
|
|
30
29
|
if (bbox.length === 6) {
|
|
31
30
|
throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return helpers_1.polygon([[lowLeft, lowRight, topRight, topLeft, lowLeft]], options.properties, { bbox
|
|
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 });
|
|
38
37
|
}
|
|
39
38
|
exports.default = bboxPolygon;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/bbox-polygon",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf bbox-polygon module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git://github.com/Turfjs/turf.git"
|
|
14
14
|
},
|
|
15
|
+
"funding": "https://opencollective.com/turf",
|
|
15
16
|
"publishConfig": {
|
|
16
17
|
"access": "public"
|
|
17
18
|
},
|
|
@@ -55,7 +56,8 @@
|
|
|
55
56
|
"typescript": "*"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
|
-
"@turf/helpers": "^
|
|
59
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
60
|
+
"tslib": "^2.3.0"
|
|
59
61
|
},
|
|
60
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
61
63
|
}
|