-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
195 lines (174 loc) · 7.73 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html>
<head>
<title>SecDrone</title>
<script type="text/javascript">
function httpGetAsync(theUrl) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<div id="map" style="width:360px;height:360px"></div>
<img src="/cam.mjpg" style="position:absolute;TOP:0px;LEFT:370px"/>
<br />
<div id="queueconfigurationLink"><h2><a href="/routes.html">Saved Route Configurations</a></h2></div>
<div id="status">STATUS LOADING</div>
<script type="text/javascript">
var map;
var dronelatLng;
var marker = null;
var markers = [];
var lastMarkerRetval = "";
function initMap() {
getLatLon();
var latlng = getLatLngFromString(dronelatLng);
map = new google.maps.Map(document.getElementById('map'), {
center: latlng,
zoom: 19
});
map.addListener('click', function(e) {
placeMarkerAndPanTo(e.latLng, map);
});
}
function placeMarkerAndPanTo(latLng, map) {
console.log(latLng.toString());
var xmlHttp = new XMLHttpRequest({
mozSystem: true
});
xmlHttp.open("GET", "/set/destqueue/" + latLng.toString(), false);
xmlHttp.send(null);
}
function getLatLngFromString(location) {
var latlang = location.replace(/[({})]/g, '');
var latlng = latlang.split(',');
var locate = new google.maps.LatLng(parseFloat(latlng[0]), parseFloat(latlng[1]));
return locate;
}
function getLatLon() {
var xmlHttp = new XMLHttpRequest({
mozSystem: true
});
xmlHttp.open("GET", "/get/latlon", false);
xmlHttp.send(null);
dronelatLng = xmlHttp.responseText;
}
function placeMarker() {
var latlng = getLatLngFromString(dronelatLng);
if(marker == null){
marker = new google.maps.Marker({
position: latlng,
map: map,
icon: 'green_marker.png'
});
} else {
marker.setPosition(latlng);
};
}
function placeDestMarkers() {
var xmlHttp = new XMLHttpRequest({
mozSystem: true
});
xmlHttp.open("GET", "/get/destqueue", false);
xmlHttp.send(null);
var destList = xmlHttp.responseText;
if(destList != lastMarkerRetval){
lastMarkerRetval = destList;
destList = destList.replace(/[({})]/g, '');
destList = destList.split(',');
deleteMarkers();
var j = 0;
for (var i = 0; i < destList.length; i+=2){
addMarker(new google.maps.LatLng(parseFloat(destList[i]), parseFloat(destList[i+1])), j++);
}
}
}
// Adds a marker to the map and push to the array.
function addMarker(location, j) {
var lab = "";
if(j < 10){
lab = j.toString();
} else {
lab = String.fromCharCode(j+87);
}
var marker = new google.maps.Marker({
position: location,
map: map,
label: lab
});
markers.push(marker);
}
// Sets the map on all markers in the array.
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setMapOnAll(null);
}
// Shows any markers currently in the array.
function showMarkers() {
setMapOnAll(map);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
function updateStatus(){
var xmlHttp = new XMLHttpRequest({
mozSystem: true
});
xmlHttp.open("GET", "/status.html", false);
xmlHttp.send(null);
var res = xmlHttp.responseText;
document.getElementById("status").innerHTML = res;
}
function updateMap() {
getLatLon(), placeMarker(), placeDestMarkers(), updateStatus()
}
setInterval(updateMap, 500);
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=$GOOGLEMAPSAPIKEYGOESHERE&callback=initMap&sensor=false" async defer></script>
<button onclick="httpGetAsync('/action/arm')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:0px;"><h2>Arm</h2></button>
<br />
<button onclick="httpGetAsync('/action/disarm')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:120px;"><h2>Disarm</h2></button>
<br />
<button onclick="httpGetAsync('/clear/destqueue')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:240px;"><h2>Clear Waypoints</h2></button>
<br />
<button onclick="httpGetAsync('/action/guided')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:360px;"><h2>Engage Guided</h2></button>
<br />
<button onclick="httpGetAsync('/action/loiter')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:480px;"><h2>Engage Loiter</h2></button>
<br />
<button onclick="httpGetAsync('/set/alt/'.concat(document.getElementById('altitude').value))" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:640px;"><h2>Set Altitude</h2></button>
<br />
<form style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:590px;">
Altitude (m):<br>
<input type="text" name="altitude" id="altitude" value="10">
</form>
<button onclick="httpGetAsync('/set/groundspeed/'.concat(document.getElementById('groundspeed').value))" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:800px;"><h2>Set Groundspeed</h2></button>
<br />
<form style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:750px;">
groundspeed (m/s):<br>
<input type="text" name="groundspeed" id="groundspeed" value="0.1">
</form>
<button onclick="httpGetAsync('/toggle/circuit/')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:920px;"><h2>Toggle Circuit</h2></button>
<form style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:1040px;">
Route name:<br>
<input type="text" name="routename" id="routename" value="">
</form>
<button onclick="httpGetAsync('/set/route/'.concat(document.getElementById('routename').value))" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:1090px;"><h2>Save Route</h2></button>
<button onclick="httpGetAsync('/toggle/altitudeoverride/')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:1210px;"><h2>Node Altitude Override</h2></button>
<form style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:1330px;">
Heading (deg):<br>
<input type="text" name="heading" id="heading" value="">
</form>
<button onclick="httpGetAsync('/set/heading/'.concat(document.getElementById('heading').value))" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:1380px;"><h2>Set Heading</h2></button>
<button onclick="httpGetAsync('/action/takeoff')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:1500px;"><h2>Takeoff</h2></button>
<button onclick="httpGetAsync('/action/rtl')" style="width: 150px;height: 100px;position: absolute; LEFT:1020px; TOP:1620px;"><h2>RTL</h2></button>
</body>
</html>