@turf/along 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 +8 -7
- package/dist/es/index.js +8 -9
- package/dist/js/index.d.ts +2 -1
- package/dist/js/index.js +14 -17
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
|
|
7
7
|
Takes a [LineString][1] and returns a [Point][2] at a specified distance along the line.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- `options.units` **[string][7]** can be degrees, radians, miles, or kilometers (optional, default `"kilometers"`)
|
|
11
|
+
* `line` **[Feature][3]<[LineString][4]>** input line
|
|
12
|
+
* `distance` **[number][5]** distance along the line
|
|
13
|
+
* `options` **[Object][6]?** Optional parameters
|
|
15
14
|
|
|
16
|
-
**
|
|
15
|
+
* `options.units` **[string][7]** can be degrees, radians, miles, or kilometers (optional, default `"kilometers"`)
|
|
16
|
+
|
|
17
|
+
### Examples
|
|
17
18
|
|
|
18
19
|
```javascript
|
|
19
20
|
var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
|
|
@@ -25,7 +26,7 @@ var along = turf.along(line, 200, options);
|
|
|
25
26
|
var addToMap = [along, line]
|
|
26
27
|
```
|
|
27
28
|
|
|
28
|
-
Returns **[Feature][3]
|
|
29
|
+
Returns **[Feature][3]<[Point][8]>** Point `distance` `units` along the line
|
|
29
30
|
|
|
30
31
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.4
|
|
31
32
|
|
package/dist/es/index.js
CHANGED
|
@@ -21,24 +21,23 @@ import { getGeom } from "@turf/invariant";
|
|
|
21
21
|
* //addToMap
|
|
22
22
|
* var addToMap = [along, line]
|
|
23
23
|
*/
|
|
24
|
-
export default function along(line, distance, options) {
|
|
25
|
-
if (options === void 0) { options = {}; }
|
|
24
|
+
export default function along(line, distance, options = {}) {
|
|
26
25
|
// Get Coords
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (
|
|
26
|
+
const geom = getGeom(line);
|
|
27
|
+
const coords = geom.coordinates;
|
|
28
|
+
let travelled = 0;
|
|
29
|
+
for (let i = 0; i < coords.length; i++) {
|
|
31
30
|
if (distance >= travelled && i === coords.length - 1) {
|
|
32
31
|
break;
|
|
33
32
|
}
|
|
34
33
|
else if (travelled >= distance) {
|
|
35
|
-
|
|
34
|
+
const overshot = distance - travelled;
|
|
36
35
|
if (!overshot) {
|
|
37
36
|
return point(coords[i]);
|
|
38
37
|
}
|
|
39
38
|
else {
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
40
|
+
const interpolated = destination(coords[i], overshot, direction, options);
|
|
42
41
|
return interpolated;
|
|
43
42
|
}
|
|
44
43
|
}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Feature, LineString, Point
|
|
1
|
+
import { Feature, LineString, Point } from "geojson";
|
|
2
|
+
import { Units } from "@turf/helpers";
|
|
2
3
|
/**
|
|
3
4
|
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
|
|
4
5
|
*
|
package/dist/js/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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");
|
|
11
9
|
/**
|
|
12
10
|
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
|
|
13
11
|
*
|
|
@@ -26,24 +24,23 @@ var invariant_1 = require("@turf/invariant");
|
|
|
26
24
|
* //addToMap
|
|
27
25
|
* var addToMap = [along, line]
|
|
28
26
|
*/
|
|
29
|
-
function along(line, distance, options) {
|
|
30
|
-
if (options === void 0) { options = {}; }
|
|
27
|
+
function along(line, distance, options = {}) {
|
|
31
28
|
// Get Coords
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
for (
|
|
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++) {
|
|
36
33
|
if (distance >= travelled && i === coords.length - 1) {
|
|
37
34
|
break;
|
|
38
35
|
}
|
|
39
36
|
else if (travelled >= distance) {
|
|
40
|
-
|
|
37
|
+
const overshot = distance - travelled;
|
|
41
38
|
if (!overshot) {
|
|
42
39
|
return helpers_1.point(coords[i]);
|
|
43
40
|
}
|
|
44
41
|
else {
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const direction = bearing_1.default(coords[i], coords[i - 1]) - 180;
|
|
43
|
+
const interpolated = destination_1.default(coords[i], overshot, direction, options);
|
|
47
44
|
return interpolated;
|
|
48
45
|
}
|
|
49
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/along",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf along module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,11 +57,12 @@
|
|
|
57
57
|
"typescript": "*"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@turf/bearing": "^
|
|
61
|
-
"@turf/destination": "^
|
|
62
|
-
"@turf/distance": "^
|
|
63
|
-
"@turf/helpers": "^
|
|
64
|
-
"@turf/invariant": "^
|
|
60
|
+
"@turf/bearing": "^7.0.0-alpha.0",
|
|
61
|
+
"@turf/destination": "^7.0.0-alpha.0",
|
|
62
|
+
"@turf/distance": "^7.0.0-alpha.0",
|
|
63
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
64
|
+
"@turf/invariant": "^7.0.0-alpha.0",
|
|
65
|
+
"tslib": "^2.3.0"
|
|
65
66
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
67
68
|
}
|