-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted turf-midpoint to Typescript (#2645)
* Converted turf-midpoint to Typescript.
- Loading branch information
1 parent
2786f69
commit 6012328
Showing
7 changed files
with
68 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Feature, Point } from "geojson"; | ||
import { bearing } from "@turf/bearing"; | ||
import { destination } from "@turf/destination"; | ||
import { distance } from "@turf/distance"; | ||
import { Coord } from "@turf/helpers"; | ||
|
||
/** | ||
* Takes two points and returns a point midway between them. The midpoint is | ||
* calculated geodesically, meaning the curvature of the earth is taken into | ||
* account. | ||
* | ||
* @name midpoint | ||
* @param {Coord} point1 first point | ||
* @param {Coord} point2 second point | ||
* @returns {Feature<Point>} a point midway between `pt1` and `pt2` | ||
* @example | ||
* const point1 = turf.point([144.834823, -37.771257]); | ||
* const point2 = turf.point([145.14244, -37.830937]); | ||
* | ||
* const midpoint = turf.midpoint(point1, point2); | ||
* | ||
* //addToMap | ||
* const addToMap = [point1, point2, midpoint]; | ||
* midpoint.properties['marker-color'] = '#f00'; | ||
*/ | ||
function midpoint(point1: Coord, point2: Coord): Feature<Point> { | ||
const dist = distance(point1, point2); | ||
const heading = bearing(point1, point2); | ||
const midpoint = destination(point1, dist / 2, heading); | ||
|
||
return midpoint; | ||
} | ||
|
||
export { midpoint }; | ||
export default midpoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.