1 | # @turf/bearing
|
2 |
|
3 | # bearing
|
4 |
|
5 | Takes two [points](http://geojson.org/geojson-spec.html#point) and finds the geographic bearing between them,
|
6 | i.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
|
17 | var point1 = {
|
18 | "type": "Feature",
|
19 | "properties": {},
|
20 | "geometry": {
|
21 | "type": "Point",
|
22 | "coordinates": [-75.343, 39.984]
|
23 | }
|
24 | };
|
25 | var point2 = {
|
26 | "type": "Feature",
|
27 | "properties": {},
|
28 | "geometry": {
|
29 | "type": "Point",
|
30 | "coordinates": [-75.534, 39.123]
|
31 | }
|
32 | };
|
33 |
|
34 | var bearing = turf.bearing(point1, point2);
|
35 |
|
36 | //addToMap
|
37 | var addToMap = [point1, point2]
|
38 | point1.properties['marker-color'] = '#f00'
|
39 | point2.properties['marker-color'] = '#0f0'
|
40 | point1.properties.bearing = bearing
|
41 | ```
|
42 |
|
43 | Returns **[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 |
|
46 | if 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 |
|
51 | This module is part of the [Turfjs project](http://turfjs.org/), an open source
|
52 | module collection dedicated to geographic algorithms. It is maintained in the
|
53 | [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
54 | PRs and issues.
|
55 |
|
56 | ### Installation
|
57 |
|
58 | Install this module individually:
|
59 |
|
60 | ```sh
|
61 | $ npm install @turf/bearing
|
62 | ```
|
63 |
|
64 | Or install the Turf module that includes it as a function:
|
65 |
|
66 | ```sh
|
67 | $ npm install @turf/turf
|
68 | ```
|