@turf/nearest-point 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 +13 -6
- package/dist/es/index.js +9 -10
- package/dist/js/index.d.ts +7 -2
- package/dist/js/index.js +13 -16
- package/package.json +13 -11
package/README.md
CHANGED
|
@@ -9,12 +9,15 @@ with Point geometries and returns the
|
|
|
9
9
|
point from the FeatureCollection closest to the reference. This calculation
|
|
10
10
|
is geodesic.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
### Parameters
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
* `targetPoint` **[Coord][2]** the reference point
|
|
15
|
+
* `points` **[FeatureCollection][3]<[Point][4]>** against input point set
|
|
16
|
+
* `options` **[Object][5]** Optional parameters (optional, default `{}`)
|
|
16
17
|
|
|
17
|
-
**
|
|
18
|
+
* `options.units` **[string][6]** the units of the numeric result (optional, default `'kilometers'`)
|
|
19
|
+
|
|
20
|
+
### Examples
|
|
18
21
|
|
|
19
22
|
```javascript
|
|
20
23
|
var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
|
|
@@ -31,7 +34,7 @@ var addToMap = [targetPoint, points, nearest];
|
|
|
31
34
|
nearest.properties['marker-color'] = '#F00';
|
|
32
35
|
```
|
|
33
36
|
|
|
34
|
-
Returns **[Feature][
|
|
37
|
+
Returns **[Feature][7]<[Point][4]>** the closest point in the set to the reference point
|
|
35
38
|
|
|
36
39
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
37
40
|
|
|
@@ -41,7 +44,11 @@ Returns **[Feature][5]<[Point][4]>** the closest point in the set to the refe
|
|
|
41
44
|
|
|
42
45
|
[4]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
43
46
|
|
|
44
|
-
[5]: https://
|
|
47
|
+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
48
|
+
|
|
49
|
+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
50
|
+
|
|
51
|
+
[7]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
45
52
|
|
|
46
53
|
<!-- This file is automatically generated. Please don't edit it directly:
|
|
47
54
|
if you find an error, edit the source file (likely index.js), and re-run
|
package/dist/es/index.js
CHANGED
|
@@ -10,6 +10,8 @@ import { featureEach } from "@turf/meta";
|
|
|
10
10
|
* @name nearestPoint
|
|
11
11
|
* @param {Coord} targetPoint the reference point
|
|
12
12
|
* @param {FeatureCollection<Point>} points against input point set
|
|
13
|
+
* @param {Object} [options={}] Optional parameters
|
|
14
|
+
* @param {string} [options.units='kilometers'] the units of the numeric result
|
|
13
15
|
* @returns {Feature<Point>} the closest point in the set to the reference point
|
|
14
16
|
* @example
|
|
15
17
|
* var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
|
|
@@ -25,25 +27,22 @@ import { featureEach } from "@turf/meta";
|
|
|
25
27
|
* var addToMap = [targetPoint, points, nearest];
|
|
26
28
|
* nearest.properties['marker-color'] = '#F00';
|
|
27
29
|
*/
|
|
28
|
-
function nearestPoint(targetPoint, points) {
|
|
30
|
+
function nearestPoint(targetPoint, points, options = {}) {
|
|
29
31
|
// Input validation
|
|
30
32
|
if (!targetPoint)
|
|
31
33
|
throw new Error("targetPoint is required");
|
|
32
34
|
if (!points)
|
|
33
35
|
throw new Error("points is required");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var distanceToPoint = distance(targetPoint, pt);
|
|
36
|
+
let minDist = Infinity;
|
|
37
|
+
let bestFeatureIndex = 0;
|
|
38
|
+
featureEach(points, (pt, featureIndex) => {
|
|
39
|
+
const distanceToPoint = distance(targetPoint, pt, options);
|
|
39
40
|
if (distanceToPoint < minDist) {
|
|
40
41
|
bestFeatureIndex = featureIndex;
|
|
41
42
|
minDist = distanceToPoint;
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
nearest.properties.distanceToPoint = minDist;
|
|
47
|
-
return nearest;
|
|
45
|
+
const nearestPoint = clone(points.features[bestFeatureIndex]);
|
|
46
|
+
return Object.assign(Object.assign({}, nearestPoint), { properties: Object.assign(Object.assign({}, nearestPoint.properties), { featureIndex: bestFeatureIndex, distanceToPoint: minDist }) });
|
|
48
47
|
}
|
|
49
48
|
export default nearestPoint;
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Feature, FeatureCollection, Point } from "geojson";
|
|
2
|
+
import { Coord, Units } from "@turf/helpers";
|
|
2
3
|
export interface NearestPoint extends Feature<Point> {
|
|
3
4
|
properties: {
|
|
4
5
|
featureIndex: number;
|
|
@@ -15,6 +16,8 @@ export interface NearestPoint extends Feature<Point> {
|
|
|
15
16
|
* @name nearestPoint
|
|
16
17
|
* @param {Coord} targetPoint the reference point
|
|
17
18
|
* @param {FeatureCollection<Point>} points against input point set
|
|
19
|
+
* @param {Object} [options={}] Optional parameters
|
|
20
|
+
* @param {string} [options.units='kilometers'] the units of the numeric result
|
|
18
21
|
* @returns {Feature<Point>} the closest point in the set to the reference point
|
|
19
22
|
* @example
|
|
20
23
|
* var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
|
|
@@ -30,5 +33,7 @@ export interface NearestPoint extends Feature<Point> {
|
|
|
30
33
|
* var addToMap = [targetPoint, points, nearest];
|
|
31
34
|
* nearest.properties['marker-color'] = '#F00';
|
|
32
35
|
*/
|
|
33
|
-
declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point
|
|
36
|
+
declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point>, options?: {
|
|
37
|
+
units?: Units;
|
|
38
|
+
}): NearestPoint;
|
|
34
39
|
export default nearestPoint;
|
package/dist/js/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const clone_1 = tslib_1.__importDefault(require("@turf/clone"));
|
|
5
|
+
const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
|
|
6
|
+
const meta_1 = require("@turf/meta");
|
|
9
7
|
/**
|
|
10
8
|
* Takes a reference {@link Point|point} and a FeatureCollection of Features
|
|
11
9
|
* with Point geometries and returns the
|
|
@@ -15,6 +13,8 @@ var meta_1 = require("@turf/meta");
|
|
|
15
13
|
* @name nearestPoint
|
|
16
14
|
* @param {Coord} targetPoint the reference point
|
|
17
15
|
* @param {FeatureCollection<Point>} points against input point set
|
|
16
|
+
* @param {Object} [options={}] Optional parameters
|
|
17
|
+
* @param {string} [options.units='kilometers'] the units of the numeric result
|
|
18
18
|
* @returns {Feature<Point>} the closest point in the set to the reference point
|
|
19
19
|
* @example
|
|
20
20
|
* var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
|
|
@@ -30,25 +30,22 @@ var meta_1 = require("@turf/meta");
|
|
|
30
30
|
* var addToMap = [targetPoint, points, nearest];
|
|
31
31
|
* nearest.properties['marker-color'] = '#F00';
|
|
32
32
|
*/
|
|
33
|
-
function nearestPoint(targetPoint, points) {
|
|
33
|
+
function nearestPoint(targetPoint, points, options = {}) {
|
|
34
34
|
// Input validation
|
|
35
35
|
if (!targetPoint)
|
|
36
36
|
throw new Error("targetPoint is required");
|
|
37
37
|
if (!points)
|
|
38
38
|
throw new Error("points is required");
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var distanceToPoint = distance_1.default(targetPoint, pt);
|
|
39
|
+
let minDist = Infinity;
|
|
40
|
+
let bestFeatureIndex = 0;
|
|
41
|
+
meta_1.featureEach(points, (pt, featureIndex) => {
|
|
42
|
+
const distanceToPoint = distance_1.default(targetPoint, pt, options);
|
|
44
43
|
if (distanceToPoint < minDist) {
|
|
45
44
|
bestFeatureIndex = featureIndex;
|
|
46
45
|
minDist = distanceToPoint;
|
|
47
46
|
}
|
|
48
47
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
nearest.properties.distanceToPoint = minDist;
|
|
52
|
-
return nearest;
|
|
48
|
+
const nearestPoint = clone_1.default(points.features[bestFeatureIndex]);
|
|
49
|
+
return Object.assign(Object.assign({}, nearestPoint), { properties: Object.assign(Object.assign({}, nearestPoint.properties), { featureIndex: bestFeatureIndex, distanceToPoint: minDist }) });
|
|
53
50
|
}
|
|
54
51
|
exports.default = nearestPoint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/nearest-point",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "turf nearest-point module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
"./package.json": "./package.json",
|
|
31
31
|
".": {
|
|
32
|
+
"types": "./dist/js/index.d.ts",
|
|
32
33
|
"import": "./dist/es/index.js",
|
|
33
34
|
"require": "./dist/js/index.js"
|
|
34
35
|
}
|
|
@@ -39,29 +40,30 @@
|
|
|
39
40
|
"dist"
|
|
40
41
|
],
|
|
41
42
|
"scripts": {
|
|
42
|
-
"bench": "
|
|
43
|
+
"bench": "tsx bench.js",
|
|
43
44
|
"build": "npm-run-all build:*",
|
|
44
45
|
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
|
|
45
46
|
"build:js": "tsc",
|
|
46
|
-
"docs": "
|
|
47
|
+
"docs": "tsx ../../scripts/generate-readmes",
|
|
47
48
|
"test": "npm-run-all test:*",
|
|
48
|
-
"test:tape": "
|
|
49
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
49
|
+
"test:tape": "tsx test.js",
|
|
50
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@types/tape": "*",
|
|
53
54
|
"benchmark": "*",
|
|
54
55
|
"npm-run-all": "*",
|
|
55
56
|
"tape": "*",
|
|
56
|
-
"ts-node": "*",
|
|
57
57
|
"tslint": "*",
|
|
58
|
+
"tsx": "*",
|
|
58
59
|
"typescript": "*"
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
61
|
-
"@turf/clone": "^
|
|
62
|
-
"@turf/distance": "^
|
|
63
|
-
"@turf/helpers": "^
|
|
64
|
-
"@turf/meta": "^
|
|
62
|
+
"@turf/clone": "^7.0.0-alpha.1",
|
|
63
|
+
"@turf/distance": "^7.0.0-alpha.1",
|
|
64
|
+
"@turf/helpers": "^7.0.0-alpha.1",
|
|
65
|
+
"@turf/meta": "^7.0.0-alpha.1",
|
|
66
|
+
"tslib": "^2.3.0"
|
|
65
67
|
},
|
|
66
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
67
69
|
}
|