@turf/length 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 +6 -5
- package/dist/es/index.js +3 -4
- package/dist/js/index.d.ts +2 -1
- package/dist/js/index.js +6 -9
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
Takes a [GeoJSON][1] and measures its length in the specified units, [(Multi)Point][2]'s distance are ignored.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- `options.units` **[string][7]** can be degrees, radians, miles, or kilometers (optional, default `kilometers`)
|
|
11
|
+
* `geojson` **[Feature][3]<([LineString][4] | [MultiLineString][5])>** GeoJSON to measure
|
|
12
|
+
* `options` **[Object][6]** Optional parameters (optional, default `{}`)
|
|
14
13
|
|
|
15
|
-
**
|
|
14
|
+
* `options.units` **[string][7]** can be degrees, radians, miles, or kilometers (optional, default `kilometers`)
|
|
15
|
+
|
|
16
|
+
### Examples
|
|
16
17
|
|
|
17
18
|
```javascript
|
|
18
19
|
var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);
|
package/dist/es/index.js
CHANGED
|
@@ -16,11 +16,10 @@ import { segmentReduce } from "@turf/meta";
|
|
|
16
16
|
* var addToMap = [line];
|
|
17
17
|
* line.properties.distance = length;
|
|
18
18
|
*/
|
|
19
|
-
export default function length(geojson, options) {
|
|
20
|
-
if (options === void 0) { options = {}; }
|
|
19
|
+
export default function length(geojson, options = {}) {
|
|
21
20
|
// Calculate distance from 2-vertex line segments
|
|
22
|
-
return segmentReduce(geojson,
|
|
23
|
-
|
|
21
|
+
return segmentReduce(geojson, (previousValue, segment) => {
|
|
22
|
+
const coords = segment.geometry.coordinates;
|
|
24
23
|
return previousValue + distance(coords[0], coords[1], options);
|
|
25
24
|
}, 0);
|
|
26
25
|
}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Feature, FeatureCollection, GeometryCollection
|
|
1
|
+
import { Feature, FeatureCollection, GeometryCollection } from "geojson";
|
|
2
|
+
import { Units } from "@turf/helpers";
|
|
2
3
|
/**
|
|
3
4
|
* Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.
|
|
4
5
|
*
|
package/dist/js/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
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
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
|
|
5
|
+
const meta_1 = require("@turf/meta");
|
|
8
6
|
/**
|
|
9
7
|
* Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.
|
|
10
8
|
*
|
|
@@ -21,11 +19,10 @@ var meta_1 = require("@turf/meta");
|
|
|
21
19
|
* var addToMap = [line];
|
|
22
20
|
* line.properties.distance = length;
|
|
23
21
|
*/
|
|
24
|
-
function length(geojson, options) {
|
|
25
|
-
if (options === void 0) { options = {}; }
|
|
22
|
+
function length(geojson, options = {}) {
|
|
26
23
|
// Calculate distance from 2-vertex line segments
|
|
27
|
-
return meta_1.segmentReduce(geojson,
|
|
28
|
-
|
|
24
|
+
return meta_1.segmentReduce(geojson, (previousValue, segment) => {
|
|
25
|
+
const coords = segment.geometry.coordinates;
|
|
29
26
|
return previousValue + distance_1.default(coords[0], coords[1], options);
|
|
30
27
|
}, 0);
|
|
31
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/length",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf length module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -63,9 +63,10 @@
|
|
|
63
63
|
"write-json-file": "*"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@turf/distance": "^
|
|
67
|
-
"@turf/helpers": "^
|
|
68
|
-
"@turf/meta": "^
|
|
66
|
+
"@turf/distance": "^7.0.0-alpha.0",
|
|
67
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
68
|
+
"@turf/meta": "^7.0.0-alpha.0",
|
|
69
|
+
"tslib": "^2.3.0"
|
|
69
70
|
},
|
|
70
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
71
72
|
}
|