@turf/nearest-point 6.5.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 +5 -5
- package/dist/es/index.js +6 -9
- package/dist/js/index.d.ts +2 -1
- package/dist/js/index.js +10 -15
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -9,12 +9,12 @@ 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
16
|
|
|
17
|
-
|
|
17
|
+
### Examples
|
|
18
18
|
|
|
19
19
|
```javascript
|
|
20
20
|
var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
|
|
@@ -31,7 +31,7 @@ var addToMap = [targetPoint, points, nearest];
|
|
|
31
31
|
nearest.properties['marker-color'] = '#F00';
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
Returns **[Feature][5]
|
|
34
|
+
Returns **[Feature][5]<[Point][4]>** the closest point in the set to the reference point
|
|
35
35
|
|
|
36
36
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
37
37
|
|
package/dist/es/index.js
CHANGED
|
@@ -31,19 +31,16 @@ function nearestPoint(targetPoint, points) {
|
|
|
31
31
|
throw new Error("targetPoint is required");
|
|
32
32
|
if (!points)
|
|
33
33
|
throw new Error("points is required");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var distanceToPoint = distance(targetPoint, pt);
|
|
34
|
+
let minDist = Infinity;
|
|
35
|
+
let bestFeatureIndex = 0;
|
|
36
|
+
featureEach(points, (pt, featureIndex) => {
|
|
37
|
+
const distanceToPoint = distance(targetPoint, pt);
|
|
39
38
|
if (distanceToPoint < minDist) {
|
|
40
39
|
bestFeatureIndex = featureIndex;
|
|
41
40
|
minDist = distanceToPoint;
|
|
42
41
|
}
|
|
43
42
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
nearest.properties.distanceToPoint = minDist;
|
|
47
|
-
return nearest;
|
|
43
|
+
const nearestPoint = clone(points.features[bestFeatureIndex]);
|
|
44
|
+
return Object.assign(Object.assign({}, nearestPoint), { properties: Object.assign(Object.assign({}, nearestPoint.properties), { featureIndex: bestFeatureIndex, distanceToPoint: minDist }) });
|
|
48
45
|
}
|
|
49
46
|
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 } from "@turf/helpers";
|
|
2
3
|
export interface NearestPoint extends Feature<Point> {
|
|
3
4
|
properties: {
|
|
4
5
|
featureIndex: number;
|
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
|
|
@@ -36,19 +34,16 @@ function nearestPoint(targetPoint, points) {
|
|
|
36
34
|
throw new Error("targetPoint is required");
|
|
37
35
|
if (!points)
|
|
38
36
|
throw new Error("points is required");
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var distanceToPoint = distance_1.default(targetPoint, pt);
|
|
37
|
+
let minDist = Infinity;
|
|
38
|
+
let bestFeatureIndex = 0;
|
|
39
|
+
meta_1.featureEach(points, (pt, featureIndex) => {
|
|
40
|
+
const distanceToPoint = distance_1.default(targetPoint, pt);
|
|
44
41
|
if (distanceToPoint < minDist) {
|
|
45
42
|
bestFeatureIndex = featureIndex;
|
|
46
43
|
minDist = distanceToPoint;
|
|
47
44
|
}
|
|
48
45
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
nearest.properties.distanceToPoint = minDist;
|
|
52
|
-
return nearest;
|
|
46
|
+
const nearestPoint = clone_1.default(points.features[bestFeatureIndex]);
|
|
47
|
+
return Object.assign(Object.assign({}, nearestPoint), { properties: Object.assign(Object.assign({}, nearestPoint.properties), { featureIndex: bestFeatureIndex, distanceToPoint: minDist }) });
|
|
53
48
|
}
|
|
54
49
|
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.0",
|
|
4
4
|
"description": "turf nearest-point module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"docs": "node ../../scripts/generate-readmes",
|
|
47
47
|
"test": "npm-run-all test:*",
|
|
48
48
|
"test:tape": "ts-node -r esm test.js",
|
|
49
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
49
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/tape": "*",
|
|
@@ -58,10 +58,11 @@
|
|
|
58
58
|
"typescript": "*"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@turf/clone": "^
|
|
62
|
-
"@turf/distance": "^
|
|
63
|
-
"@turf/helpers": "^
|
|
64
|
-
"@turf/meta": "^
|
|
61
|
+
"@turf/clone": "^7.0.0-alpha.0",
|
|
62
|
+
"@turf/distance": "^7.0.0-alpha.0",
|
|
63
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
64
|
+
"@turf/meta": "^7.0.0-alpha.0",
|
|
65
|
+
"tslib": "^2.3.0"
|
|
65
66
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
67
68
|
}
|