@turf/destination
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
@@ -1,3 +0,1 @@ | ||
// http://en.wikipedia.org/wiki/Haversine_formula | ||
// http://www.movable-type.co.uk/scripts/latlong.html | ||
import { degreesToRadians, lengthToRadians, point, radiansToDegrees, } from "@turf/helpers"; | ||
@@ -31,18 +29,17 @@ import { getCoord } from "@turf/invariant"; | ||
*/ | ||
export default function destination(origin, distance, bearing, options) { | ||
if (options === void 0) { options = {}; } | ||
export default function destination(origin, distance, bearing, options = {}) { | ||
// Handle input | ||
var coordinates1 = getCoord(origin); | ||
var longitude1 = degreesToRadians(coordinates1[0]); | ||
var latitude1 = degreesToRadians(coordinates1[1]); | ||
var bearingRad = degreesToRadians(bearing); | ||
var radians = lengthToRadians(distance, options.units); | ||
const coordinates1 = getCoord(origin); | ||
const longitude1 = degreesToRadians(coordinates1[0]); | ||
const latitude1 = degreesToRadians(coordinates1[1]); | ||
const bearingRad = degreesToRadians(bearing); | ||
const radians = lengthToRadians(distance, options.units); | ||
// Main | ||
var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) + | ||
const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) + | ||
Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)); | ||
var longitude2 = longitude1 + | ||
const longitude2 = longitude1 + | ||
Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1), Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)); | ||
var lng = radiansToDegrees(longitude2); | ||
var lat = radiansToDegrees(latitude2); | ||
const lng = radiansToDegrees(longitude2); | ||
const lat = radiansToDegrees(latitude2); | ||
return point([lng, lat], options.properties); | ||
} |
@@ -1,2 +0,3 @@ | ||
import { Coord, Feature, Point, Properties, Units } from "@turf/helpers"; | ||
import { Feature, Point, GeoJsonProperties } from "geojson"; | ||
import { Coord, Units } from "@turf/helpers"; | ||
/** | ||
@@ -28,5 +29,5 @@ * Takes a {@link Point} and calculates the location of a destination point given a distance in | ||
*/ | ||
export default function destination<P = Properties>(origin: Coord, distance: number, bearing: number, options?: { | ||
export default function destination<P = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: { | ||
units?: Units; | ||
properties?: P; | ||
}): Feature<Point, P>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// http://en.wikipedia.org/wiki/Haversine_formula | ||
// http://www.movable-type.co.uk/scripts/latlong.html | ||
var helpers_1 = require("@turf/helpers"); | ||
var invariant_1 = require("@turf/invariant"); | ||
const helpers_1 = require("@turf/helpers"); | ||
const invariant_1 = require("@turf/invariant"); | ||
/** | ||
@@ -33,19 +31,18 @@ * Takes a {@link Point} and calculates the location of a destination point given a distance in | ||
*/ | ||
function destination(origin, distance, bearing, options) { | ||
if (options === void 0) { options = {}; } | ||
function destination(origin, distance, bearing, options = {}) { | ||
// Handle input | ||
var coordinates1 = invariant_1.getCoord(origin); | ||
var longitude1 = helpers_1.degreesToRadians(coordinates1[0]); | ||
var latitude1 = helpers_1.degreesToRadians(coordinates1[1]); | ||
var bearingRad = helpers_1.degreesToRadians(bearing); | ||
var radians = helpers_1.lengthToRadians(distance, options.units); | ||
const coordinates1 = invariant_1.getCoord(origin); | ||
const longitude1 = helpers_1.degreesToRadians(coordinates1[0]); | ||
const latitude1 = helpers_1.degreesToRadians(coordinates1[1]); | ||
const bearingRad = helpers_1.degreesToRadians(bearing); | ||
const radians = helpers_1.lengthToRadians(distance, options.units); | ||
// Main | ||
var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) + | ||
const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) + | ||
Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)); | ||
var longitude2 = longitude1 + | ||
const longitude2 = longitude1 + | ||
Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1), Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)); | ||
var lng = helpers_1.radiansToDegrees(longitude2); | ||
var lat = helpers_1.radiansToDegrees(latitude2); | ||
const lng = helpers_1.radiansToDegrees(longitude2); | ||
const lat = helpers_1.radiansToDegrees(latitude2); | ||
return helpers_1.point([lng, lat], options.properties); | ||
} | ||
exports.default = destination; |
{ | ||
"name": "@turf/destination", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf destination module", | ||
@@ -51,3 +51,3 @@ "author": "Turf Authors", | ||
"devDependencies": { | ||
"@turf/truncate": "^6.5.0", | ||
"@turf/truncate": "^7.0.0-alpha.0", | ||
"@types/tape": "*", | ||
@@ -65,6 +65,7 @@ "benchmark": "*", | ||
"dependencies": { | ||
"@turf/helpers": "^6.5.0", | ||
"@turf/invariant": "^6.5.0" | ||
"@turf/helpers": "^7.0.0-alpha.0", | ||
"@turf/invariant": "^7.0.0-alpha.0", | ||
"tslib": "^2.3.0" | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
@@ -7,15 +7,18 @@ # @turf/destination | ||
Takes a [Point][1] and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and bearing in degrees. This uses the [Haversine formula][2] to account for global curvature. | ||
Takes a [Point][1] and calculates the location of a destination point given a distance in | ||
degrees, radians, miles, or kilometers; and bearing in degrees. | ||
This uses the [Haversine formula][2] to account for global curvature. | ||
**Parameters** | ||
### Parameters | ||
- `origin` **[Coord][3]** starting point | ||
- `distance` **[number][4]** distance from the origin point | ||
- `bearing` **[number][4]** ranging from -180 to 180 | ||
- `options` **[Object][5]** Optional parameters (optional, default `{}`) | ||
- `options.units` **[string][6]** miles, kilometers, degrees, or radians (optional, default `'kilometers'`) | ||
- `options.properties` **[Object][5]** Translate properties to Point (optional, default `{}`) | ||
* `origin` **[Coord][3]** starting point | ||
* `distance` **[number][4]** distance from the origin point | ||
* `bearing` **[number][4]** ranging from -180 to 180 | ||
* `options` **[Object][5]** Optional parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.units` **[string][6]** miles, kilometers, degrees, or radians (optional, default `'kilometers'`) | ||
* `options.properties` **[Object][5]** Translate properties to Point (optional, default `{}`) | ||
### Examples | ||
```javascript | ||
@@ -35,3 +38,3 @@ var point = turf.point([-75.343, 39.984]); | ||
Returns **[Feature][7]<[Point][8]>** destination point | ||
Returns **[Feature][7]<[Point][8]>** destination point | ||
@@ -38,0 +41,0 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.2 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79
10895
3
123
1
+ Addedtslib@^2.3.0
+ Added@turf/helpers@7.1.0(transitive)
+ Added@turf/invariant@7.1.0(transitive)
+ Added@types/geojson@7946.0.14(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/helpers@6.5.0(transitive)
- Removed@turf/invariant@6.5.0(transitive)
Updated@turf/helpers@^7.0.0-alpha.0