@turf/nearest-point 7.0.0-alpha.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 +9 -2
- package/dist/es/index.js +4 -2
- package/dist/js/index.d.ts +6 -2
- package/dist/js/index.js +4 -2
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -13,6 +13,9 @@ is geodesic.
|
|
|
13
13
|
|
|
14
14
|
* `targetPoint` **[Coord][2]** the reference point
|
|
15
15
|
* `points` **[FeatureCollection][3]<[Point][4]>** against input point set
|
|
16
|
+
* `options` **[Object][5]** Optional parameters (optional, default `{}`)
|
|
17
|
+
|
|
18
|
+
* `options.units` **[string][6]** the units of the numeric result (optional, default `'kilometers'`)
|
|
16
19
|
|
|
17
20
|
### Examples
|
|
18
21
|
|
|
@@ -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 referen
|
|
|
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,7 +27,7 @@ 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");
|
|
@@ -34,7 +36,7 @@ function nearestPoint(targetPoint, points) {
|
|
|
34
36
|
let minDist = Infinity;
|
|
35
37
|
let bestFeatureIndex = 0;
|
|
36
38
|
featureEach(points, (pt, featureIndex) => {
|
|
37
|
-
const distanceToPoint = distance(targetPoint, pt);
|
|
39
|
+
const distanceToPoint = distance(targetPoint, pt, options);
|
|
38
40
|
if (distanceToPoint < minDist) {
|
|
39
41
|
bestFeatureIndex = featureIndex;
|
|
40
42
|
minDist = distanceToPoint;
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Feature, FeatureCollection, Point } from "geojson";
|
|
2
|
-
import { Coord } from "@turf/helpers";
|
|
2
|
+
import { Coord, Units } from "@turf/helpers";
|
|
3
3
|
export interface NearestPoint extends Feature<Point> {
|
|
4
4
|
properties: {
|
|
5
5
|
featureIndex: number;
|
|
@@ -16,6 +16,8 @@ export interface NearestPoint extends Feature<Point> {
|
|
|
16
16
|
* @name nearestPoint
|
|
17
17
|
* @param {Coord} targetPoint the reference point
|
|
18
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
|
|
19
21
|
* @returns {Feature<Point>} the closest point in the set to the reference point
|
|
20
22
|
* @example
|
|
21
23
|
* var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
|
|
@@ -31,5 +33,7 @@ export interface NearestPoint extends Feature<Point> {
|
|
|
31
33
|
* var addToMap = [targetPoint, points, nearest];
|
|
32
34
|
* nearest.properties['marker-color'] = '#F00';
|
|
33
35
|
*/
|
|
34
|
-
declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point
|
|
36
|
+
declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point>, options?: {
|
|
37
|
+
units?: Units;
|
|
38
|
+
}): NearestPoint;
|
|
35
39
|
export default nearestPoint;
|
package/dist/js/index.js
CHANGED
|
@@ -13,6 +13,8 @@ const meta_1 = require("@turf/meta");
|
|
|
13
13
|
* @name nearestPoint
|
|
14
14
|
* @param {Coord} targetPoint the reference point
|
|
15
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
|
|
16
18
|
* @returns {Feature<Point>} the closest point in the set to the reference point
|
|
17
19
|
* @example
|
|
18
20
|
* var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
|
|
@@ -28,7 +30,7 @@ const meta_1 = require("@turf/meta");
|
|
|
28
30
|
* var addToMap = [targetPoint, points, nearest];
|
|
29
31
|
* nearest.properties['marker-color'] = '#F00';
|
|
30
32
|
*/
|
|
31
|
-
function nearestPoint(targetPoint, points) {
|
|
33
|
+
function nearestPoint(targetPoint, points, options = {}) {
|
|
32
34
|
// Input validation
|
|
33
35
|
if (!targetPoint)
|
|
34
36
|
throw new Error("targetPoint is required");
|
|
@@ -37,7 +39,7 @@ function nearestPoint(targetPoint, points) {
|
|
|
37
39
|
let minDist = Infinity;
|
|
38
40
|
let bestFeatureIndex = 0;
|
|
39
41
|
meta_1.featureEach(points, (pt, featureIndex) => {
|
|
40
|
-
const distanceToPoint = distance_1.default(targetPoint, pt);
|
|
42
|
+
const distanceToPoint = distance_1.default(targetPoint, pt, options);
|
|
41
43
|
if (distanceToPoint < minDist) {
|
|
42
44
|
bestFeatureIndex = featureIndex;
|
|
43
45
|
minDist = distanceToPoint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/nearest-point",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
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,13 +40,13 @@
|
|
|
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:tape": "tsx test.js",
|
|
49
50
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
@@ -53,16 +54,16 @@
|
|
|
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": "^7.0.0-alpha.
|
|
62
|
-
"@turf/distance": "^7.0.0-alpha.
|
|
63
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
64
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
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",
|
|
65
66
|
"tslib": "^2.3.0"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
68
69
|
}
|