forked from hotdoy/EDbearing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
99 lines (82 loc) · 2.61 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
$(document).ready(function() {
console.log( "ApplicationStart" );
var title = getParameterByName();
if (title) {
document.title = title + ' ― EDbearing';
}
else{
document.title ='EDbearing';
}
$( ".loader-bg" ).fadeOut( 1000, function() {});
// $( ".loader-logo" ).fadeOut( 800, function() {});
});
$( "#latStart, #lonStart, #latDest, #lonDest, #title" ).on('input', function() {
calculateBearing();
});
function calculateBearing(){
var latStart = $("#latStart").val() * Math.PI/180;
var lonStart = $("#lonStart").val() * Math.PI/180;
var latDest = $("#latDest").val() * Math.PI/180;
var lonDest = $("#lonDest").val() * Math.PI/180;
var deltaLon = lonDest - lonStart;
var deltaLat = Math.log(Math.tan(Math.PI/4 + latDest/2)/Math.tan(Math.PI/4 + latStart/2));
var initialBearing = (Math.atan2(deltaLon, deltaLat)) * (180/Math.PI);
if (initialBearing < 0) {
initialBearing = 360 + initialBearing;
}
initialBearing = Math.round(initialBearing);
console.log(initialBearing);
if (isNaN(initialBearing)) {
$("#bearing").html("X");
}
else{
$("#bearing").html(initialBearing);
}
updateURL(
$("#latDest").val(),
$("#lonDest").val(),
$("#title").text()
);
if ($("#title").text()) {
document.title = $("#title").text() + ' ― EDbearing';
}
else{
document.title ='EDbearing';
}
}
function setDestination(lat, lon, title) {
$("#latDest").val(lat);
$("#lonDest").val(lon);
$("#title").text(title);
calculateBearing();
}
function updateURL(lat, lon, title) {
if (lat.length > 0 && lon.length >0) {
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?lat=' + lat + '&lon=' + lon + '&title=' + title;
window.history.pushState({path:newurl},'',newurl);
}
}
else {
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname;
window.history.pushState({path:newurl},'',newurl);
}
}
}
function getParameterByName() {
var lat = RegExp('[?&]' + 'lat' + '=([^&]*)').exec(window.location.search);
var lon = RegExp('[?&]' + 'lon' + '=([^&]*)').exec(window.location.search);
var title = RegExp('[?&]' + 'title' + '=([^&]*)').exec(window.location.search);
setDestination(
lat && decodeURIComponent(lat[1].replace(/\+/g, ' ')),
lon && decodeURIComponent(lon[1].replace(/\+/g, ' ')),
title && decodeURIComponent(title[1].replace(/\+/g, ' '))
);
return title && decodeURIComponent(title[1].replace(/\+/g, ' '));
}
$(".card").click(function() {
$('html, body').animate({
scrollTop: $("#top").offset().top
}, 1000);
});