@turf/destination 6.5.0 → 7.0.0-alpha.1
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 +13 -10
- package/dist/es/index.js +10 -13
- package/dist/js/index.d.ts +3 -2
- package/dist/js/index.js +12 -15
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -4,18 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
## destination
|
|
6
6
|
|
|
7
|
-
Takes a [Point][1] and calculates the location of a destination point given a distance in
|
|
7
|
+
Takes a [Point][1] and calculates the location of a destination point given a distance in
|
|
8
|
+
degrees, radians, miles, or kilometers; and bearing in degrees.
|
|
9
|
+
This uses the [Haversine formula][2] to account for global curvature.
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
### Parameters
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- `options.units` **[string][6]** miles, kilometers, degrees, or radians (optional, default `'kilometers'`)
|
|
16
|
-
- `options.properties` **[Object][5]** Translate properties to Point (optional, default `{}`)
|
|
13
|
+
* `origin` **[Coord][3]** starting point
|
|
14
|
+
* `distance` **[number][4]** distance from the origin point
|
|
15
|
+
* `bearing` **[number][4]** ranging from -180 to 180
|
|
16
|
+
* `options` **[Object][5]** Optional parameters (optional, default `{}`)
|
|
17
17
|
|
|
18
|
-
**
|
|
18
|
+
* `options.units` **[string][6]** miles, kilometers, degrees, or radians (optional, default `'kilometers'`)
|
|
19
|
+
* `options.properties` **[Object][5]** Translate properties to Point (optional, default `{}`)
|
|
20
|
+
|
|
21
|
+
### Examples
|
|
19
22
|
|
|
20
23
|
```javascript
|
|
21
24
|
var point = turf.point([-75.343, 39.984]);
|
|
@@ -31,7 +34,7 @@ destination.properties['marker-color'] = '#f00';
|
|
|
31
34
|
point.properties['marker-color'] = '#0f0';
|
|
32
35
|
```
|
|
33
36
|
|
|
34
|
-
Returns **[Feature][7]
|
|
37
|
+
Returns **[Feature][7]<[Point][8]>** destination point
|
|
35
38
|
|
|
36
39
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
37
40
|
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// http://en.wikipedia.org/wiki/Haversine_formula
|
|
2
|
-
// http://www.movable-type.co.uk/scripts/latlong.html
|
|
3
1
|
import { degreesToRadians, lengthToRadians, point, radiansToDegrees, } from "@turf/helpers";
|
|
4
2
|
import { getCoord } from "@turf/invariant";
|
|
5
3
|
/**
|
|
@@ -28,20 +26,19 @@ import { getCoord } from "@turf/invariant";
|
|
|
28
26
|
* destination.properties['marker-color'] = '#f00';
|
|
29
27
|
* point.properties['marker-color'] = '#0f0';
|
|
30
28
|
*/
|
|
31
|
-
export default function destination(origin, distance, bearing, options) {
|
|
32
|
-
if (options === void 0) { options = {}; }
|
|
29
|
+
export default function destination(origin, distance, bearing, options = {}) {
|
|
33
30
|
// Handle input
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const coordinates1 = getCoord(origin);
|
|
32
|
+
const longitude1 = degreesToRadians(coordinates1[0]);
|
|
33
|
+
const latitude1 = degreesToRadians(coordinates1[1]);
|
|
34
|
+
const bearingRad = degreesToRadians(bearing);
|
|
35
|
+
const radians = lengthToRadians(distance, options.units);
|
|
39
36
|
// Main
|
|
40
|
-
|
|
37
|
+
const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
|
|
41
38
|
Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
|
|
42
|
-
|
|
39
|
+
const longitude2 = longitude1 +
|
|
43
40
|
Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1), Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const lng = radiansToDegrees(longitude2);
|
|
42
|
+
const lat = radiansToDegrees(latitude2);
|
|
46
43
|
return point([lng, lat], options.properties);
|
|
47
44
|
}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Feature, Point, GeoJsonProperties } from "geojson";
|
|
2
|
+
import { Coord, Units } from "@turf/helpers";
|
|
2
3
|
/**
|
|
3
4
|
* Takes a {@link Point} and calculates the location of a destination point given a distance in
|
|
4
5
|
* degrees, radians, miles, or kilometers; and bearing in degrees.
|
|
@@ -25,7 +26,7 @@ import { Coord, Feature, Point, Properties, Units } from "@turf/helpers";
|
|
|
25
26
|
* destination.properties['marker-color'] = '#f00';
|
|
26
27
|
* point.properties['marker-color'] = '#0f0';
|
|
27
28
|
*/
|
|
28
|
-
export default function destination<P =
|
|
29
|
+
export default function destination<P = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: {
|
|
29
30
|
units?: Units;
|
|
30
31
|
properties?: P;
|
|
31
32
|
}): Feature<Point, P>;
|
package/dist/js/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var helpers_1 = require("@turf/helpers");
|
|
6
|
-
var invariant_1 = require("@turf/invariant");
|
|
3
|
+
const helpers_1 = require("@turf/helpers");
|
|
4
|
+
const invariant_1 = require("@turf/invariant");
|
|
7
5
|
/**
|
|
8
6
|
* Takes a {@link Point} and calculates the location of a destination point given a distance in
|
|
9
7
|
* degrees, radians, miles, or kilometers; and bearing in degrees.
|
|
@@ -30,21 +28,20 @@ var invariant_1 = require("@turf/invariant");
|
|
|
30
28
|
* destination.properties['marker-color'] = '#f00';
|
|
31
29
|
* point.properties['marker-color'] = '#0f0';
|
|
32
30
|
*/
|
|
33
|
-
function destination(origin, distance, bearing, options) {
|
|
34
|
-
if (options === void 0) { options = {}; }
|
|
31
|
+
function destination(origin, distance, bearing, options = {}) {
|
|
35
32
|
// Handle input
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const coordinates1 = invariant_1.getCoord(origin);
|
|
34
|
+
const longitude1 = helpers_1.degreesToRadians(coordinates1[0]);
|
|
35
|
+
const latitude1 = helpers_1.degreesToRadians(coordinates1[1]);
|
|
36
|
+
const bearingRad = helpers_1.degreesToRadians(bearing);
|
|
37
|
+
const radians = helpers_1.lengthToRadians(distance, options.units);
|
|
41
38
|
// Main
|
|
42
|
-
|
|
39
|
+
const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
|
|
43
40
|
Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
|
|
44
|
-
|
|
41
|
+
const longitude2 = longitude1 +
|
|
45
42
|
Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1), Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const lng = helpers_1.radiansToDegrees(longitude2);
|
|
44
|
+
const lat = helpers_1.radiansToDegrees(latitude2);
|
|
48
45
|
return helpers_1.point([lng, lat], options.properties);
|
|
49
46
|
}
|
|
50
47
|
exports.default = destination;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/destination",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "turf destination module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
"./package.json": "./package.json",
|
|
31
31
|
".": {
|
|
32
|
+
"types": "./dist/js/index.d.ts",
|
|
32
33
|
"import": "./dist/es/index.js",
|
|
33
34
|
"require": "./dist/js/index.js"
|
|
34
35
|
}
|
|
@@ -39,30 +40,31 @@
|
|
|
39
40
|
"dist"
|
|
40
41
|
],
|
|
41
42
|
"scripts": {
|
|
42
|
-
"bench": "
|
|
43
|
+
"bench": "tsx bench.js",
|
|
43
44
|
"build": "npm-run-all build:*",
|
|
44
45
|
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
|
|
45
46
|
"build:js": "tsc",
|
|
46
|
-
"docs": "
|
|
47
|
+
"docs": "tsx ../../scripts/generate-readmes",
|
|
47
48
|
"test": "npm-run-all test:*",
|
|
48
|
-
"test:tape": "
|
|
49
|
+
"test:tape": "tsx test.js"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@turf/truncate": "^
|
|
52
|
+
"@turf/truncate": "^7.0.0-alpha.1",
|
|
52
53
|
"@types/tape": "*",
|
|
53
54
|
"benchmark": "*",
|
|
54
55
|
"glob": "*",
|
|
55
56
|
"load-json-file": "*",
|
|
56
57
|
"npm-run-all": "*",
|
|
57
58
|
"tape": "*",
|
|
58
|
-
"ts-node": "*",
|
|
59
59
|
"tslint": "*",
|
|
60
|
+
"tsx": "*",
|
|
60
61
|
"typescript": "*",
|
|
61
62
|
"write-json-file": "*"
|
|
62
63
|
},
|
|
63
64
|
"dependencies": {
|
|
64
|
-
"@turf/helpers": "^
|
|
65
|
-
"@turf/invariant": "^
|
|
65
|
+
"@turf/helpers": "^7.0.0-alpha.1",
|
|
66
|
+
"@turf/invariant": "^7.0.0-alpha.1",
|
|
67
|
+
"tslib": "^2.3.0"
|
|
66
68
|
},
|
|
67
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
68
70
|
}
|