@turf/line-slice-along 7.0.0-alpha.1 → 7.0.0-alpha.110
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 +67 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/esm/index.d.mts +16 -0
- package/dist/esm/index.mjs +67 -0
- package/dist/esm/index.mjs.map +1 -0
- package/index.d.ts +4 -1
- package/package.json +31 -24
- package/dist/es/index.js +0 -87
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -96
package/README.md
CHANGED
|
@@ -47,26 +47,21 @@ Returns **[Feature][3]<[LineString][4]>** sliced line
|
|
|
47
47
|
|
|
48
48
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
49
49
|
|
|
50
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
51
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
52
|
-
./scripts/generate-readmes in the turf project. -->
|
|
50
|
+
<!-- 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. -->
|
|
53
51
|
|
|
54
52
|
---
|
|
55
53
|
|
|
56
|
-
This module is part of the [Turfjs project](
|
|
57
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
58
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
59
|
-
PRs and issues.
|
|
54
|
+
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.
|
|
60
55
|
|
|
61
56
|
### Installation
|
|
62
57
|
|
|
63
|
-
Install this module individually:
|
|
58
|
+
Install this single module individually:
|
|
64
59
|
|
|
65
60
|
```sh
|
|
66
61
|
$ npm install @turf/line-slice-along
|
|
67
62
|
```
|
|
68
63
|
|
|
69
|
-
Or install the
|
|
64
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
70
65
|
|
|
71
66
|
```sh
|
|
72
67
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,67 @@
|
|
|
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.js
|
|
5
|
+
var _bearing = require('@turf/bearing');
|
|
6
|
+
var _distance = require('@turf/distance');
|
|
7
|
+
var _destination = require('@turf/destination');
|
|
8
|
+
var _helpers = require('@turf/helpers');
|
|
9
|
+
function lineSliceAlong(line, startDist, stopDist, options) {
|
|
10
|
+
options = options || {};
|
|
11
|
+
if (!_helpers.isObject.call(void 0, options))
|
|
12
|
+
throw new Error("options is invalid");
|
|
13
|
+
var coords;
|
|
14
|
+
var slice = [];
|
|
15
|
+
if (line.type === "Feature")
|
|
16
|
+
coords = line.geometry.coordinates;
|
|
17
|
+
else if (line.type === "LineString")
|
|
18
|
+
coords = line.coordinates;
|
|
19
|
+
else
|
|
20
|
+
throw new Error("input must be a LineString Feature or Geometry");
|
|
21
|
+
var origCoordsLength = coords.length;
|
|
22
|
+
var travelled = 0;
|
|
23
|
+
var overshot, direction, interpolated;
|
|
24
|
+
for (var i = 0; i < coords.length; i++) {
|
|
25
|
+
if (startDist >= travelled && i === coords.length - 1)
|
|
26
|
+
break;
|
|
27
|
+
else if (travelled > startDist && slice.length === 0) {
|
|
28
|
+
overshot = startDist - travelled;
|
|
29
|
+
if (!overshot) {
|
|
30
|
+
slice.push(coords[i]);
|
|
31
|
+
return _helpers.lineString.call(void 0, slice);
|
|
32
|
+
}
|
|
33
|
+
direction = _bearing.bearing.call(void 0, coords[i], coords[i - 1]) - 180;
|
|
34
|
+
interpolated = _destination.destination.call(void 0, coords[i], overshot, direction, options);
|
|
35
|
+
slice.push(interpolated.geometry.coordinates);
|
|
36
|
+
}
|
|
37
|
+
if (travelled >= stopDist) {
|
|
38
|
+
overshot = stopDist - travelled;
|
|
39
|
+
if (!overshot) {
|
|
40
|
+
slice.push(coords[i]);
|
|
41
|
+
return _helpers.lineString.call(void 0, slice);
|
|
42
|
+
}
|
|
43
|
+
direction = _bearing.bearing.call(void 0, coords[i], coords[i - 1]) - 180;
|
|
44
|
+
interpolated = _destination.destination.call(void 0, coords[i], overshot, direction, options);
|
|
45
|
+
slice.push(interpolated.geometry.coordinates);
|
|
46
|
+
return _helpers.lineString.call(void 0, slice);
|
|
47
|
+
}
|
|
48
|
+
if (travelled >= startDist) {
|
|
49
|
+
slice.push(coords[i]);
|
|
50
|
+
}
|
|
51
|
+
if (i === coords.length - 1) {
|
|
52
|
+
return _helpers.lineString.call(void 0, slice);
|
|
53
|
+
}
|
|
54
|
+
travelled += _distance.distance.call(void 0, coords[i], coords[i + 1], options);
|
|
55
|
+
}
|
|
56
|
+
if (travelled < startDist && coords.length === origCoordsLength)
|
|
57
|
+
throw new Error("Start position is beyond line");
|
|
58
|
+
var last = coords[coords.length - 1];
|
|
59
|
+
return _helpers.lineString.call(void 0, [last, last]);
|
|
60
|
+
}
|
|
61
|
+
__name(lineSliceAlong, "lineSliceAlong");
|
|
62
|
+
var turf_line_slice_along_default = lineSliceAlong;
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
exports.default = turf_line_slice_along_default; exports.lineSliceAlong = lineSliceAlong;
|
|
67
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"names":[],"mappings":";;;;AAAA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,YAAY,gBAAgB;AAyBrC,SAAS,eAAe,MAAM,WAAW,UAAU,SAAS;AAE1D,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,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zD;AAEA,MAAI,YAAY,aAAa,OAAO,WAAW;AAC7C,UAAM,IAAI,MAAM,+BAA+B;AAEjD,MAAI,OAAO,OAAO,OAAO,SAAS,CAAC;AACnC,SAAO,WAAW,CAAC,MAAM,IAAI,CAAC;AAChC;AAxDS;AA2DT,IAAO,gCAAQ","sourcesContent":["import { bearing } from \"@turf/bearing\";\nimport { distance } from \"@turf/distance\";\nimport { destination } from \"@turf/destination\";\nimport { lineString, isObject } from \"@turf/helpers\";\n\n/**\n * Takes a {@link LineString|line}, a specified distance along the line to a start {@link Point},\n * and a specified distance along the line to a stop point\n * and returns a subsection of the line in-between those points.\n *\n * This can be useful for extracting only the part of a route between two distances.\n *\n * @name lineSliceAlong\n * @param {Feature<LineString>|LineString} line input line\n * @param {number} startDist distance along the line to starting point\n * @param {number} stopDist distance along the line to ending point\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);\n * var start = 12.5;\n * var stop = 25;\n * var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line, start, stop, sliced]\n */\nfunction lineSliceAlong(line, startDist, stopDist, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n\n var coords;\n var slice = [];\n\n // Validation\n if (line.type === \"Feature\") coords = line.geometry.coordinates;\n else if (line.type === \"LineString\") coords = line.coordinates;\n else throw new Error(\"input must be a LineString Feature or Geometry\");\n var origCoordsLength = coords.length;\n var travelled = 0;\n var overshot, direction, interpolated;\n for (var i = 0; i < coords.length; i++) {\n if (startDist >= travelled && i === coords.length - 1) break;\n else if (travelled > startDist && slice.length === 0) {\n overshot = startDist - travelled;\n if (!overshot) {\n slice.push(coords[i]);\n return lineString(slice);\n }\n direction = bearing(coords[i], coords[i - 1]) - 180;\n interpolated = destination(coords[i], overshot, direction, options);\n slice.push(interpolated.geometry.coordinates);\n }\n\n if (travelled >= stopDist) {\n overshot = stopDist - travelled;\n if (!overshot) {\n slice.push(coords[i]);\n return lineString(slice);\n }\n direction = bearing(coords[i], coords[i - 1]) - 180;\n interpolated = destination(coords[i], overshot, direction, options);\n slice.push(interpolated.geometry.coordinates);\n return lineString(slice);\n }\n\n if (travelled >= startDist) {\n slice.push(coords[i]);\n }\n\n if (i === coords.length - 1) {\n return lineString(slice);\n }\n\n travelled += distance(coords[i], coords[i + 1], options);\n }\n\n if (travelled < startDist && coords.length === origCoordsLength)\n throw new Error(\"Start position is beyond line\");\n\n var last = coords[coords.length - 1];\n return lineString([last, last]);\n}\n\nexport { lineSliceAlong };\nexport default lineSliceAlong;\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Feature, LineString } from 'geojson';
|
|
2
|
+
import { Units } from '@turf/helpers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* http://turfjs.org/docs/
|
|
6
|
+
*/
|
|
7
|
+
declare function lineSliceAlong(
|
|
8
|
+
line: Feature<LineString> | LineString,
|
|
9
|
+
startDist: number,
|
|
10
|
+
stopDist: number,
|
|
11
|
+
options?: {
|
|
12
|
+
units?: Units;
|
|
13
|
+
}
|
|
14
|
+
): Feature<LineString>;
|
|
15
|
+
|
|
16
|
+
export { lineSliceAlong as default, lineSliceAlong };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Feature, LineString } from 'geojson';
|
|
2
|
+
import { Units } from '@turf/helpers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* http://turfjs.org/docs/
|
|
6
|
+
*/
|
|
7
|
+
declare function lineSliceAlong(
|
|
8
|
+
line: Feature<LineString> | LineString,
|
|
9
|
+
startDist: number,
|
|
10
|
+
stopDist: number,
|
|
11
|
+
options?: {
|
|
12
|
+
units?: Units;
|
|
13
|
+
}
|
|
14
|
+
): Feature<LineString>;
|
|
15
|
+
|
|
16
|
+
export { lineSliceAlong as default, lineSliceAlong };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.js
|
|
5
|
+
import { bearing } from "@turf/bearing";
|
|
6
|
+
import { distance } from "@turf/distance";
|
|
7
|
+
import { destination } from "@turf/destination";
|
|
8
|
+
import { lineString, isObject } from "@turf/helpers";
|
|
9
|
+
function lineSliceAlong(line, startDist, stopDist, options) {
|
|
10
|
+
options = options || {};
|
|
11
|
+
if (!isObject(options))
|
|
12
|
+
throw new Error("options is invalid");
|
|
13
|
+
var coords;
|
|
14
|
+
var slice = [];
|
|
15
|
+
if (line.type === "Feature")
|
|
16
|
+
coords = line.geometry.coordinates;
|
|
17
|
+
else if (line.type === "LineString")
|
|
18
|
+
coords = line.coordinates;
|
|
19
|
+
else
|
|
20
|
+
throw new Error("input must be a LineString Feature or Geometry");
|
|
21
|
+
var origCoordsLength = coords.length;
|
|
22
|
+
var travelled = 0;
|
|
23
|
+
var overshot, direction, interpolated;
|
|
24
|
+
for (var i = 0; i < coords.length; i++) {
|
|
25
|
+
if (startDist >= travelled && i === coords.length - 1)
|
|
26
|
+
break;
|
|
27
|
+
else if (travelled > startDist && slice.length === 0) {
|
|
28
|
+
overshot = startDist - travelled;
|
|
29
|
+
if (!overshot) {
|
|
30
|
+
slice.push(coords[i]);
|
|
31
|
+
return lineString(slice);
|
|
32
|
+
}
|
|
33
|
+
direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
34
|
+
interpolated = destination(coords[i], overshot, direction, options);
|
|
35
|
+
slice.push(interpolated.geometry.coordinates);
|
|
36
|
+
}
|
|
37
|
+
if (travelled >= stopDist) {
|
|
38
|
+
overshot = stopDist - travelled;
|
|
39
|
+
if (!overshot) {
|
|
40
|
+
slice.push(coords[i]);
|
|
41
|
+
return lineString(slice);
|
|
42
|
+
}
|
|
43
|
+
direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
44
|
+
interpolated = destination(coords[i], overshot, direction, options);
|
|
45
|
+
slice.push(interpolated.geometry.coordinates);
|
|
46
|
+
return lineString(slice);
|
|
47
|
+
}
|
|
48
|
+
if (travelled >= startDist) {
|
|
49
|
+
slice.push(coords[i]);
|
|
50
|
+
}
|
|
51
|
+
if (i === coords.length - 1) {
|
|
52
|
+
return lineString(slice);
|
|
53
|
+
}
|
|
54
|
+
travelled += distance(coords[i], coords[i + 1], options);
|
|
55
|
+
}
|
|
56
|
+
if (travelled < startDist && coords.length === origCoordsLength)
|
|
57
|
+
throw new Error("Start position is beyond line");
|
|
58
|
+
var last = coords[coords.length - 1];
|
|
59
|
+
return lineString([last, last]);
|
|
60
|
+
}
|
|
61
|
+
__name(lineSliceAlong, "lineSliceAlong");
|
|
62
|
+
var turf_line_slice_along_default = lineSliceAlong;
|
|
63
|
+
export {
|
|
64
|
+
turf_line_slice_along_default as default,
|
|
65
|
+
lineSliceAlong
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"sourcesContent":["import { bearing } from \"@turf/bearing\";\nimport { distance } from \"@turf/distance\";\nimport { destination } from \"@turf/destination\";\nimport { lineString, isObject } from \"@turf/helpers\";\n\n/**\n * Takes a {@link LineString|line}, a specified distance along the line to a start {@link Point},\n * and a specified distance along the line to a stop point\n * and returns a subsection of the line in-between those points.\n *\n * This can be useful for extracting only the part of a route between two distances.\n *\n * @name lineSliceAlong\n * @param {Feature<LineString>|LineString} line input line\n * @param {number} startDist distance along the line to starting point\n * @param {number} stopDist distance along the line to ending point\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);\n * var start = 12.5;\n * var stop = 25;\n * var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line, start, stop, sliced]\n */\nfunction lineSliceAlong(line, startDist, stopDist, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n\n var coords;\n var slice = [];\n\n // Validation\n if (line.type === \"Feature\") coords = line.geometry.coordinates;\n else if (line.type === \"LineString\") coords = line.coordinates;\n else throw new Error(\"input must be a LineString Feature or Geometry\");\n var origCoordsLength = coords.length;\n var travelled = 0;\n var overshot, direction, interpolated;\n for (var i = 0; i < coords.length; i++) {\n if (startDist >= travelled && i === coords.length - 1) break;\n else if (travelled > startDist && slice.length === 0) {\n overshot = startDist - travelled;\n if (!overshot) {\n slice.push(coords[i]);\n return lineString(slice);\n }\n direction = bearing(coords[i], coords[i - 1]) - 180;\n interpolated = destination(coords[i], overshot, direction, options);\n slice.push(interpolated.geometry.coordinates);\n }\n\n if (travelled >= stopDist) {\n overshot = stopDist - travelled;\n if (!overshot) {\n slice.push(coords[i]);\n return lineString(slice);\n }\n direction = bearing(coords[i], coords[i - 1]) - 180;\n interpolated = destination(coords[i], overshot, direction, options);\n slice.push(interpolated.geometry.coordinates);\n return lineString(slice);\n }\n\n if (travelled >= startDist) {\n slice.push(coords[i]);\n }\n\n if (i === coords.length - 1) {\n return lineString(slice);\n }\n\n travelled += distance(coords[i], coords[i + 1], options);\n }\n\n if (travelled < startDist && coords.length === origCoordsLength)\n throw new Error(\"Start position is beyond line\");\n\n var last = coords[coords.length - 1];\n return lineString([last, last]);\n}\n\nexport { lineSliceAlong };\nexport default lineSliceAlong;\n"],"mappings":";;;;AAAA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,YAAY,gBAAgB;AAyBrC,SAAS,eAAe,MAAM,WAAW,UAAU,SAAS;AAE1D,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AA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AAI,YAAY,aAAa,OAAO,WAAW;AAC7C,UAAM,IAAI,MAAM,+BAA+B;AAEjD,MAAI,OAAO,OAAO,OAAO,SAAS,CAAC;AACnC,SAAO,WAAW,CAAC,MAAM,IAAI,CAAC;AAChC;AAxDS;AA2DT,IAAO,gCAAQ;","names":[]}
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Units } from "@turf/helpers";
|
|
|
4
4
|
/**
|
|
5
5
|
* http://turfjs.org/docs/
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
declare function lineSliceAlong(
|
|
8
8
|
line: Feature<LineString> | LineString,
|
|
9
9
|
startDist: number,
|
|
10
10
|
stopDist: number,
|
|
@@ -12,3 +12,6 @@ export default function lineSliceAlong(
|
|
|
12
12
|
units?: Units;
|
|
13
13
|
}
|
|
14
14
|
): Feature<LineString>;
|
|
15
|
+
|
|
16
|
+
export { lineSliceAlong };
|
|
17
|
+
export default lineSliceAlong;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/line-slice-along",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf line-slice-along module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,43 +21,50 @@
|
|
|
21
21
|
"along",
|
|
22
22
|
"line-slice"
|
|
23
23
|
],
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"main": "dist/cjs/index.cjs",
|
|
26
|
+
"module": "dist/esm/index.mjs",
|
|
27
|
+
"types": "dist/cjs/index.d.ts",
|
|
26
28
|
"exports": {
|
|
27
29
|
"./package.json": "./package.json",
|
|
28
30
|
".": {
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/esm/index.d.mts",
|
|
33
|
+
"default": "./dist/esm/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/cjs/index.d.ts",
|
|
37
|
+
"default": "./dist/cjs/index.cjs"
|
|
38
|
+
}
|
|
32
39
|
}
|
|
33
40
|
},
|
|
34
|
-
"types": "index.d.ts",
|
|
35
41
|
"sideEffects": false,
|
|
36
42
|
"files": [
|
|
37
43
|
"dist",
|
|
38
44
|
"index.d.ts"
|
|
39
45
|
],
|
|
40
46
|
"scripts": {
|
|
41
|
-
"bench": "tsx bench.
|
|
42
|
-
"build": "
|
|
43
|
-
"docs": "tsx ../../scripts/generate-readmes",
|
|
44
|
-
"test": "npm-run-all test:*",
|
|
45
|
-
"test:tape": "tsx test.
|
|
47
|
+
"bench": "tsx bench.ts",
|
|
48
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
49
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
50
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
51
|
+
"test:tape": "tsx test.ts"
|
|
46
52
|
},
|
|
47
53
|
"devDependencies": {
|
|
48
|
-
"@turf/along": "^7.0.0-alpha.
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"tape": "
|
|
54
|
-
"
|
|
54
|
+
"@turf/along": "^7.0.0-alpha.110+1411d63a7",
|
|
55
|
+
"@turf/length": "^7.0.0-alpha.110+1411d63a7",
|
|
56
|
+
"benchmark": "^2.1.4",
|
|
57
|
+
"load-json-file": "^7.0.1",
|
|
58
|
+
"npm-run-all": "^4.1.5",
|
|
59
|
+
"tape": "^5.7.2",
|
|
60
|
+
"tsup": "^8.0.1",
|
|
61
|
+
"tsx": "^4.6.2"
|
|
55
62
|
},
|
|
56
63
|
"dependencies": {
|
|
57
|
-
"@turf/bearing": "^7.0.0-alpha.
|
|
58
|
-
"@turf/destination": "^7.0.0-alpha.
|
|
59
|
-
"@turf/distance": "^7.0.0-alpha.
|
|
60
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
64
|
+
"@turf/bearing": "^7.0.0-alpha.110+1411d63a7",
|
|
65
|
+
"@turf/destination": "^7.0.0-alpha.110+1411d63a7",
|
|
66
|
+
"@turf/distance": "^7.0.0-alpha.110+1411d63a7",
|
|
67
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7"
|
|
61
68
|
},
|
|
62
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
63
70
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import bearing from '@turf/bearing';
|
|
2
|
-
import distance from '@turf/distance';
|
|
3
|
-
import destination from '@turf/destination';
|
|
4
|
-
import { isObject, lineString } from '@turf/helpers';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Takes a {@link LineString|line}, a specified distance along the line to a start {@link Point},
|
|
8
|
-
* and a specified distance along the line to a stop point
|
|
9
|
-
* and returns a subsection of the line in-between those points.
|
|
10
|
-
*
|
|
11
|
-
* This can be useful for extracting only the part of a route between two distances.
|
|
12
|
-
*
|
|
13
|
-
* @name lineSliceAlong
|
|
14
|
-
* @param {Feature<LineString>|LineString} line input line
|
|
15
|
-
* @param {number} startDist distance along the line to starting point
|
|
16
|
-
* @param {number} stopDist distance along the line to ending point
|
|
17
|
-
* @param {Object} [options={}] Optional parameters
|
|
18
|
-
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
|
|
19
|
-
* @returns {Feature<LineString>} sliced line
|
|
20
|
-
* @example
|
|
21
|
-
* var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);
|
|
22
|
-
* var start = 12.5;
|
|
23
|
-
* var stop = 25;
|
|
24
|
-
* var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});
|
|
25
|
-
*
|
|
26
|
-
* //addToMap
|
|
27
|
-
* var addToMap = [line, start, stop, sliced]
|
|
28
|
-
*/
|
|
29
|
-
function lineSliceAlong(line, startDist, stopDist, options) {
|
|
30
|
-
// Optional parameters
|
|
31
|
-
options = options || {};
|
|
32
|
-
if (!isObject(options)) throw new Error("options is invalid");
|
|
33
|
-
|
|
34
|
-
var coords;
|
|
35
|
-
var slice = [];
|
|
36
|
-
|
|
37
|
-
// Validation
|
|
38
|
-
if (line.type === "Feature") coords = line.geometry.coordinates;
|
|
39
|
-
else if (line.type === "LineString") coords = line.coordinates;
|
|
40
|
-
else throw new Error("input must be a LineString Feature or Geometry");
|
|
41
|
-
var origCoordsLength = coords.length;
|
|
42
|
-
var travelled = 0;
|
|
43
|
-
var overshot, direction, interpolated;
|
|
44
|
-
for (var i = 0; i < coords.length; i++) {
|
|
45
|
-
if (startDist >= travelled && i === coords.length - 1) break;
|
|
46
|
-
else if (travelled > startDist && slice.length === 0) {
|
|
47
|
-
overshot = startDist - travelled;
|
|
48
|
-
if (!overshot) {
|
|
49
|
-
slice.push(coords[i]);
|
|
50
|
-
return lineString(slice);
|
|
51
|
-
}
|
|
52
|
-
direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
53
|
-
interpolated = destination(coords[i], overshot, direction, options);
|
|
54
|
-
slice.push(interpolated.geometry.coordinates);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (travelled >= stopDist) {
|
|
58
|
-
overshot = stopDist - travelled;
|
|
59
|
-
if (!overshot) {
|
|
60
|
-
slice.push(coords[i]);
|
|
61
|
-
return lineString(slice);
|
|
62
|
-
}
|
|
63
|
-
direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
64
|
-
interpolated = destination(coords[i], overshot, direction, options);
|
|
65
|
-
slice.push(interpolated.geometry.coordinates);
|
|
66
|
-
return lineString(slice);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (travelled >= startDist) {
|
|
70
|
-
slice.push(coords[i]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (i === coords.length - 1) {
|
|
74
|
-
return lineString(slice);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
travelled += distance(coords[i], coords[i + 1], options);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (travelled < startDist && coords.length === origCoordsLength)
|
|
81
|
-
throw new Error("Start position is beyond line");
|
|
82
|
-
|
|
83
|
-
var last = coords[coords.length - 1];
|
|
84
|
-
return lineString([last, last]);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export default lineSliceAlong;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var bearing = require('@turf/bearing');
|
|
4
|
-
var distance = require('@turf/distance');
|
|
5
|
-
var destination = require('@turf/destination');
|
|
6
|
-
var helpers = require('@turf/helpers');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var bearing__default = /*#__PURE__*/_interopDefaultLegacy(bearing);
|
|
11
|
-
var distance__default = /*#__PURE__*/_interopDefaultLegacy(distance);
|
|
12
|
-
var destination__default = /*#__PURE__*/_interopDefaultLegacy(destination);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Takes a {@link LineString|line}, a specified distance along the line to a start {@link Point},
|
|
16
|
-
* and a specified distance along the line to a stop point
|
|
17
|
-
* and returns a subsection of the line in-between those points.
|
|
18
|
-
*
|
|
19
|
-
* This can be useful for extracting only the part of a route between two distances.
|
|
20
|
-
*
|
|
21
|
-
* @name lineSliceAlong
|
|
22
|
-
* @param {Feature<LineString>|LineString} line input line
|
|
23
|
-
* @param {number} startDist distance along the line to starting point
|
|
24
|
-
* @param {number} stopDist distance along the line to ending point
|
|
25
|
-
* @param {Object} [options={}] Optional parameters
|
|
26
|
-
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
|
|
27
|
-
* @returns {Feature<LineString>} sliced line
|
|
28
|
-
* @example
|
|
29
|
-
* var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);
|
|
30
|
-
* var start = 12.5;
|
|
31
|
-
* var stop = 25;
|
|
32
|
-
* var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});
|
|
33
|
-
*
|
|
34
|
-
* //addToMap
|
|
35
|
-
* var addToMap = [line, start, stop, sliced]
|
|
36
|
-
*/
|
|
37
|
-
function lineSliceAlong(line, startDist, stopDist, options) {
|
|
38
|
-
// Optional parameters
|
|
39
|
-
options = options || {};
|
|
40
|
-
if (!helpers.isObject(options)) throw new Error("options is invalid");
|
|
41
|
-
|
|
42
|
-
var coords;
|
|
43
|
-
var slice = [];
|
|
44
|
-
|
|
45
|
-
// Validation
|
|
46
|
-
if (line.type === "Feature") coords = line.geometry.coordinates;
|
|
47
|
-
else if (line.type === "LineString") coords = line.coordinates;
|
|
48
|
-
else throw new Error("input must be a LineString Feature or Geometry");
|
|
49
|
-
var origCoordsLength = coords.length;
|
|
50
|
-
var travelled = 0;
|
|
51
|
-
var overshot, direction, interpolated;
|
|
52
|
-
for (var i = 0; i < coords.length; i++) {
|
|
53
|
-
if (startDist >= travelled && i === coords.length - 1) break;
|
|
54
|
-
else if (travelled > startDist && slice.length === 0) {
|
|
55
|
-
overshot = startDist - travelled;
|
|
56
|
-
if (!overshot) {
|
|
57
|
-
slice.push(coords[i]);
|
|
58
|
-
return helpers.lineString(slice);
|
|
59
|
-
}
|
|
60
|
-
direction = bearing__default['default'](coords[i], coords[i - 1]) - 180;
|
|
61
|
-
interpolated = destination__default['default'](coords[i], overshot, direction, options);
|
|
62
|
-
slice.push(interpolated.geometry.coordinates);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (travelled >= stopDist) {
|
|
66
|
-
overshot = stopDist - travelled;
|
|
67
|
-
if (!overshot) {
|
|
68
|
-
slice.push(coords[i]);
|
|
69
|
-
return helpers.lineString(slice);
|
|
70
|
-
}
|
|
71
|
-
direction = bearing__default['default'](coords[i], coords[i - 1]) - 180;
|
|
72
|
-
interpolated = destination__default['default'](coords[i], overshot, direction, options);
|
|
73
|
-
slice.push(interpolated.geometry.coordinates);
|
|
74
|
-
return helpers.lineString(slice);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (travelled >= startDist) {
|
|
78
|
-
slice.push(coords[i]);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (i === coords.length - 1) {
|
|
82
|
-
return helpers.lineString(slice);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
travelled += distance__default['default'](coords[i], coords[i + 1], options);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (travelled < startDist && coords.length === origCoordsLength)
|
|
89
|
-
throw new Error("Start position is beyond line");
|
|
90
|
-
|
|
91
|
-
var last = coords[coords.length - 1];
|
|
92
|
-
return helpers.lineString([last, last]);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
module.exports = lineSliceAlong;
|
|
96
|
-
module.exports.default = lineSliceAlong;
|