2
2
< html >
3
3
< head >
4
4
< link rel ="stylesheet " href ="css/styles.css ">
5
+ < link rel ="stylesheet " href ="/css/leaflet.css " />
5
6
6
7
<!-- Matomo -->
7
8
< script type ="text/javascript ">
20
21
<!-- End Matomo Code -->
21
22
22
23
</ head >
23
- < script src ='https://npmcdn.com/@turf/turf/turf.min.js '> </ script >
24
+ < script src ="js/leaflet/leaflet.js "> </ script >
25
+ < script src ="js/leaflet/leaflet-knn.js "> </ script >
24
26
< script src ="js/LoadData.js "> </ script >
25
27
< script src ="js/moment.js "> </ script >
26
28
< script >
50
52
}
51
53
52
54
function showPosition ( position ) {
53
-
54
55
document . getElementById ( "status" ) . innerHTML = "Running calculations" ;
55
56
56
- var currentLocation = turf . point ( [ position . coords . longitude , position . coords . latitude ] ) ;
57
-
57
+ var gj = L . geoJson ( data ) ;
58
+
58
59
// 0.3 miles from AICW 6
59
- //var currentLocation = turf.point([-76.2932567,36.7960833]);
60
+ //var currentLocation = L.latLng(36.7960833, -76.2932567);
61
+ var currentLocation = L . latLng ( position . coords . latitude , position . coords . longitude ) ;
60
62
61
63
document . getElementById ( "status" ) . innerHTML = "Running calculations..." ;
62
- var nearest = turf . nearestPoint ( currentLocation , data ) ;
64
+ var nearest = leafletKnn ( gj ) . nearest ( currentLocation , 1 ) ;
63
65
64
66
document . getElementById ( "status" ) . innerHTML = "Setting position values" ;
65
67
document . getElementById ( "latitude" ) . innerHTML = position . coords . latitude . toFixed ( 5 ) ;
66
68
document . getElementById ( "longitude" ) . innerHTML = position . coords . longitude . toFixed ( 5 ) ;
67
69
68
70
document . getElementById ( "status" ) . innerHTML = "Setting distance value" ;
69
- //document.getElementById("distance").innerHTML = (nearest.properties.distanceToPoint / 1.852).toFixed(2) + " nautical miles";
71
+ var point2 = L . latLng ( nearest [ 0 ] . lat , nearest [ 0 ] . lon )
72
+ var distance = currentLocation . distanceTo ( point2 ) ;
73
+
74
+ document . getElementById ( "distance" ) . innerHTML = ( distance / 1852 ) . toFixed ( 2 ) + " nm" ;
70
75
71
76
document . getElementById ( "status" ) . innerHTML = "Setting accuracy value" ;
72
- document . getElementById ( "accuracy" ) . innerHTML = position . coords . accuracy . toFixed ( 0 ) + " meters " ;
77
+ document . getElementById ( "accuracy" ) . innerHTML = ( position . coords . accuracy / 1852 ) . toFixed ( 3 ) + " nm " ;
73
78
74
79
75
80
document . getElementById ( "status" ) . innerHTML = "Setting nearest point" ;
76
81
if ( position . coords . accuracy > 1000 ) {
77
82
document . getElementById ( "status" ) . innerHTML = "Setting nearest point (inaccurate)" ;
78
- document . getElementById ( "nearest" ) . innerHTML = nearest . properties . name + " maybe" ;
83
+ document . getElementById ( "nearest" ) . innerHTML = nearest [ 0 ] . layer . feature . properties . name + " maybe" ;
79
84
}
80
85
else {
81
86
document . getElementById ( "status" ) . innerHTML = "Setting nearest point (accurate)" ;
82
- document . getElementById ( "nearest" ) . innerHTML = nearest . properties . name ;
87
+ document . getElementById ( "nearest" ) . innerHTML = nearest [ 0 ] . layer . feature . properties . name ;
83
88
}
84
89
document . getElementById ( "status" ) . innerHTML = "Getting current time" ;
85
90
var now = new moment ( ) ;
@@ -143,5 +148,6 @@ <h1 id="nearest"></h1>
143
148
< td id ="distance "> </ td >
144
149
</ tr >
145
150
</ table >
151
+ < div id ="mapid "> </ div >
146
152
</ body >
147
153
</ html >
0 commit comments