Created
February 19, 2020 17:20
-
-
Save ArrayIterator/ddf2e90a246fad462ddec17c1584b517 to your computer and use it in GitHub Desktop.
Add Bearing (Rotation Based) to Leaflet LatLng
This file contains hidden or 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
| /** | |
| * @see https://github.com/gregallensworth/Leaflet/blob/master/LatLng_Bearings.js | |
| */ | |
| L.LatLng.prototype.bearingTo = function(LatLng) { | |
| let d2r = Math.PI / 180; | |
| let r2d = 180 / Math.PI; | |
| let lat1 = this.lat * d2r; | |
| let lat2 = LatLng.lat * d2r; | |
| let dLon = (LatLng.lng-this.lng) * d2r; | |
| let y = Math.sin(dLon) * Math.cos(lat2); | |
| let x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon); | |
| return (parseInt( Math.atan2(y, x) * r2d ) + 360 ) % 360; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment