@turf/nearest-point-on-line 7.1.0-alpha.7 → 7.1.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 CHANGED
@@ -8,11 +8,11 @@ Takes a [Point][1] and a [LineString][2] and calculates the closest Point on the
8
8
 
9
9
  ### Parameters
10
10
 
11
- * `lines` **([Geometry][3] | [Feature][4]<([LineString][5] | [MultiLineString][6])>)** lines to snap to
12
- * `pt` **([Geometry][3] | [Feature][4]<[Point][7]> | [Array][8]<[number][9]>)** point to snap from
13
- * `options` **[Object][10]** Optional parameters (optional, default `{}`)
11
+ * `lines` **([Geometry][3] | [Feature][4]<([LineString][2] | [MultiLineString][5])>)** lines to snap to
12
+ * `pt` **([Geometry][3] | [Feature][4]<[Point][1]> | [Array][6]<[number][7]>)** point to snap from
13
+ * `options` **[Object][8]** Optional parameters (optional, default `{}`)
14
14
 
15
- * `options.units` **[string][11]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
15
+ * `options.units` **[string][9]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
16
16
 
17
17
  ### Examples
18
18
 
@@ -34,7 +34,7 @@ var addToMap = [line, pt, snapped];
34
34
  snapped.properties['marker-color'] = '#00f';
