1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- "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");
- /**
- * Takes a {@link Point} 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](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature.
- *
- * @name destination
- * @param {Coord} origin starting point
- * @param {number} distance distance from the origin point
- * @param {number} bearing ranging from -180 to 180
- * @param {Object} [options={}] Optional parameters
- * @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians
- * @param {Object} [options.properties={}] Translate properties to Point
- * @returns {Feature<Point>} destination point
- * @example
- * var point = turf.point([-75.343, 39.984]);
- * var distance = 50;
- * var bearing = 90;
- * var options = {units: 'miles'};
- *
- * var destination = turf.destination(point, distance, bearing, options);
- *
- * //addToMap
- * var addToMap = [point, destination]
- * destination.properties['marker-color'] = '#f00';
- * point.properties['marker-color'] = '#0f0';
- */
- function destination(origin, distance, bearing, options) {
- if (options === void 0) { 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);
- // Main
- var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
- Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
- var 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);
- return helpers_1.point([lng, lat], options.properties);
- }
- exports.default = destination;
|