@turf/center-mean 7.0.0-alpha.0 → 7.0.0-alpha.110
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 +35 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +6 -4
- package/dist/{es/index.js → esm/index.d.mts} +12 -24
- package/dist/esm/index.mjs +35 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +36 -30
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -52
package/README.md
CHANGED
|
@@ -50,26 +50,21 @@ Returns **[Feature][6]<[Point][7]>** a Point feature at the mean center point of
|
|
|
50
50
|
|
|
51
51
|
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
52
52
|
|
|
53
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
54
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
55
|
-
./scripts/generate-readmes in the turf project. -->
|
|
53
|
+
<!-- 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. -->
|
|
56
54
|
|
|
57
55
|
---
|
|
58
56
|
|
|
59
|
-
This module is part of the [Turfjs project](
|
|
60
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
61
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
62
|
-
PRs and issues.
|
|
57
|
+
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.
|
|
63
58
|
|
|
64
59
|
### Installation
|
|
65
60
|
|
|
66
|
-
Install this module individually:
|
|
61
|
+
Install this single module individually:
|
|
67
62
|
|
|
68
63
|
```sh
|
|
69
64
|
$ npm install @turf/center-mean
|
|
70
65
|
```
|
|
71
66
|
|
|
72
|
-
Or install the
|
|
67
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
73
68
|
|
|
74
69
|
```sh
|
|
75
70
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _meta = require('@turf/meta');
|
|
6
|
+
var _helpers = require('@turf/helpers');
|
|
7
|
+
function centerMean(geojson, options = {}) {
|
|
8
|
+
let sumXs = 0;
|
|
9
|
+
let sumYs = 0;
|
|
10
|
+
let sumNs = 0;
|
|
11
|
+
_meta.geomEach.call(void 0, geojson, function(geom, featureIndex, properties) {
|
|
12
|
+
let weight = options.weight ? properties == null ? void 0 : properties[options.weight] : void 0;
|
|
13
|
+
weight = weight === void 0 || weight === null ? 1 : weight;
|
|
14
|
+
if (!_helpers.isNumber.call(void 0, weight))
|
|
15
|
+
throw new Error(
|
|
16
|
+
"weight value must be a number for feature index " + featureIndex
|
|
17
|
+
);
|
|
18
|
+
weight = Number(weight);
|
|
19
|
+
if (weight > 0) {
|
|
20
|
+
_meta.coordEach.call(void 0, geom, function(coord) {
|
|
21
|
+
sumXs += coord[0] * weight;
|
|
22
|
+
sumYs += coord[1] * weight;
|
|
23
|
+
sumNs += weight;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return _helpers.point.call(void 0, [sumXs / sumNs, sumYs / sumNs], options.properties, options);
|
|
28
|
+
}
|
|
29
|
+
__name(centerMean, "centerMean");
|
|
30
|
+
var turf_center_mean_default = centerMean;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
exports.centerMean = centerMean; exports.default = turf_center_mean_default;
|
|
35
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAS,UAAU,iBAAiB;AACpC,SAAS,UAAU,aAAiB;AA4BpC,SAAS,WACP,SACA,UAAqE,CAAC,GACnD;AACnB,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,WAAS,SAAS,SAAU,MAAM,cAAc,YAAY;AAC1D,QAAI,SAAS,QAAQ,SAAS,yCAAa,QAAQ,UAAU;AAC7D,aAAS,WAAW,UAAa,WAAW,OAAO,IAAI;AACvD,QAAI,CAAC,SAAS,MAAM;AAClB,YAAM,IAAI;AAAA,QACR,qDAAqD;AAAA,MACvD;AACF,aAAS,OAAO,MAAM;AACtB,QAAI,SAAS,GAAG;AACd,gBAAU,MAAM,SAAU,OAAO;AAC/B,iBAAS,MAAM,CAAC,IAAI;AACpB,iBAAS,MAAM,CAAC,IAAI;AACpB,iBAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACD,SAAO,MAAM,CAAC,QAAQ,OAAO,QAAQ,KAAK,GAAG,QAAQ,YAAY,OAAO;AAC1E;AAxBS;AA2BT,IAAO,2BAAQ","sourcesContent":["import { BBox, Feature, Point, GeoJsonProperties } from \"geojson\";\nimport { geomEach, coordEach } from \"@turf/meta\";\nimport { isNumber, point, Id } from \"@turf/helpers\";\n\n/**\n * Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.\n *\n * @name centerMean\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Point\n * @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point\n * @param {Object} [options.id={}] Translate GeoJSON Id to Point\n * @param {string} [options.weight] the property name used to weight the center\n * @returns {Feature<Point>} a Point feature at the mean center point of all input features\n * @example\n * var features = turf.featureCollection([\n * turf.point([-97.522259, 35.4691], {value: 10}),\n * turf.point([-97.502754, 35.463455], {value: 3}),\n * turf.point([-97.508269, 35.463245], {value: 5})\n * ]);\n *\n * var options = {weight: \"value\"}\n * var mean = turf.centerMean(features, options);\n *\n * //addToMap\n * var addToMap = [features, mean]\n * mean.properties['marker-size'] = 'large';\n * mean.properties['marker-color'] = '#000';\n */\nfunction centerMean<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: any, // To-Do include Typescript AllGeoJSON\n options: { properties?: P; bbox?: BBox; id?: Id; weight?: string } = {}\n): Feature<Point, P> {\n let sumXs = 0;\n let sumYs = 0;\n let sumNs = 0;\n geomEach(geojson, function (geom, featureIndex, properties) {\n let weight = options.weight ? properties?.[options.weight] : undefined;\n weight = weight === undefined || weight === null ? 1 : weight;\n if (!isNumber(weight))\n throw new Error(\n \"weight value must be a number for feature index \" + featureIndex\n );\n weight = Number(weight);\n if (weight > 0) {\n coordEach(geom, function (coord) {\n sumXs += coord[0] * weight;\n sumYs += coord[1] * weight;\n sumNs += weight;\n });\n }\n });\n return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);\n}\n\nexport { centerMean };\nexport default centerMean;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BBox, Feature, Point
|
|
2
|
-
import { Id } from
|
|
1
|
+
import { GeoJsonProperties, BBox, Feature, Point } from 'geojson';
|
|
2
|
+
import { Id } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
|
|
5
6
|
*
|
|
@@ -26,11 +27,12 @@ import { Id } from "@turf/helpers";
|
|
|
26
27
|
* mean.properties['marker-size'] = 'large';
|
|
27
28
|
* mean.properties['marker-color'] = '#000';
|
|
28
29
|
*/
|
|
29
|
-
declare function centerMean<P = GeoJsonProperties>(geojson: any, // To-Do include Typescript AllGeoJSON
|
|
30
|
+
declare function centerMean<P extends GeoJsonProperties = GeoJsonProperties>(geojson: any, // To-Do include Typescript AllGeoJSON
|
|
30
31
|
options?: {
|
|
31
32
|
properties?: P;
|
|
32
33
|
bbox?: BBox;
|
|
33
34
|
id?: Id;
|
|
34
35
|
weight?: string;
|
|
35
36
|
}): Feature<Point, P>;
|
|
36
|
-
|
|
37
|
+
|
|
38
|
+
export { centerMean, centerMean as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { GeoJsonProperties, BBox, Feature, Point } from 'geojson';
|
|
2
|
+
import { Id } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
|
|
5
6
|
*
|
|
@@ -26,25 +27,12 @@ import { isNumber, point } from "@turf/helpers";
|
|
|
26
27
|
* mean.properties['marker-size'] = 'large';
|
|
27
28
|
* mean.properties['marker-color'] = '#000';
|
|
28
29
|
*/
|
|
29
|
-
function centerMean(geojson, // To-Do include Typescript AllGeoJSON
|
|
30
|
-
options
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
throw new Error("weight value must be a number for feature index " + featureIndex);
|
|
39
|
-
weight = Number(weight);
|
|
40
|
-
if (weight > 0) {
|
|
41
|
-
coordEach(geom, function (coord) {
|
|
42
|
-
sumXs += coord[0] * weight;
|
|
43
|
-
sumYs += coord[1] * weight;
|
|
44
|
-
sumNs += weight;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
|
|
49
|
-
}
|
|
50
|
-
export default centerMean;
|
|
30
|
+
declare function centerMean<P extends GeoJsonProperties = GeoJsonProperties>(geojson: any, // To-Do include Typescript AllGeoJSON
|
|
31
|
+
options?: {
|
|
32
|
+
properties?: P;
|
|
33
|
+
bbox?: BBox;
|
|
34
|
+
id?: Id;
|
|
35
|
+
weight?: string;
|
|
36
|
+
}): Feature<Point, P>;
|
|
37
|
+
|
|
38
|
+
export { centerMean, centerMean as default };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { geomEach, coordEach } from "@turf/meta";
|
|
6
|
+
import { isNumber, point } from "@turf/helpers";
|
|
7
|
+
function centerMean(geojson, options = {}) {
|
|
8
|
+
let sumXs = 0;
|
|
9
|
+
let sumYs = 0;
|
|
10
|
+
let sumNs = 0;
|
|
11
|
+
geomEach(geojson, function(geom, featureIndex, properties) {
|
|
12
|
+
let weight = options.weight ? properties == null ? void 0 : properties[options.weight] : void 0;
|
|
13
|
+
weight = weight === void 0 || weight === null ? 1 : weight;
|
|
14
|
+
if (!isNumber(weight))
|
|
15
|
+
throw new Error(
|
|
16
|
+
"weight value must be a number for feature index " + featureIndex
|
|
17
|
+
);
|
|
18
|
+
weight = Number(weight);
|
|
19
|
+
if (weight > 0) {
|
|
20
|
+
coordEach(geom, function(coord) {
|
|
21
|
+
sumXs += coord[0] * weight;
|
|
22
|
+
sumYs += coord[1] * weight;
|
|
23
|
+
sumNs += weight;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
|
|
28
|
+
}
|
|
29
|
+
__name(centerMean, "centerMean");
|
|
30
|
+
var turf_center_mean_default = centerMean;
|
|
31
|
+
export {
|
|
32
|
+
centerMean,
|
|
33
|
+
turf_center_mean_default as default
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { BBox, Feature, Point, GeoJsonProperties } from \"geojson\";\nimport { geomEach, coordEach } from \"@turf/meta\";\nimport { isNumber, point, Id } from \"@turf/helpers\";\n\n/**\n * Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.\n *\n * @name centerMean\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Point\n * @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point\n * @param {Object} [options.id={}] Translate GeoJSON Id to Point\n * @param {string} [options.weight] the property name used to weight the center\n * @returns {Feature<Point>} a Point feature at the mean center point of all input features\n * @example\n * var features = turf.featureCollection([\n * turf.point([-97.522259, 35.4691], {value: 10}),\n * turf.point([-97.502754, 35.463455], {value: 3}),\n * turf.point([-97.508269, 35.463245], {value: 5})\n * ]);\n *\n * var options = {weight: \"value\"}\n * var mean = turf.centerMean(features, options);\n *\n * //addToMap\n * var addToMap = [features, mean]\n * mean.properties['marker-size'] = 'large';\n * mean.properties['marker-color'] = '#000';\n */\nfunction centerMean<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: any, // To-Do include Typescript AllGeoJSON\n options: { properties?: P; bbox?: BBox; id?: Id; weight?: string } = {}\n): Feature<Point, P> {\n let sumXs = 0;\n let sumYs = 0;\n let sumNs = 0;\n geomEach(geojson, function (geom, featureIndex, properties) {\n let weight = options.weight ? properties?.[options.weight] : undefined;\n weight = weight === undefined || weight === null ? 1 : weight;\n if (!isNumber(weight))\n throw new Error(\n \"weight value must be a number for feature index \" + featureIndex\n );\n weight = Number(weight);\n if (weight > 0) {\n coordEach(geom, function (coord) {\n sumXs += coord[0] * weight;\n sumYs += coord[1] * weight;\n sumNs += weight;\n });\n }\n });\n return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);\n}\n\nexport { centerMean };\nexport default centerMean;\n"],"mappings":";;;;AACA,SAAS,UAAU,iBAAiB;AACpC,SAAS,UAAU,aAAiB;AA4BpC,SAAS,WACP,SACA,UAAqE,CAAC,GACnD;AACnB,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,WAAS,SAAS,SAAU,MAAM,cAAc,YAAY;AAC1D,QAAI,SAAS,QAAQ,SAAS,yCAAa,QAAQ,UAAU;AAC7D,aAAS,WAAW,UAAa,WAAW,OAAO,IAAI;AACvD,QAAI,CAAC,SAAS,MAAM;AAClB,YAAM,IAAI;AAAA,QACR,qDAAqD;AAAA,MACvD;AACF,aAAS,OAAO,MAAM;AACtB,QAAI,SAAS,GAAG;AACd,gBAAU,MAAM,SAAU,OAAO;AAC/B,iBAAS,MAAM,CAAC,IAAI;AACpB,iBAAS,MAAM,CAAC,IAAI;AACpB,iBAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACD,SAAO,MAAM,CAAC,QAAQ,OAAO,QAAQ,KAAK,GAAG,QAAQ,YAAY,OAAO;AAC1E;AAxBS;AA2BT,IAAO,2BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/center-mean",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf center-mean module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -28,49 +28,55 @@
|
|
|
28
28
|
"geo",
|
|
29
29
|
"turf"
|
|
30
30
|
],
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"type": "commonjs",
|
|
32
|
+
"main": "dist/cjs/index.cjs",
|
|
33
|
+
"module": "dist/esm/index.mjs",
|
|
34
|
+
"types": "dist/cjs/index.d.ts",
|
|
33
35
|
"exports": {
|
|
34
36
|
"./package.json": "./package.json",
|
|
35
37
|
".": {
|
|
36
|
-
"import":
|
|
37
|
-
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/esm/index.d.mts",
|
|
40
|
+
"default": "./dist/esm/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/cjs/index.d.ts",
|
|
44
|
+
"default": "./dist/cjs/index.cjs"
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
47
|
},
|
|
40
|
-
"types": "dist/js/index.d.ts",
|
|
41
48
|
"sideEffects": false,
|
|
42
49
|
"files": [
|
|
43
50
|
"dist"
|
|
44
51
|
],
|
|
45
52
|
"scripts": {
|
|
46
|
-
"bench": "
|
|
47
|
-
"build": "
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"test": "npm-run-all test:*",
|
|
52
|
-
"test:tape": "ts-node -r esm test.js",
|
|
53
|
+
"bench": "tsx bench.ts",
|
|
54
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
55
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
56
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
57
|
+
"test:tape": "tsx test.ts",
|
|
53
58
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
54
59
|
},
|
|
55
60
|
"devDependencies": {
|
|
56
|
-
"@turf/center": "^7.0.0-alpha.
|
|
57
|
-
"@turf/truncate": "^7.0.0-alpha.
|
|
58
|
-
"@types/
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
61
|
+
"@turf/center": "^7.0.0-alpha.110+1411d63a7",
|
|
62
|
+
"@turf/truncate": "^7.0.0-alpha.110+1411d63a7",
|
|
63
|
+
"@types/benchmark": "^2.1.5",
|
|
64
|
+
"@types/tape": "^4.2.32",
|
|
65
|
+
"benchmark": "^2.1.4",
|
|
66
|
+
"glob": "^10.3.10",
|
|
67
|
+
"load-json-file": "^7.0.1",
|
|
68
|
+
"npm-run-all": "^4.1.5",
|
|
69
|
+
"tape": "^5.7.2",
|
|
70
|
+
"tsup": "^8.0.1",
|
|
71
|
+
"tsx": "^4.6.2",
|
|
72
|
+
"typescript": "^5.2.2",
|
|
73
|
+
"write-json-file": "^5.0.0"
|
|
68
74
|
},
|
|
69
75
|
"dependencies": {
|
|
70
|
-
"@turf/bbox": "^7.0.0-alpha.
|
|
71
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
72
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
73
|
-
"tslib": "^2.
|
|
76
|
+
"@turf/bbox": "^7.0.0-alpha.110+1411d63a7",
|
|
77
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
78
|
+
"@turf/meta": "^7.0.0-alpha.110+1411d63a7",
|
|
79
|
+
"tslib": "^2.6.2"
|
|
74
80
|
},
|
|
75
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
76
82
|
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const meta_1 = require("@turf/meta");
|
|
4
|
-
const helpers_1 = require("@turf/helpers");
|
|
5
|
-
/**
|
|
6
|
-
* Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
|
|
7
|
-
*
|
|
8
|
-
* @name centerMean
|
|
9
|
-
* @param {GeoJSON} geojson GeoJSON to be centered
|
|
10
|
-
* @param {Object} [options={}] Optional parameters
|
|
11
|
-
* @param {Object} [options.properties={}] Translate GeoJSON Properties to Point
|
|
12
|
-
* @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point
|
|
13
|
-
* @param {Object} [options.id={}] Translate GeoJSON Id to Point
|
|
14
|
-
* @param {string} [options.weight] the property name used to weight the center
|
|
15
|
-
* @returns {Feature<Point>} a Point feature at the mean center point of all input features
|
|
16
|
-
* @example
|
|
17
|
-
* var features = turf.featureCollection([
|
|
18
|
-
* turf.point([-97.522259, 35.4691], {value: 10}),
|
|
19
|
-
* turf.point([-97.502754, 35.463455], {value: 3}),
|
|
20
|
-
* turf.point([-97.508269, 35.463245], {value: 5})
|
|
21
|
-
* ]);
|
|
22
|
-
*
|
|
23
|
-
* var options = {weight: "value"}
|
|
24
|
-
* var mean = turf.centerMean(features, options);
|
|
25
|
-
*
|
|
26
|
-
* //addToMap
|
|
27
|
-
* var addToMap = [features, mean]
|
|
28
|
-
* mean.properties['marker-size'] = 'large';
|
|
29
|
-
* mean.properties['marker-color'] = '#000';
|
|
30
|
-
*/
|
|
31
|
-
function centerMean(geojson, // To-Do include Typescript AllGeoJSON
|
|
32
|
-
options = {}) {
|
|
33
|
-
let sumXs = 0;
|
|
34
|
-
let sumYs = 0;
|
|
35
|
-
let sumNs = 0;
|
|
36
|
-
meta_1.geomEach(geojson, function (geom, featureIndex, properties) {
|
|
37
|
-
let weight = options.weight ? properties === null || properties === void 0 ? void 0 : properties[options.weight] : undefined;
|
|
38
|
-
weight = weight === undefined || weight === null ? 1 : weight;
|
|
39
|
-
if (!helpers_1.isNumber(weight))
|
|
40
|
-
throw new Error("weight value must be a number for feature index " + featureIndex);
|
|
41
|
-
weight = Number(weight);
|
|
42
|
-
if (weight > 0) {
|
|
43
|
-
meta_1.coordEach(geom, function (coord) {
|
|
44
|
-
sumXs += coord[0] * weight;
|
|
45
|
-
sumYs += coord[1] * weight;
|
|
46
|
-
sumNs += weight;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return helpers_1.point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
|
|
51
|
-
}
|
|
52
|
-
exports.default = centerMean;
|