@turf/center-mean 6.5.0 → 7.0.0-alpha.1
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 +10 -9
- package/dist/es/index.js +6 -7
- package/dist/js/index.d.ts +3 -2
- package/dist/js/index.js +7 -8
- package/package.json +14 -12
package/README.md
CHANGED
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
Takes a [Feature][1] or [FeatureCollection][2] and returns the mean center. Can be weighted.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- `options.properties` **[Object][4]** Translate GeoJSON Properties to Point (optional, default `{}`)
|
|
14
|
-
- `options.bbox` **[Object][4]** Translate GeoJSON BBox to Point (optional, default `{}`)
|
|
15
|
-
- `options.id` **[Object][4]** Translate GeoJSON Id to Point (optional, default `{}`)
|
|
16
|
-
- `options.weight` **[string][5]?** the property name used to weight the center
|
|
11
|
+
* `geojson` **[GeoJSON][3]** GeoJSON to be centered
|
|
12
|
+
* `options` **[Object][4]** Optional parameters (optional, default `{}`)
|
|
17
13
|
|
|
18
|
-
**
|
|
14
|
+
* `options.properties` **[Object][4]** Translate GeoJSON Properties to Point (optional, default `{}`)
|
|
15
|
+
* `options.bbox` **[Object][4]** Translate GeoJSON BBox to Point (optional, default `{}`)
|
|
16
|
+
* `options.id` **[Object][4]** Translate GeoJSON Id to Point (optional, default `{}`)
|
|
17
|
+
* `options.weight` **[string][5]?** the property name used to weight the center
|
|
18
|
+
|
|
19
|
+
### Examples
|
|
19
20
|
|
|
20
21
|
```javascript
|
|
21
22
|
var features = turf.featureCollection([
|
|
@@ -33,7 +34,7 @@ mean.properties['marker-size'] = 'large';
|
|
|
33
34
|
mean.properties['marker-color'] = '#000';
|
|
34
35
|
```
|
|
35
36
|
|
|
36
|
-
Returns **[Feature][6]
|
|
37
|
+
Returns **[Feature][6]<[Point][7]>** a Point feature at the mean center point of all input features
|
|
37
38
|
|
|
38
39
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
39
40
|
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { geomEach, coordEach } from "@turf/meta";
|
|
2
|
-
import { isNumber, point
|
|
2
|
+
import { isNumber, point } from "@turf/helpers";
|
|
3
3
|
/**
|
|
4
4
|
* Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
|
|
5
5
|
*
|
|
@@ -27,13 +27,12 @@ import { isNumber, point, } from "@turf/helpers";
|
|
|
27
27
|
* mean.properties['marker-color'] = '#000';
|
|
28
28
|
*/
|
|
29
29
|
function centerMean(geojson, // To-Do include Typescript AllGeoJSON
|
|
30
|
-
options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var sumNs = 0;
|
|
30
|
+
options = {}) {
|
|
31
|
+
let sumXs = 0;
|
|
32
|
+
let sumYs = 0;
|
|
33
|
+
let sumNs = 0;
|
|
35
34
|
geomEach(geojson, function (geom, featureIndex, properties) {
|
|
36
|
-
|
|
35
|
+
let weight = options.weight ? properties === null || properties === void 0 ? void 0 : properties[options.weight] : undefined;
|
|
37
36
|
weight = weight === undefined || weight === null ? 1 : weight;
|
|
38
37
|
if (!isNumber(weight))
|
|
39
38
|
throw new Error("weight value must be a number for feature index " + featureIndex);
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Feature, Point,
|
|
1
|
+
import { BBox, Feature, Point, GeoJsonProperties } from "geojson";
|
|
2
|
+
import { Id } from "@turf/helpers";
|
|
2
3
|
/**
|
|
3
4
|
* Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
|
|
4
5
|
*
|
|
@@ -25,7 +26,7 @@ import { Feature, Point, Properties, BBox, Id } from "@turf/helpers";
|
|
|
25
26
|
* mean.properties['marker-size'] = 'large';
|
|
26
27
|
* mean.properties['marker-color'] = '#000';
|
|
27
28
|
*/
|
|
28
|
-
declare function centerMean<P =
|
|
29
|
+
declare function centerMean<P = GeoJsonProperties>(geojson: any, // To-Do include Typescript AllGeoJSON
|
|
29
30
|
options?: {
|
|
30
31
|
properties?: P;
|
|
31
32
|
bbox?: BBox;
|
package/dist/js/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const meta_1 = require("@turf/meta");
|
|
4
|
+
const helpers_1 = require("@turf/helpers");
|
|
5
5
|
/**
|
|
6
6
|
* Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
|
|
7
7
|
*
|
|
@@ -29,13 +29,12 @@ var helpers_1 = require("@turf/helpers");
|
|
|
29
29
|
* mean.properties['marker-color'] = '#000';
|
|
30
30
|
*/
|
|
31
31
|
function centerMean(geojson, // To-Do include Typescript AllGeoJSON
|
|
32
|
-
options) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var sumNs = 0;
|
|
32
|
+
options = {}) {
|
|
33
|
+
let sumXs = 0;
|
|
34
|
+
let sumYs = 0;
|
|
35
|
+
let sumNs = 0;
|
|
37
36
|
meta_1.geomEach(geojson, function (geom, featureIndex, properties) {
|
|
38
|
-
|
|
37
|
+
let weight = options.weight ? properties === null || properties === void 0 ? void 0 : properties[options.weight] : undefined;
|
|
39
38
|
weight = weight === undefined || weight === null ? 1 : weight;
|
|
40
39
|
if (!helpers_1.isNumber(weight))
|
|
41
40
|
throw new Error("weight value must be a number for feature index " + featureIndex);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/center-mean",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "turf center-mean module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"exports": {
|
|
34
34
|
"./package.json": "./package.json",
|
|
35
35
|
".": {
|
|
36
|
+
"types": "./dist/js/index.d.ts",
|
|
36
37
|
"import": "./dist/es/index.js",
|
|
37
38
|
"require": "./dist/js/index.js"
|
|
38
39
|
}
|
|
@@ -43,33 +44,34 @@
|
|
|
43
44
|
"dist"
|
|
44
45
|
],
|
|
45
46
|
"scripts": {
|
|
46
|
-
"bench": "
|
|
47
|
+
"bench": "tsx bench.js",
|
|
47
48
|
"build": "npm-run-all build:*",
|
|
48
49
|
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
|
|
49
50
|
"build:js": "tsc",
|
|
50
|
-
"docs": "
|
|
51
|
+
"docs": "tsx ../../scripts/generate-readmes",
|
|
51
52
|
"test": "npm-run-all test:*",
|
|
52
|
-
"test:tape": "
|
|
53
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
53
|
+
"test:tape": "tsx test.js",
|
|
54
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@turf/center": "^
|
|
57
|
-
"@turf/truncate": "^
|
|
57
|
+
"@turf/center": "^7.0.0-alpha.1",
|
|
58
|
+
"@turf/truncate": "^7.0.0-alpha.1",
|
|
58
59
|
"@types/tape": "*",
|
|
59
60
|
"benchmark": "*",
|
|
60
61
|
"glob": "*",
|
|
61
62
|
"load-json-file": "*",
|
|
62
63
|
"npm-run-all": "*",
|
|
63
64
|
"tape": "*",
|
|
64
|
-
"ts-node": "*",
|
|
65
65
|
"tslint": "*",
|
|
66
|
+
"tsx": "*",
|
|
66
67
|
"typescript": "*",
|
|
67
68
|
"write-json-file": "*"
|
|
68
69
|
},
|
|
69
70
|
"dependencies": {
|
|
70
|
-
"@turf/bbox": "^
|
|
71
|
-
"@turf/helpers": "^
|
|
72
|
-
"@turf/meta": "^
|
|
71
|
+
"@turf/bbox": "^7.0.0-alpha.1",
|
|
72
|
+
"@turf/helpers": "^7.0.0-alpha.1",
|
|
73
|
+
"@turf/meta": "^7.0.0-alpha.1",
|
|
74
|
+
"tslib": "^2.3.0"
|
|
73
75
|
},
|
|
74
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
75
77
|
}
|