UNPKG

2.06 kBMarkdownView Raw
1# @turf/bearing
2
3# bearing
4
5Takes two [points](http://geojson.org/geojson-spec.html#point) and finds the geographic bearing between them,
6i.e. the angle measured in degrees from the north line (0 degrees)
7
8**Parameters**
9
10- `start` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** starting Point
11- `end` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** ending Point
12- `final` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** calculates the final bearing if true (optional, default `false`)
13
14**Examples**
15
16```javascript
17var point1 = {
18 "type": "Feature",
19 "properties": {},
20 "geometry": {
21 "type": "Point",
22 "coordinates": [-75.343, 39.984]
23 }
24};
25var point2 = {
26 "type": "Feature",
27 "properties": {},
28 "geometry": {
29 "type": "Point",
30 "coordinates": [-75.534, 39.123]
31 }
32};
33
34var bearing = turf.bearing(point1, point2);
35
36//addToMap
37var addToMap = [point1, point2]
38point1.properties['marker-color'] = '#f00'
39point2.properties['marker-color'] = '#0f0'
40point1.properties.bearing = bearing
41```
42
43Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
44
45<!-- This file is automatically generated. Please don't edit it directly:
46if you find an error, edit the source file (likely index.js), and re-run
47./scripts/generate-readmes in the turf project. -->
48
49---
50
51This module is part of the [Turfjs project](http://turfjs.org/), an open source
52module collection dedicated to geographic algorithms. It is maintained in the
53[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
54PRs and issues.
55
56### Installation
57
58Install this module individually:
59
60```sh
61$ npm install @turf/bearing
62```
63
64Or install the Turf module that includes it as a function:
65
66```sh
67$ npm install @turf/turf
68```