-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
153 lines (135 loc) · 6.1 KB
/
index.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="/css/leaflet.css" />
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://matomo.axvigs.com/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '3']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<script src="js/leaflet/leaflet.js"></script>
<script src="js/leaflet/leaflet-knn.js"></script>
<script src="js/LoadData.js"></script>
<script src="js/moment.js"></script>
<script>
function start() {
document.getElementById("status").innerHTML = "Loading data";
loadAllData()
.then(function() {
getLocation();
});
}
function getLocation() {
document.getElementById("status").innerHTML = "Getting location";
var options = {
enableHighAccuracy: true,
timeout: Infinity,
maximumAge: 0
};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError, options);
}
else {
document.getElementById("status").innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
document.getElementById("status").innerHTML = "Running calculations";
var gj = L.geoJson(data);
// 0.3 miles from AICW 6
//var currentLocation = L.latLng(36.7960833, -76.2932567);
var currentLocation = L.latLng(position.coords.latitude, position.coords.longitude);
document.getElementById("status").innerHTML = "Running calculations...";
var nearest = leafletKnn(gj).nearest(currentLocation, 1);
document.getElementById("status").innerHTML = "Setting position values";
document.getElementById("latitude").innerHTML = position.coords.latitude.toFixed(5);
document.getElementById("longitude").innerHTML = position.coords.longitude.toFixed(5);
document.getElementById("status").innerHTML = "Setting distance value";
var point2 = L.latLng(nearest[0].lat, nearest[0].lon)
var distance = currentLocation.distanceTo(point2);
document.getElementById("distance").innerHTML = (distance / 1852).toFixed(2) + " nm";
document.getElementById("status").innerHTML = "Setting accuracy value";
document.getElementById("accuracy").innerHTML = (position.coords.accuracy / 1852).toFixed(3) + " nm";
document.getElementById("status").innerHTML = "Setting nearest point";
if (position.coords.accuracy > 1000) {
document.getElementById("status").innerHTML = "Setting nearest point (inaccurate)";
document.getElementById("nearest").innerHTML = nearest[0].layer.feature.properties.name + " maybe";
}
else {
document.getElementById("status").innerHTML = "Setting nearest point (accurate)";
document.getElementById("nearest").innerHTML = nearest[0].layer.feature.properties.name;
}
document.getElementById("status").innerHTML = "Getting current time";
var now = new moment();
document.getElementById("status").innerHTML = "Setting updated value";
document.getElementById("status").innerHTML = "Updated at " + now.format("HH:mm:ss");
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
document.getElementById("status").innerHTML = "User denied the request for geolocation."
break;
case error.POSITION_UNAVAILABLE:
document.getElementById("status").innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
document.getElementById("status").innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
document.getElementById("status").innerHTML = "An unknown error occurred."
break;
default:
document.getElementById("status").innerHTML = "A really unknown error occurred."
}
}
</script>
<body onload="start()">
<nav class="menu">
<ul>
<li>Main</li>
<li><a href="about.html">About</a></li>
<li><a href="data.html">Data</a></li>
<li>v1.10</li>
</ul>
</nav>
<div style='border: 3px solid black; border-radius: 10px; text-align: center; display: inline-block; padding: 10px'>
<h2>Nearest marker</h2>
<h1 id="nearest"></h1>
</div>
<table>
<tr>
<td>Status:</td>
<td id="status"></td>
</tr>
<tr>
<td>My latitude:</td>
<td id="latitude"></td>
</tr>
<tr>
<td>My longitude:</td>
<td id="longitude"></td>
</tr>
<tr>
<td>My position accuracy:</td>
<td id="accuracy"></td>
</tr>
<tr>
<td>Distance to nearest mile mark:</td>
<td id="distance"></td>
</tr>
</table>
<div id="mapid"></div>
</body>
</html>