35
35
  ```
36
36
 
37
- Returns **[Feature][4]<[Point][7]>** closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.
37
+ Returns **[Feature][4]<[Point][1]>** closest point on the `line` to `point`. The properties object will contain four values: `index`: closest point was found on nth line part, `multiFeatureIndex`: closest point was found on the nth line of the `MultiLineString`, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.
38
38
 
39
39
  [1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
40
40
 
@@ -44,19 +44,15 @@ Returns **[Feature][4]<[Point][7]>** closest point on the `line` to `point`. The
44
44
 
45
45
  [4]: https://tools.ietf.org/html/rfc7946#section-3.2
46
46
 
47
- [5]: https://tools.ietf.org/html/rfc7946#section-3.1.4
47
+ [5]: https://tools.ietf.org/html/rfc7946#section-3.1.5
48
48
 
49
- [6]: https://tools.ietf.org/html/rfc7946#section-3.1.5
49
+ [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
50
50
 
51
- [7]: https://tools.ietf.org/html/rfc7946#section-3.1.2
51
+ [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
52
52
 
53
- [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
53
+ [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
54
54
 
55
- [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
56
-
57
- [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
58
-
59
- [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
55
+ [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
60
56
 
61
57
  <!-- 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. -->
62
58
 
@@ -33,71 +33,81 @@ function nearestPointOnLine(lines, pt, options = {}) {
33
33
  let closestPt = _helpers.point.call(void 0, [Infinity, Infinity], {
34
34
  dist: Infinity,
35
35
  index: -1,
36
+ multiFeatureIndex: -1,
36
37
  location: -1
37
38
  });
38
39
  let length = 0;
39
- _meta.flattenEach.call(void 0, lines, function(line) {
40
- const coords = _invariant.getCoords.call(void 0, line);
41
- for (let i = 0; i < coords.length - 1; i++) {
42
- const start = _helpers.point.call(void 0, coords[i]);
43
- start.properties.dist = _distance.distance.call(void 0, pt, start, options);
44
- const stop = _helpers.point.call(void 0, coords[i + 1]);
45
- stop.properties.dist = _distance.distance.call(void 0, pt, stop, options);
46
- const sectionLength = _distance.distance.call(void 0, start, stop, options);
47
- const heightDistance = Math.max(
48
- start.properties.dist,
49
- stop.properties.dist
50
- );
51
- const direction = _bearing.bearing.call(void 0, start, stop);
52
- const perpendicularPt1 = _destination.destination.call(void 0,
53
- pt,
54
- heightDistance,
55
- direction + 90,
56
- options
57
- );
58
- const perpendicularPt2 = _destination.destination.call(void 0,
59
- pt,
60
- heightDistance,
61
- direction - 90,
62
- options
63
- );
64
- const intersect = _lineintersect.lineIntersect.call(void 0,
65
- _helpers.lineString.call(void 0, [
66
- perpendicularPt1.geometry.coordinates,
67
- perpendicularPt2.geometry.coordinates
68
- ]),
69
- _helpers.lineString.call(void 0, [start.geometry.coordinates, stop.geometry.coordinates])
70
- );
71
- let intersectPt;
72
- if (intersect.features.length > 0 && intersect.features[0]) {
73
- intersectPt = __spreadProps(__spreadValues({}, intersect.features[0]), {
74
- properties: {
75
- dist: _distance.distance.call(void 0, pt, intersect.features[0], options),
76
- location: length + _distance.distance.call(void 0, start, intersect.features[0], options)
77
- }
78
- });
40
+ _meta.flattenEach.call(void 0,
41
+ lines,
42
+ function(line, _featureIndex, multiFeatureIndex) {
43
+ const coords = _invariant.getCoords.call(void 0, line);
44
+ for (let i = 0; i < coords.length - 1; i++) {
45
+ const start = _helpers.point.call(void 0, coords[i]);
46
+ start.properties.dist = _distance.distance.call(void 0, pt, start, options);
47
+ const stop = _helpers.point.call(void 0, coords[i + 1]);
48
+ stop.properties.dist = _distance.distance.call(void 0, pt, stop, options);
49
+ const sectionLength = _distance.distance.call(void 0, start, stop, options);
50
+ const heightDistance = Math.max(
51
+ start.properties.dist,
52
+ stop.properties.dist
53
+ );
54
+ const direction = _bearing.bearing.call(void 0, start, stop);
55
+ const perpendicularPt1 = _destination.destination.call(void 0,
56
+ pt,
57
+ heightDistance,
58
+ direction + 90,
59
+ options
60
+ );
61
+ const perpendicularPt2 = _destination.destination.call(void 0,
62
+ pt,
63
+ heightDistance,
64
+ direction - 90,
65
+ options
66
+ );
67
+ const intersect = _lineintersect.lineIntersect.call(void 0,
68
+ _helpers.lineString.call(void 0, [
69
+ perpendicularPt1.geometry.coordinates,
70
+ perpendicularPt2.geometry.coordinates
71
+ ]),
72
+ _helpers.lineString.call(void 0, [start.geometry.coordinates, stop.geometry.coordinates])
73
+ );
74
+ let intersectPt;
75
+ if (intersect.features.length > 0 && intersect.features[0]) {
76
+ intersectPt = __spreadProps(__spreadValues({}, intersect.features[0]), {
77
+ properties: {
78
+ dist: _distance.distance.call(void 0, pt, intersect.features[0], options),
79
+ multiFeatureIndex,
80
+ location: length + _distance.distance.call(void 0, start, intersect.features[0], options)
81
+ }
82
+ });
83
+ }
84
+ if (start.properties.dist < closestPt.properties.dist) {
85
+ closestPt = __spreadProps(__spreadValues({}, start), {
86
+ properties: __spreadProps(__spreadValues({}, start.properties), {
87
+ index: i,
88
+ multiFeatureIndex,
89
+ location: length
90
+ })
91
+ });
92
+ }
93
+ if (stop.properties.dist < closestPt.properties.dist) {
94
+ closestPt = __spreadProps(__spreadValues({}, stop), {
95
+ properties: __spreadProps(__spreadValues({}, stop.properties), {
96
+ index: i + 1,
97
+ multiFeatureIndex,
98
+ location: length + sectionLength
99
+ })
100
+ });
101
+ }
102
+ if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) {
103
+ closestPt = __spreadProps(__spreadValues({}, intersectPt), {
104
+ properties: __spreadProps(__spreadValues({}, intersectPt.properties), { index: i })
105
+ });
106
+ }
107
+ length += sectionLength;
79
108
  }
80
- if (start.properties.dist < closestPt.properties.dist) {
81
- closestPt = __spreadProps(__spreadValues({}, start), {
82
- properties: __spreadProps(__spreadValues({}, start.properties), { index: i, location: length })
83
- });
84
- }
85
- if (stop.properties.dist < closestPt.properties.dist) {
86
- closestPt = __spreadProps(__spreadValues({}, stop), {
87
- properties: __spreadProps(__spreadValues({}, stop.properties), {
88
- index: i + 1,
89
- location: length + sectionLength
90
- })
91
- });
92
- }
93
- if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) {
94
- closestPt = __spreadProps(__spreadValues({}, intersectPt), {
95
- properties: __spreadProps(__spreadValues({}, intersectPt.properties), { index: i })
96
- });
97
- }
98
- length += sectionLength;
99
109
  }
100
- });
110
+ );
101
111
  return closestPt;
102
112
  }
103
113
  var turf_nearest_point_on_line_default = nearestPointOnLine;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,sBAAsB;AAChD,SAAS,mBAAmB;AAC5B,SAAS,OAAO,kBAAgC;AAChD,SAAS,iBAAiB;AA4B1B,SAAS,mBACP,OACA,IACA,UAA6B,CAAC,GAS9B;AACA,MAAI,CAAC,SAAS,CAAC,IAAI;AACjB,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,MAAI,YAGA,MAAM,CAAC,UAAU,QAAQ,GAAG;AAAA,IAC9B,MAAM;AAAA,IACN,OAAO;AAAA,IACP,UAAU;AAAA,EACZ,CAAC;AAED,MAAI,SAAS;AACb,cAAY,OAAO,SAAU,MAAW;AACtC,UAAM,SAAc,UAAU,IAAI;AAElC,aAAS,IAAI,GAAG,IAAI,OAAO,SAAS,GAAG,KAAK;AAE1C,YAAM,QAA0C,MAAM,OAAO,CAAC,CAAC;AAC/D,YAAM,WAAW,OAAO,SAAS,IAAI,OAAO,OAAO;AAEnD,YAAM,OAAyC,MAAM,OAAO,IAAI,CAAC,CAAC;AAClE,WAAK,WAAW,OAAO,SAAS,IAAI,MAAM,OAAO;AAEjD,YAAM,gBAAgB,SAAS,OAAO,MAAM,OAAO;AAEnD,YAAM,iBAAiB,KAAK;AAAA,QAC1B,MAAM,WAAW;AAAA,QACjB,KAAK,WAAW;AAAA,MAClB;AACA,YAAM,YAAY,QAAQ,OAAO,IAAI;AACrC,YAAM,mBAAmB;AAAA,QACvB;AAAA,QACA;AAAA,QACA,YAAY;AAAA,QACZ;AAAA,MACF;AACA,YAAM,mBAAmB;AAAA,QACvB;AAAA,QACA;AAAA,QACA,YAAY;AAAA,QACZ;AAAA,MACF;AACA,YAAM,YAAY;AAAA,QAChB,WAAW;AAAA,UACT,iBAAiB,SAAS;AAAA,UAC1B,iBAAiB,SAAS;AAAA,QAC5B,CAAC;AAAA,QACD,WAAW,CAAC,MAAM,SAAS,aAAa,KAAK,SAAS,WAAW,CAAC;AAAA,MACpE;AACA,UAAI;AAIJ,UAAI,UAAU,SAAS,SAAS,KAAK,UAAU,SAAS,CAAC,GAAG;AAC1D,sBAAc,iCACT,UAAU,SAAS,CAAC,IADX;AAAA,UAEZ,YAAY;AAAA,YACV,MAAM,SAAS,IAAI,UAAU,SAAS,CAAC,GAAG,OAAO;AAAA,YACjD,UAAU,SAAS,SAAS,OAAO,UAAU,SAAS,CAAC,GAAG,OAAO;AAAA,UACnE;AAAA,QACF;AAAA,MACF;AAEA,UAAI,MAAM,WAAW,OAAO,UAAU,WAAW,MAAM;AACrD,oBAAY,iCACP,QADO;AAAA,UAEV,YAAY,iCAAK,MAAM,aAAX,EAAuB,OAAO,GAAG,UAAU,OAAO;AAAA,QAChE;AAAA,MACF;AAEA,UAAI,KAAK,WAAW,OAAO,UAAU,WAAW,MAAM;AACpD,oBAAY,iCACP,OADO;AAAA,UAEV,YAAY,iCACP,KAAK,aADE;AAAA,YAEV,OAAO,IAAI;AAAA,YACX,UAAU,SAAS;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAEA,UACE,eACA,YAAY,WAAW,OAAO,UAAU,WAAW,MACnD;AACA,oBAAY,iCACP,cADO;AAAA,UAEV,YAAY,iCAAK,YAAY,aAAjB,EAA6B,OAAO,EAAE;AAAA,QACpD;AAAA,MACF;AAEA,gBAAU;AAAA,IACZ;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAGA,IAAO,qCAAQ","sourcesContent":["import { Feature, Point, LineString, MultiLineString } from \"geojson\";\nimport { bearing } from \"@turf/bearing\";\nimport { distance } from \"@turf/distance\";\nimport { destination } from \"@turf/destination\";\nimport { lineIntersect as lineIntersects } from \"@turf/line-intersect\";\nimport { flattenEach } from \"@turf/meta\";\nimport { point, lineString, Coord, Units } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\n\n/**\n * Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString.\n *\n * @name nearestPointOnLine\n * @param {Geometry|Feature<LineString|MultiLineString>} lines lines to snap to\n * @param {Geometry|Feature<Point>|number[]} pt point to snap from\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var pt = turf.point([-77.037076, 38.884017]);\n *\n * var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line, pt, snapped];\n * snapped.properties['marker-color'] = '#00f';\n */\nfunction nearestPointOnLine<G extends LineString | MultiLineString>(\n lines: Feature<G> | G,\n pt: Coord,\n options: { units?: Units } = {}\n): Feature<\n Point,\n {\n dist: number;\n index: number;\n location: number;\n [key: string]: any;\n }\n> {\n if (!lines || !pt) {\n throw new Error(\"lines and pt are required arguments\");\n }\n\n let closestPt: Feature<\n Point,\n { dist: number; index: number; location: number }\n > = point([Infinity, Infinity], {\n dist: Infinity,\n index: -1,\n location: -1,\n });\n\n let length = 0.0;\n flattenEach(lines, function (line: any) {\n const coords: any = getCoords(line);\n\n for (let i = 0; i < coords.length - 1; i++) {\n //start\n const start: Feature<Point, { dist: number }> = point(coords[i]);\n start.properties.dist = distance(pt, start, options);\n //stop\n const stop: Feature<Point, { dist: number }> = point(coords[i + 1]);\n stop.properties.dist = distance(pt, stop, options);\n // sectionLength\n const sectionLength = distance(start, stop, options);\n //perpendicular\n const heightDistance = Math.max(\n start.properties.dist,\n stop.properties.dist\n );\n const direction = bearing(start, stop);\n const perpendicularPt1 = destination(\n pt,\n heightDistance,\n direction + 90,\n options\n );\n const perpendicularPt2 = destination(\n pt,\n heightDistance,\n direction - 90,\n options\n );\n const intersect = lineIntersects(\n lineString([\n perpendicularPt1.geometry.coordinates,\n perpendicularPt2.geometry.coordinates,\n ]),\n lineString([start.geometry.coordinates, stop.geometry.coordinates])\n );\n let intersectPt:\n | Feature<Point, { dist: number; location: number }>\n | undefined;\n\n if (intersect.features.length > 0 && intersect.features[0]) {\n intersectPt = {\n ...intersect.features[0],\n properties: {\n dist: distance(pt, intersect.features[0], options),\n location: length + distance(start, intersect.features[0], options),\n },\n };\n }\n\n if (start.properties.dist < closestPt.properties.dist) {\n closestPt = {\n ...start,\n properties: { ...start.properties, index: i, location: length },\n };\n }\n\n if (stop.properties.dist < closestPt.properties.dist) {\n closestPt = {\n ...stop,\n properties: {\n ...stop.properties,\n index: i + 1,\n location: length + sectionLength,\n },\n };\n }\n\n if (\n intersectPt &&\n intersectPt.properties.dist < closestPt.properties.dist\n ) {\n closestPt = {\n ...intersectPt,\n properties: { ...intersectPt.properties, index: i },\n };\n }\n // update length\n length += sectionLength;\n }\n });\n\n return closestPt;\n}\n\nexport { nearestPointOnLine };\nexport default nearestPointOnLine;\n"]}
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,sBAAsB;AAChD,SAAS,mBAAmB;AAC5B,SAAS,OAAO,kBAAgC;AAChD,SAAS,iBAAiB;AA4B1B,SAAS,mBACP,OACA,IACA,UAA6B,CAAC,GAU9B;AACA,MAAI,CAAC,SAAS,CAAC,IAAI;AACjB,UAAM,IAAI,MAAM,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D;AAAA,cACA,UACE,SAAS,SAAS,OAAO,UAAU,SAAS,CAAC,GAAG,OAAO;AAAA,YAC3D;AAAA,UACF;AAAA,QACF;AAEA,YAAI,MAAM,WAAW,OAAO,UAAU,WAAW,MAAM;AACrD,sBAAY,iCACP,QADO;AAAA,YAEV,YAAY,iCACP,MAAM,aADC;AAAA,cAEV,OAAO;AAAA,cACP;AAAA,cACA,UAAU;AAAA,YACZ;AAAA,UACF;AAAA,QACF;AAEA,YAAI,KAAK,WAAW,OAAO,UAAU,WAAW,MAAM;AACpD,sBAAY,iCACP,OADO;AAAA,YAEV,YAAY,iCACP,KAAK,aADE;AAAA,cAEV,OAAO,IAAI;AAAA,cACX;AAAA,cACA,UAAU,SAAS;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAEA,YACE,eACA,YAAY,WAAW,OAAO,UAAU,WAAW,MACnD;AACA,sBAAY,iCACP,cADO;AAAA,YAEV,YAAY,iCAAK,YAAY,aAAjB,EAA6B,OAAO,EAAE;AAAA,UACpD;AAAA,QACF;AAEA,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAGA,IAAO,qCAAQ","sourcesContent":["import { Feature, Point, LineString, MultiLineString } from \"geojson\";\nimport { bearing } from \"@turf/bearing\";\nimport { distance } from \"@turf/distance\";\nimport { destination } from \"@turf/destination\";\nimport { lineIntersect as lineIntersects } from \"@turf/line-intersect\";\nimport { flattenEach } from \"@turf/meta\";\nimport { point, lineString, Coord, Units } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\n\n/**\n * Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString.\n *\n * @name nearestPointOnLine\n * @param {Geometry|Feature<LineString|MultiLineString>} lines lines to snap to\n * @param {Geometry|Feature<Point>|number[]} pt point to snap from\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain four values: `index`: closest point was found on nth line part, `multiFeatureIndex`: closest point was found on the nth line of the `MultiLineString`, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var pt = turf.point([-77.037076, 38.884017]);\n *\n * var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line, pt, snapped];\n * snapped.properties['marker-color'] = '#00f';\n */\nfunction nearestPointOnLine<G extends LineString | MultiLineString>(\n lines: Feature<G> | G,\n pt: Coord,\n options: { units?: Units } = {}\n): Feature<\n Point,\n {\n dist: number;\n index: number;\n multiFeatureIndex: number;\n location: number;\n [key: string]: any;\n }\n> {\n if (!lines || !pt) {\n throw new Error(\"lines and pt are required arguments\");\n }\n\n let closestPt: Feature<\n Point,\n { dist: number; index: number; multiFeatureIndex: number; location: number }\n > = point([Infinity, Infinity], {\n dist: Infinity,\n index: -1,\n multiFeatureIndex: -1,\n location: -1,\n });\n\n let length = 0.0;\n flattenEach(\n lines,\n function (line: any, _featureIndex: number, multiFeatureIndex: number) {\n const coords: any = getCoords(line);\n\n for (let i = 0; i < coords.length - 1; i++) {\n //start\n const start: Feature<Point, { dist: number }> = point(coords[i]);\n start.properties.dist = distance(pt, start, options);\n //stop\n const stop: Feature<Point, { dist: number }> = point(coords[i + 1]);\n stop.properties.dist = distance(pt, stop, options);\n // sectionLength\n const sectionLength = distance(start, stop, options);\n //perpendicular\n const heightDistance = Math.max(\n start.properties.dist,\n stop.properties.dist\n );\n const direction = bearing(start, stop);\n const perpendicularPt1 = destination(\n pt,\n heightDistance,\n direction + 90,\n options\n );\n const perpendicularPt2 = destination(\n pt,\n heightDistance,\n direction - 90,\n options\n );\n const intersect = lineIntersects(\n lineString([\n perpendicularPt1.geometry.coordinates,\n perpendicularPt2.geometry.coordinates,\n ]),\n lineString([start.geometry.coordinates, stop.geometry.coordinates])\n );\n let intersectPt:\n | Feature<\n Point,\n { dist: number; multiFeatureIndex: number; location: number }\n >\n | undefined;\n\n if (intersect.features.length > 0 && intersect.features[0]) {\n intersectPt = {\n ...intersect.features[0],\n properties: {\n dist: distance(pt, intersect.features[0], options),\n multiFeatureIndex: multiFeatureIndex,\n location:\n length + distance(start, intersect.features[0], options),\n },\n };\n }\n\n if (start.properties.dist < closestPt.properties.dist) {\n closestPt = {\n ...start,\n properties: {\n ...start.properties,\n index: i,\n multiFeatureIndex: multiFeatureIndex,\n location: length,\n },\n };\n }\n\n if (stop.properties.dist < closestPt.properties.dist) {\n closestPt = {\n ...stop,\n properties: {\n ...stop.properties,\n index: i + 1,\n multiFeatureIndex: multiFeatureIndex,\n location: length + sectionLength,\n },\n };\n }\n\n if (\n intersectPt &&\n intersectPt.properties.dist < closestPt.properties.dist\n ) {\n closestPt = {\n ...intersectPt,\n properties: { ...intersectPt.properties, index: i },\n };\n }\n // update length\n length += sectionLength;\n }\n }\n );\n\n return closestPt;\n}\n\nexport { nearestPointOnLine };\nexport default nearestPointOnLine;\n"]}
@@ -9,7 +9,7 @@ import { Coord, Units } from '@turf/helpers';
9
9
  * @param {Geometry|Feature<Point>|number[]} pt point to snap from
10
10
  * @param {Object} [options={}] Optional parameters
11
11
  * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
12
- * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.
12
+ * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain four values: `index`: closest point was found on nth line part, `multiFeatureIndex`: closest point was found on the nth line of the `MultiLineString`, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.
13
13
  * @example
14
14
  * var line = turf.lineString([
15
15
  * [-77.031669, 38.878605],
@@ -32,6 +32,7 @@ declare function nearestPointOnLine<G extends LineString | MultiLineString>(line
32
32
  }): Feature<Point, {
33
33
  dist: number;
34
34
  index: number;
35
+ multiFeatureIndex: number;
35
36
  location: number;
36
37
  [key: string]: any;
37
38
  }>;
@@ -9,7 +9,7 @@ import { Coord, Units } from '@turf/helpers';
9
9
  * @param {Geometry|Feature<Point>|number[]} pt point to snap from
10
10
  * @param {Object} [options={}] Optional parameters
11
11
  * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
12
- * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.
12
+ * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain four values: `index`: closest point was found on nth line part, `multiFeatureIndex`: closest point was found on the nth line of the `MultiLineString`, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.
13
13
  * @example
14
14
  * var line = turf.lineString([
15
15
  * [-77.031669, 38.878605],
@@ -32,6 +32,7 @@ declare function nearestPointOnLine<G extends LineString | MultiLineString>(line
32
32
  }): Feature<Point, {
33
33
  dist: number;
34
34
  index: number;
35
+ multiFeatureIndex: number;
35
36
  location: number;
36
37
  [key: string]: any;
37
38
  }>;
package/dist/esm/index.js CHANGED
@@ -33,71 +33,81 @@ function nearestPointOnLine(lines, pt, options = {}) {
33
33
  let closestPt = point([Infinity, Infinity], {
34
34
  dist: Infinity,
35
35
  index: -1,
36
+ multiFeatureIndex: -1,
36
37
  location: -1
37
38
  });
38
39
  let length = 0;
39
- flattenEach(lines, function(line) {
40
- const coords = getCoords(line);
41
- for (let i = 0; i < coords.length - 1; i++) {
42
- const start = point(coords[i]);
43
- start.properties.dist = distance(pt, start, options);
44
- const stop = point(coords[i + 1]);
45
- stop.properties.dist = distance(pt, stop, options);
46
- const sectionLength = distance(start, stop, options);
47
- const heightDistance = Math.max(
48
- start.properties.dist,
49
- stop.properties.dist
50
- );
51
- const direction = bearing(start, stop);
52
- const perpendicularPt1 = destination(
53
- pt,
54
- heightDistance,
55
- direction + 90,
56
- options
57
- );
58
- const perpendicularPt2 = destination(
59
- pt,
60
- heightDistance,
61
- direction - 90,
62
- options
63
- );
64
- const intersect = lineIntersects(
65
- lineString([
66
- perpendicularPt1.geometry.coordinates,
67
- perpendicularPt2.geometry.coordinates
68
- ]),
69
- lineString([start.geometry.coordinates, stop.geometry.coordinates])
70
- );
71
- let intersectPt;
72
- if (intersect.features.length > 0 && intersect.features[0]) {
73
- intersectPt = __spreadProps(__spreadValues({}, intersect.features[0]), {
74
- properties: {
75
- dist: distance(pt, intersect.features[0], options),
76
- location: length + distance(start, intersect.features[0], options)
77
- }
78
- });
40
+ flattenEach(
41
+ lines,
42
+ function(line, _featureIndex, multiFeatureIndex) {
43
+ const coords = getCoords(line);
44
+ for (let i = 0; i < coords.length - 1; i++) {
45
+ const start = point(coords[i]);
46
+ start.properties.dist = distance(pt, start, options);
47
+ const stop = point(coords[i + 1]);
48
+ stop.properties.dist = distance(pt, stop, options);
49
+ const sectionLength = distance(start, stop, options);
50
+ const heightDistance = Math.max(
51
+ start.properties.dist,
52
+ stop.properties.dist
53
+ );
54
+ const direction = bearing(start, stop);
55
+ const perpendicularPt1 = destination(
56
+ pt,
57
+ heightDistance,
58
+ direction + 90,
59
+ options
60
+ );
61
+ const perpendicularPt2 = destination(
62
+ pt,
63
+ heightDistance,
64
+ direction - 90,
65
+ options
66
+ );
67
+ const intersect = lineIntersects(
68
+ lineString([
69
+ perpendicularPt1.geometry.coordinates,
70
+ perpendicularPt2.geometry.coordinates
71
+ ]),
72
+ lineString([start.geometry.coordinates, stop.geometry.coordinates])
73
+ );
74
+ let intersectPt;
75
+ if (intersect.features.length > 0 && intersect.features[0]) {
76
+ intersectPt = __spreadProps(__spreadValues({}, intersect.features[0]), {
77
+ properties: {
78
+ dist: distance(pt, intersect.features[0], options),
79
+ multiFeatureIndex,
80
+ location: length + distance(start, intersect.features[0], options)
81
+ }
82
+ });
83
+ }
84
+ if (start.properties.dist < closestPt.properties.dist) {
85
+ closestPt = __spreadProps(__spreadValues({}, start), {
86
+ properties: __spreadProps(__spreadValues({}, start.properties), {
87
+ index: i,
88
+ multiFeatureIndex,
89
+ location: length
90
+ })
91
+ });
92
+ }
93
+ if (stop.properties.dist < closestPt.properties.dist) {
94
+ closestPt = __spreadProps(__spreadValues({}, stop), {
95
+ properties: __spreadProps(__spreadValues({}, stop.properties), {
96
+ index: i + 1,
97
+ multiFeatureIndex,
98
+ location: length + sectionLength
99
+ })
100
+ });
101
+ }
102
+ if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) {
103
+ closestPt = __spreadProps(__spreadValues({}, intersectPt), {
104
+ properties: __spreadProps(__spreadValues({}, intersectPt.properties), { index: i })
105
+ });
106
+ }
107
+ length += sectionLength;
79
108
  }
80
- if (start.properties.dist < closestPt.properties.dist) {
81
- closestPt = __spreadProps(__spreadValues({}, start), {
82
- properties: __spreadProps(__spreadValues({}, start.properties), { index: i, location: length })
83
- });
84
- }
85
- if (stop.properties.dist < closestPt.properties.dist) {
86
- closestPt = __spreadProps(__spreadValues({}, stop), {
87
- properties: __spreadProps(__spreadValues({}, stop.properties), {
88
- index: i + 1,
89
- location: length + sectionLength
90
- })
91
- });
92
- }
93
- if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) {
94
- closestPt = __spreadProps(__spreadValues({}, intersectPt), {
95
- properties: __spreadProps(__spreadValues({}, intersectPt.properties), { index: i })
96
- });
97
- }
98
- length += sectionLength;
99
109
  }
100
- });
110
+ );
101
111
  return closestPt;
102
112
  }
103
113
  var turf_nearest_point_on_line_default = nearestPointOnLine;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, Point, LineString, MultiLineString } from \"geojson\";\nimport { bearing } from \"@turf/bearing\";\nimport { distance } from \"@turf/distance\";\nimport { destination } from \"@turf/destination\";\nimport { lineIntersect as lineIntersects } from \"@turf/line-intersect\";\nimport { flattenEach } from \"@turf/meta\";\nimport { point, lineString, Coord, Units } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\n\n/**\n * Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString.\n *\n * @name nearestPointOnLine\n * @param {Geometry|Feature<LineString|MultiLineString>} lines lines to snap to\n * @param {Geometry|Feature<Point>|number[]} pt point to snap from\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var pt = turf.point([-77.037076, 38.884017]);\n *\n * var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line, pt, snapped];\n * snapped.properties['marker-color'] = '#00f';\n */\nfunction nearestPointOnLine<G extends LineString | MultiLineString>(\n lines: Feature<G> | G,\n pt: Coord,\n options: { units?: Units } = {}\n): Feature<\n Point,\n {\n dist: number;\n index: number;\n location: number;\n [key: string]: any;\n }\n> {\n if (!lines || !pt) {\n throw new Error(\"lines and pt are required arguments\");\n }\n\n let closestPt: Feature<\n Point,\n { dist: number; index: number; location: number }\n > = point([Infinity, Infinity], {\n dist: Infinity,\n index: -1,\n location: -1,\n });\n\n let length = 0.0;\n flattenEach(lines, function (line: any) {\n const coords: any = getCoords(line);\n\n for (let i = 0; i < coords.length - 1; i++) {\n //start\n const start: Feature<Point, { dist: number }> = point(coords[i]);\n start.properties.dist = distance(pt, start, options);\n //stop\n const stop: Feature<Point, { dist: number }> = point(coords[i + 1]);\n stop.properties.dist = distance(pt, stop, options);\n // sectionLength\n const sectionLength = distance(start, stop, options);\n //perpendicular\n const heightDistance = Math.max(\n start.properties.dist,\n stop.properties.dist\n );\n const direction = bearing(start, stop);\n const perpendicularPt1 = destination(\n pt,\n heightDistance,\n direction + 90,\n options\n );\n const perpendicularPt2 = destination(\n pt,\n heightDistance,\n direction - 90,\n options\n );\n const intersect = lineIntersects(\n lineString([\n perpendicularPt1.geometry.coordinates,\n perpendicularPt2.geometry.coordinates,\n ]),\n lineString([start.geometry.coordinates, stop.geometry.coordinates])\n );\n let intersectPt:\n | Feature<Point, { dist: number; location: number }>\n | undefined;\n\n if (intersect.features.length > 0 && intersect.features[0]) {\n intersectPt = {\n ...intersect.features[0],\n properties: {\n dist: distance(pt, intersect.features[0], options),\n location: length + distance(start, intersect.features[0], options),\n },\n };\n }\n\n if (start.properties.dist < closestPt.properties.dist) {\n closestPt = {\n ...start,\n properties: { ...start.properties, index: i, location: length },\n };\n }\n\n if (stop.properties.dist < closestPt.properties.dist) {\n closestPt = {\n ...stop,\n properties: {\n ...stop.properties,\n index: i + 1,\n location: length + sectionLength,\n },\n };\n }\n\n if (\n intersectPt &&\n intersectPt.properties.dist < closestPt.properties.dist\n ) {\n closestPt = {\n ...intersectPt,\n properties: { ...intersectPt.properties, index: i },\n };\n }\n // update length\n length += sectionLength;\n }\n });\n\n return closestPt;\n}\n\nexport { nearestPointOnLine };\nexport default nearestPointOnLine;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,sBAAsB;AAChD,SAAS,mBAAmB;AAC5B,SAAS,OAAO,kBAAgC;AAChD,SAAS,iBAAiB;AA4B1B,SAAS,mBACP,OACA,IACA,UAA6B,CAAC,GAS9B;AACA,MAAI,CAAC,SAAS,CAAC,IAAI;AACjB,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,MAAI,YAGA,MAAM,CAAC,UAAU,QAAQ,GAAG;AAAA,IAC9B,MAAM;AAAA,IACN,OAAO;AAAA,IACP,UAA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A,UAEV,YAAY,iCAAK,MAAM,aAAX,EAAuB,OAAO,GAAG,UAAU,OAAO;AAAA,QAChE;AAAA,MACF;AAEA,UAAI,KAAK,WAAW,OAAO,UAAU,WAAW,MAAM;AACpD,oBAAY,iCACP,OADO;AAAA,UAEV,YAAY,iCACP,KAAK,aADE;AAAA,YAEV,OAAO,IAAI;AAAA,YACX,UAAU,SAAS;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAEA,UACE,eACA,YAAY,WAAW,OAAO,UAAU,WAAW,MACnD;AACA,oBAAY,iCACP,cADO;AAAA,UAEV,YAAY,iCAAK,YAAY,aAAjB,EAA6B,OAAO,EAAE;AAAA,QACpD;AAAA,MACF;AAEA,gBAAU;AAAA,IACZ;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAGA,IAAO,qCAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, Point, LineString, MultiLineString } from \"geojson\";\nimport { bearing } from \"@turf/bearing\";\nimport { distance } from \"@turf/distance\";\nimport { destination } from \"@turf/destination\";\nimport { lineIntersect as lineIntersects } from \"@turf/line-intersect\";\nimport { flattenEach } from \"@turf/meta\";\nimport { point, lineString, Coord, Units } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\n\n/**\n * Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString.\n *\n * @name nearestPointOnLine\n * @param {Geometry|Feature<LineString|MultiLineString>} lines lines to snap to\n * @param {Geometry|Feature<Point>|number[]} pt point to snap from\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain four values: `index`: closest point was found on nth line part, `multiFeatureIndex`: closest point was found on the nth line of the `MultiLineString`, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point.\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var pt = turf.point([-77.037076, 38.884017]);\n *\n * var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line, pt, snapped];\n * snapped.properties['marker-color'] = '#00f';\n */\nfunction nearestPointOnLine<G extends LineString | MultiLineString>(\n lines: Feature<G> | G,\n pt: Coord,\n options: { units?: Units } = {}\n): Feature<\n Point,\n {\n dist: number;\n index: number;\n multiFeatureIndex: number;\n location: number;\n [key: string]: any;\n }\n> {\n if (!lines || !pt) {\n throw new Error(\"lines and pt are required arguments\");\n }\n\n let closestPt: Feature<\n Point,\n { dist: number; index: number; multiFeatureIndex: number; location: number }\n > = point([Infinity, Infinity], {\n dist: Infinity,\n index: -1,\n multiFeatureIndex: -1,\n location: -1,\n });\n\n let length = 0.0;\n flattenEach(\n lines,\n function (line: any, _featureIndex: number, multiFeatureIndex: number) {\n const coords: any = getCoords(line);\n\n for (let i = 0; i < coords.length - 1; i++) {\n //start\n const start: Feature<Point, { dist: number }> = point(coords[i]);\n start.properties.dist = distance(pt, start, options);\n //stop\n const stop: Feature<Point, { dist: number }> = point(coords[i + 1]);\n stop.properties.dist = distance(pt, stop, options);\n // sectionLength\n const sectionLength = distance(start, stop, options);\n //perpendicular\n const heightDistance = Math.max(\n start.properties.dist,\n stop.properties.dist\n );\n const direction = bearing(start, stop);\n const perpendicularPt1 = destination(\n pt,\n heightDistance,\n direction + 90,\n options\n );\n const perpendicularPt2 = destination(\n pt,\n heightDistance,\n direction - 90,\n options\n );\n const intersect = lineIntersects(\n lineString([\n perpendicularPt1.geometry.coordinates,\n perpendicularPt2.geometry.coordinates,\n ]),\n lineString([start.geometry.coordinates, stop.geometry.coordinates])\n );\n let intersectPt:\n | Feature<\n Point,\n { dist: number; multiFeatureIndex: number; location: number }\n >\n | undefined;\n\n if (intersect.features.length > 0 && intersect.features[0]) {\n intersectPt = {\n ...intersect.features[0],\n properties: {\n dist: distance(pt, intersect.features[0], options),\n multiFeatureIndex: multiFeatureIndex,\n location:\n length + distance(start, intersect.features[0], options),\n },\n };\n }\n\n if (start.properties.dist < closestPt.properties.dist) {\n closestPt = {\n ...start,\n properties: {\n ...start.properties,\n index: i,\n multiFeatureIndex: multiFeatureIndex,\n location: length,\n },\n };\n }\n\n if (stop.properties.dist < closestPt.properties.dist) {\n closestPt = {\n ...stop,\n properties: {\n ...stop.properties,\n index: i + 1,\n multiFeatureIndex: multiFeatureIndex,\n location: length + sectionLength,\n },\n };\n }\n\n if (\n intersectPt &&\n intersectPt.properties.dist < closestPt.properties.dist\n ) {\n closestPt = {\n ...intersectPt,\n properties: { ...intersectPt.properties, index: i },\n };\n }\n // update length\n length += sectionLength;\n }\n }\n );\n\n return closestPt;\n}\n\nexport { nearestPointOnLine };\nexport default nearestPointOnLine;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,sBAAsB;AAChD,SAAS,mBAAmB;AAC5B,SAAS,OAAO,kBAAgC;AAChD,SAAS,iBAAiB;AA4B1B,SAAS,mBACP,OACA,IACA,UAA6B,CAAC,GAU9B;AACA,MAAI,CAAC,SAAS,CAAC,IAAI;AACjB,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,MAAI,YAGA,MAAM,CAAC,UAAU,QAAQ,GAAG;AAAA,IAC9B,MAAM;AAAA,IACN,OAAO;AAAA,IACP,mBAAmB;AAAA,IACnB,UAAU;AAAA,EACZ,CAAC;AAED,MAAI,SAAS;AACb;AAAA,IACE;AAAA,IACA,SAAU,MAAW,eAAuB,mBAA2B;AACrE,YAAM,SAAc,UAAU,IAAI;AAElC,eAAS,IAAI,GAAG,IAAI,OAAO,SAAS,GAAG,KAAK;AAE1C,cAAM,QAA0C,MAAM,OAAO,CAAC,CAAC;AAC/D,cAAM,WAAW,OA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,KAAK,aADE;AAAA,cAEV,OAAO,IAAI;AAAA,cACX;AAAA,cACA,UAAU,SAAS;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAEA,YACE,eACA,YAAY,WAAW,OAAO,UAAU,WAAW,MACnD;AACA,sBAAY,iCACP,cADO;AAAA,YAEV,YAAY,iCAAK,YAAY,aAAjB,EAA6B,OAAO,EAAE;AAAA,UACpD;AAAA,QACF;AAEA,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAGA,IAAO,qCAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/nearest-point-on-line",
3
- "version": "7.1.0-alpha.7+0ce6ecca0",
3
+ "version": "7.1.0",
4
4
  "description": "turf nearest-point-on-line module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -46,9 +46,9 @@
46
46
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
47
47
  },
48
48
  "devDependencies": {
49
- "@turf/along": "^7.1.0-alpha.7+0ce6ecca0",
50
- "@turf/length": "^7.1.0-alpha.7+0ce6ecca0",
51
- "@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0",
49
+ "@turf/along": "^7.1.0",
50
+ "@turf/length": "^7.1.0",
51
+ "@turf/truncate": "^7.1.0",
52
52
  "@types/benchmark": "^2.1.5",
53
53
  "@types/tape": "^4.2.32",
54
54
  "benchmark": "^2.1.4",
@@ -61,14 +61,15 @@
61
61
  "write-json-file": "^5.0.0"
62
62
  },
63
63
  "dependencies": {
64
- "@turf/bearing": "^7.1.0-alpha.7+0ce6ecca0",
65
- "@turf/destination": "^7.1.0-alpha.7+0ce6ecca0",
66
- "@turf/distance": "^7.1.0-alpha.7+0ce6ecca0",
67
- "@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
68
- "@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0",
69
- "@turf/line-intersect": "^7.1.0-alpha.7+0ce6ecca0",
70
- "@turf/meta": "^7.1.0-alpha.7+0ce6ecca0",
64
+ "@turf/bearing": "^7.1.0",
65
+ "@turf/destination": "^7.1.0",
66
+ "@turf/distance": "^7.1.0",
67
+ "@turf/helpers": "^7.1.0",
68
+ "@turf/invariant": "^7.1.0",
69
+ "@turf/line-intersect": "^7.1.0",
70
+ "@turf/meta": "^7.1.0",
71
+ "@types/geojson": "^7946.0.10",
71
72
  "tslib": "^2.6.2"
72
73
  },
73
- "gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
74
+ "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
74
75
  }