@turf/along 7.0.0-alpha.2 → 7.0.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 +4 -9
- package/dist/cjs/index.cjs +43 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +26 -0
- package/dist/{js → esm}/index.d.ts +6 -3
- package/dist/esm/index.js +43 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +34 -29
- package/dist/es/index.js +0 -49
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -53
package/README.md
CHANGED
|
@@ -44,26 +44,21 @@ Returns **[Feature][3]<[Point][8]>** Point `distance` `units` along the line
|
|
|
44
44
|
|
|
45
45
|
[8]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
46
46
|
|
|
47
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
48
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
49
|
-
./scripts/generate-readmes in the turf project. -->
|
|
47
|
+
<!-- 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. -->
|
|
50
48
|
|
|
51
49
|
---
|
|
52
50
|
|
|
53
|
-
This module is part of the [Turfjs project](
|
|
54
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
55
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
56
|
-
PRs and issues.
|
|
51
|
+
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.
|
|
57
52
|
|
|
58
53
|
### Installation
|
|
59
54
|
|
|
60
|
-
Install this module individually:
|
|
55
|
+
Install this single module individually:
|
|
61
56
|
|
|
62
57
|
```sh
|
|
63
58
|
$ npm install @turf/along
|
|
64
59
|
```
|
|
65
60
|
|
|
66
|
-
Or install the
|
|
61
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
67
62
|
|
|
68
63
|
```sh
|
|
69
64
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,43 @@
|
|
|
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 _bearing = require('@turf/bearing');
|
|
6
|
+
var _destination = require('@turf/destination');
|
|
7
|
+
var _distance = require('@turf/distance');
|
|
8
|
+
var _helpers = require('@turf/helpers');
|
|
9
|
+
var _invariant = require('@turf/invariant');
|
|
10
|
+
function along(line, distance, options = {}) {
|
|
11
|
+
const geom = _invariant.getGeom.call(void 0, line);
|
|
12
|
+
const coords = geom.coordinates;
|
|
13
|
+
let travelled = 0;
|
|
14
|
+
for (let i = 0; i < coords.length; i++) {
|
|
15
|
+
if (distance >= travelled && i === coords.length - 1) {
|
|
16
|
+
break;
|
|
17
|
+
} else if (travelled >= distance) {
|
|
18
|
+
const overshot = distance - travelled;
|
|
19
|
+
if (!overshot) {
|
|
20
|
+
return _helpers.point.call(void 0, coords[i]);
|
|
21
|
+
} else {
|
|
22
|
+
const direction = _bearing.bearing.call(void 0, coords[i], coords[i - 1]) - 180;
|
|
23
|
+
const interpolated = _destination.destination.call(void 0,
|
|
24
|
+
coords[i],
|
|
25
|
+
overshot,
|
|
26
|
+
direction,
|
|
27
|
+
options
|
|
28
|
+
);
|
|
29
|
+
return interpolated;
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
travelled += _distance.distance.call(void 0, coords[i], coords[i + 1], options);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return _helpers.point.call(void 0, coords[coords.length - 1]);
|
|
36
|
+
}
|
|
37
|
+
__name(along, "along");
|
|
38
|
+
var turf_along_default = along;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
exports.along = along; exports.default = turf_along_default;
|
|
43
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,YAAY,uBAAuB;AAC5C,SAAS,aAAoB;AAC7B,SAAS,eAAe;AAoBxB,SAAS,MACP,MACA,UACA,UAA6B,CAAC,GACd;AAEhB,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,SAAS,KAAK;AACpB,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,QAAI,YAAY,aAAa,MAAM,OAAO,SAAS,GAAG;AACpD;AAAA,IACF,WAAW,aAAa,UAAU;AAChC,YAAM,WAAW,WAAW;AAC5B,UAAI,CAAC,UAAU;AACb,eAAO,MAAM,OAAO,CAAC,CAAC;AAAA,MACxB,OAAO;AACL,cAAM,YAAY,QAAQ,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,IAAI;AACtD,cAAM,eAAe;AAAA,UACnB,OAAO,CAAC;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,IACF,OAAO;AACL,mBAAa,gBAAgB,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,OAAO;AAAA,IAChE;AAAA,EACF;AACA,SAAO,MAAM,OAAO,OAAO,SAAS,CAAC,CAAC;AACxC;AA/BS;AAkCT,IAAO,qBAAQ","sourcesContent":["import { Feature, LineString, Point } from \"geojson\";\nimport { bearing } from \"@turf/bearing\";\nimport { destination } from \"@turf/destination\";\nimport { distance as measureDistance } from \"@turf/distance\";\nimport { point, Units } from \"@turf/helpers\";\nimport { getGeom } from \"@turf/invariant\";\n\n/**\n * Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.\n *\n * @name along\n * @param {Feature<LineString>} line input line\n * @param {number} distance distance along the line\n * @param {Object} [options] Optional parameters\n * @param {string} [options.units=\"kilometers\"] can be degrees, radians, miles, or kilometers\n * @returns {Feature<Point>} Point `distance` `units` along the line\n * @example\n * var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);\n * var options = {units: 'miles'};\n *\n * var along = turf.along(line, 200, options);\n *\n * //addToMap\n * var addToMap = [along, line]\n */\nfunction along(\n line: Feature<LineString> | LineString,\n distance: number,\n options: { units?: Units } = {}\n): Feature<Point> {\n // Get Coords\n const geom = getGeom(line);\n const coords = geom.coordinates;\n let travelled = 0;\n for (let i = 0; i < coords.length; i++) {\n if (distance >= travelled && i === coords.length - 1) {\n break;\n } else if (travelled >= distance) {\n const overshot = distance - travelled;\n if (!overshot) {\n return point(coords[i]);\n } else {\n const direction = bearing(coords[i], coords[i - 1]) - 180;\n const interpolated = destination(\n coords[i],\n overshot,\n direction,\n options\n );\n return interpolated;\n }\n } else {\n travelled += measureDistance(coords[i], coords[i + 1], options);\n }\n }\n return point(coords[coords.length - 1]);\n}\n\nexport { along };\nexport default along;\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Feature, LineString, Point } from 'geojson';
|
|
2
|
+
import { Units } from '@turf/helpers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
|
|
6
|
+
*
|
|
7
|
+
* @name along
|
|
8
|
+
* @param {Feature<LineString>} line input line
|
|
9
|
+
* @param {number} distance distance along the line
|
|
10
|
+
* @param {Object} [options] Optional parameters
|
|
11
|
+
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
|
|
12
|
+
* @returns {Feature<Point>} Point `distance` `units` along the line
|
|
13
|
+
* @example
|
|
14
|
+
* var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
|
|
15
|
+
* var options = {units: 'miles'};
|
|
16
|
+
*
|
|
17
|
+
* var along = turf.along(line, 200, options);
|
|
18
|
+
*
|
|
19
|
+
* //addToMap
|
|
20
|
+
* var addToMap = [along, line]
|
|
21
|
+
*/
|
|
22
|
+
declare function along(line: Feature<LineString> | LineString, distance: number, options?: {
|
|
23
|
+
units?: Units;
|
|
24
|
+
}): Feature<Point>;
|
|
25
|
+
|
|
26
|
+
export { along, along as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Feature, LineString, Point } from
|
|
2
|
-
import { Units } from
|
|
1
|
+
import { Feature, LineString, Point } from 'geojson';
|
|
2
|
+
import { Units } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
|
|
5
6
|
*
|
|
@@ -18,6 +19,8 @@ import { Units } from "@turf/helpers";
|
|
|
18
19
|
* //addToMap
|
|
19
20
|
* var addToMap = [along, line]
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
declare function along(line: Feature<LineString> | LineString, distance: number, options?: {
|
|
22
23
|
units?: Units;
|
|
23
24
|
}): Feature<Point>;
|
|
25
|
+
|
|
26
|
+
export { along, along as default };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { bearing } from "@turf/bearing";
|
|
6
|
+
import { destination } from "@turf/destination";
|
|
7
|
+
import { distance as measureDistance } from "@turf/distance";
|
|
8
|
+
import { point } from "@turf/helpers";
|
|
9
|
+
import { getGeom } from "@turf/invariant";
|
|
10
|
+
function along(line, distance, options = {}) {
|
|
11
|
+
const geom = getGeom(line);
|
|
12
|
+
const coords = geom.coordinates;
|
|
13
|
+
let travelled = 0;
|
|
14
|
+
for (let i = 0; i < coords.length; i++) {
|
|
15
|
+
if (distance >= travelled && i === coords.length - 1) {
|
|
16
|
+
break;
|
|
17
|
+
} else if (travelled >= distance) {
|
|
18
|
+
const overshot = distance - travelled;
|
|
19
|
+
if (!overshot) {
|
|
20
|
+
return point(coords[i]);
|
|
21
|
+
} else {
|
|
22
|
+
const direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
23
|
+
const interpolated = destination(
|
|
24
|
+
coords[i],
|
|
25
|
+
overshot,
|
|
26
|
+
direction,
|
|
27
|
+
options
|
|
28
|
+
);
|
|
29
|
+
return interpolated;
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
travelled += measureDistance(coords[i], coords[i + 1], options);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return point(coords[coords.length - 1]);
|
|
36
|
+
}
|
|
37
|
+
__name(along, "along");
|
|
38
|
+
var turf_along_default = along;
|
|
39
|
+
export {
|
|
40
|
+
along,
|
|
41
|
+
turf_along_default as default
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, LineString, Point } from \"geojson\";\nimport { bearing } from \"@turf/bearing\";\nimport { destination } from \"@turf/destination\";\nimport { distance as measureDistance } from \"@turf/distance\";\nimport { point, Units } from \"@turf/helpers\";\nimport { getGeom } from \"@turf/invariant\";\n\n/**\n * Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.\n *\n * @name along\n * @param {Feature<LineString>} line input line\n * @param {number} distance distance along the line\n * @param {Object} [options] Optional parameters\n * @param {string} [options.units=\"kilometers\"] can be degrees, radians, miles, or kilometers\n * @returns {Feature<Point>} Point `distance` `units` along the line\n * @example\n * var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);\n * var options = {units: 'miles'};\n *\n * var along = turf.along(line, 200, options);\n *\n * //addToMap\n * var addToMap = [along, line]\n */\nfunction along(\n line: Feature<LineString> | LineString,\n distance: number,\n options: { units?: Units } = {}\n): Feature<Point> {\n // Get Coords\n const geom = getGeom(line);\n const coords = geom.coordinates;\n let travelled = 0;\n for (let i = 0; i < coords.length; i++) {\n if (distance >= travelled && i === coords.length - 1) {\n break;\n } else if (travelled >= distance) {\n const overshot = distance - travelled;\n if (!overshot) {\n return point(coords[i]);\n } else {\n const direction = bearing(coords[i], coords[i - 1]) - 180;\n const interpolated = destination(\n coords[i],\n overshot,\n direction,\n options\n );\n return interpolated;\n }\n } else {\n travelled += measureDistance(coords[i], coords[i + 1], options);\n }\n }\n return point(coords[coords.length - 1]);\n}\n\nexport { along };\nexport default along;\n"],"mappings":";;;;AACA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,YAAY,uBAAuB;AAC5C,SAAS,aAAoB;AAC7B,SAAS,eAAe;AAoBxB,SAAS,MACP,MACA,UACA,UAA6B,CAAC,GACd;AAEhB,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,SAAS,KAAK;AACpB,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,QAAI,YAAY,aAAa,MAAM,OAAO,SAAS,GAAG;AACpD;AAAA,IACF,WAAW,aAAa,UAAU;AAChC,YAAM,WAAW,WAAW;AAC5B,UAAI,CAAC,UAAU;AACb,eAAO,MAAM,OAAO,CAAC,CAAC;AAAA,MACxB,OAAO;AACL,cAAM,YAAY,QAAQ,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,IAAI;AACtD,cAAM,eAAe;AAAA,UACnB,OAAO,CAAC;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,IACF,OAAO;AACL,mBAAa,gBAAgB,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,OAAO;AAAA,IAChE;AAAA,EACF;AACA,SAAO,MAAM,OAAO,OAAO,SAAS,CAAC,CAAC;AACxC;AA/BS;AAkCT,IAAO,qBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/along",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "turf along module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,47 +23,52 @@
|
|
|
23
23
|
"turf",
|
|
24
24
|
"distance"
|
|
25
25
|
],
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/cjs/index.cjs",
|
|
28
|
+
"module": "dist/esm/index.js",
|
|
29
|
+
"types": "dist/esm/index.d.ts",
|
|
28
30
|
"exports": {
|
|
29
31
|
"./package.json": "./package.json",
|
|
30
32
|
".": {
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/esm/index.d.ts",
|
|
35
|
+
"default": "./dist/esm/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/cjs/index.d.cts",
|
|
39
|
+
"default": "./dist/cjs/index.cjs"
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
},
|
|
36
|
-
"types": "dist/js/index.d.ts",
|
|
37
43
|
"sideEffects": false,
|
|
38
44
|
"files": [
|
|
39
45
|
"dist"
|
|
40
46
|
],
|
|
41
47
|
"scripts": {
|
|
42
|
-
"bench": "tsx bench.
|
|
43
|
-
"build": "
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"test": "npm-run-all test:*",
|
|
48
|
-
"test:tape": "tsx test.js"
|
|
48
|
+
"bench": "tsx bench.ts",
|
|
49
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
50
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
51
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
52
|
+
"test:tape": "tsx test.ts"
|
|
49
53
|
},
|
|
50
54
|
"devDependencies": {
|
|
51
|
-
"@types/
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
55
|
+
"@types/benchmark": "^2.1.5",
|
|
56
|
+
"@types/tape": "^4.2.32",
|
|
57
|
+
"benchmark": "^2.1.4",
|
|
58
|
+
"load-json-file": "^7.0.1",
|
|
59
|
+
"npm-run-all": "^4.1.5",
|
|
60
|
+
"tape": "^5.7.2",
|
|
61
|
+
"tsup": "^8.0.1",
|
|
62
|
+
"tsx": "^4.6.2",
|
|
63
|
+
"typescript": "^5.2.2"
|
|
59
64
|
},
|
|
60
65
|
"dependencies": {
|
|
61
|
-
"@turf/bearing": "^7.0.0
|
|
62
|
-
"@turf/destination": "^7.0.0
|
|
63
|
-
"@turf/distance": "^7.0.0
|
|
64
|
-
"@turf/helpers": "^7.0.0
|
|
65
|
-
"@turf/invariant": "^7.0.0
|
|
66
|
-
"tslib": "^2.
|
|
66
|
+
"@turf/bearing": "^7.0.0",
|
|
67
|
+
"@turf/destination": "^7.0.0",
|
|
68
|
+
"@turf/distance": "^7.0.0",
|
|
69
|
+
"@turf/helpers": "^7.0.0",
|
|
70
|
+
"@turf/invariant": "^7.0.0",
|
|
71
|
+
"tslib": "^2.6.2"
|
|
67
72
|
},
|
|
68
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
|
|
69
74
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import bearing from "@turf/bearing";
|
|
2
|
-
import destination from "@turf/destination";
|
|
3
|
-
import measureDistance from "@turf/distance";
|
|
4
|
-
import { point } from "@turf/helpers";
|
|
5
|
-
import { getGeom } from "@turf/invariant";
|
|
6
|
-
/**
|
|
7
|
-
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
|
|
8
|
-
*
|
|
9
|
-
* @name along
|
|
10
|
-
* @param {Feature<LineString>} line input line
|
|
11
|
-
* @param {number} distance distance along the line
|
|
12
|
-
* @param {Object} [options] Optional parameters
|
|
13
|
-
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
|
|
14
|
-
* @returns {Feature<Point>} Point `distance` `units` along the line
|
|
15
|
-
* @example
|
|
16
|
-
* var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
|
|
17
|
-
* var options = {units: 'miles'};
|
|
18
|
-
*
|
|
19
|
-
* var along = turf.along(line, 200, options);
|
|
20
|
-
*
|
|
21
|
-
* //addToMap
|
|
22
|
-
* var addToMap = [along, line]
|
|
23
|
-
*/
|
|
24
|
-
export default function along(line, distance, options = {}) {
|
|
25
|
-
// Get Coords
|
|
26
|
-
const geom = getGeom(line);
|
|
27
|
-
const coords = geom.coordinates;
|
|
28
|
-
let travelled = 0;
|
|
29
|
-
for (let i = 0; i < coords.length; i++) {
|
|
30
|
-
if (distance >= travelled && i === coords.length - 1) {
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
else if (travelled >= distance) {
|
|
34
|
-
const overshot = distance - travelled;
|
|
35
|
-
if (!overshot) {
|
|
36
|
-
return point(coords[i]);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
40
|
-
const interpolated = destination(coords[i], overshot, direction, options);
|
|
41
|
-
return interpolated;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
travelled += measureDistance(coords[i], coords[i + 1], options);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return point(coords[coords.length - 1]);
|
|
49
|
-
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const bearing_1 = tslib_1.__importDefault(require("@turf/bearing"));
|
|
5
|
-
const destination_1 = tslib_1.__importDefault(require("@turf/destination"));
|
|
6
|
-
const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
|
|
7
|
-
const helpers_1 = require("@turf/helpers");
|
|
8
|
-
const invariant_1 = require("@turf/invariant");
|
|
9
|
-
/**
|
|
10
|
-
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
|
|
11
|
-
*
|
|
12
|
-
* @name along
|
|
13
|
-
* @param {Feature<LineString>} line input line
|
|
14
|
-
* @param {number} distance distance along the line
|
|
15
|
-
* @param {Object} [options] Optional parameters
|
|
16
|
-
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
|
|
17
|
-
* @returns {Feature<Point>} Point `distance` `units` along the line
|
|
18
|
-
* @example
|
|
19
|
-
* var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
|
|
20
|
-
* var options = {units: 'miles'};
|
|
21
|
-
*
|
|
22
|
-
* var along = turf.along(line, 200, options);
|
|
23
|
-
*
|
|
24
|
-
* //addToMap
|
|
25
|
-
* var addToMap = [along, line]
|
|
26
|
-
*/
|
|
27
|
-
function along(line, distance, options = {}) {
|
|
28
|
-
// Get Coords
|
|
29
|
-
const geom = invariant_1.getGeom(line);
|
|
30
|
-
const coords = geom.coordinates;
|
|
31
|
-
let travelled = 0;
|
|
32
|
-
for (let i = 0; i < coords.length; i++) {
|
|
33
|
-
if (distance >= travelled && i === coords.length - 1) {
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
else if (travelled >= distance) {
|
|
37
|
-
const overshot = distance - travelled;
|
|
38
|
-
if (!overshot) {
|
|
39
|
-
return helpers_1.point(coords[i]);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const direction = bearing_1.default(coords[i], coords[i - 1]) - 180;
|
|
43
|
-
const interpolated = destination_1.default(coords[i], overshot, direction, options);
|
|
44
|
-
return interpolated;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
travelled += distance_1.default(coords[i], coords[i + 1], options);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return helpers_1.point(coords[coords.length - 1]);
|
|
52
|
-
}
|
|
53
|
-
exports.default = along;
|