-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrackerMap.html
More file actions
327 lines (275 loc) · 9.84 KB
/
trackerMap.html
File metadata and controls
327 lines (275 loc) · 9.84 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0,user-scalable=no" />
<meta charset="utf-8"/>
<style type="text/css">
html {
height: 100%;
}
body {
height: 58vh;
margin: 0;
padding: 0;
}
#map-canvas {
height: 100%;
opacity:1.00;
/*
foreground: linear-gradient(
rgba(200, 200, 200, 0.5),
rgba(200, 200, 200, 0.5)
);
*/
}
#black-canvas { /*map is overlayed on top of this black canvas, and made transparent*/
height: 100%;
background-color: black;
}
/*
.wrapper {
height: 100%;
background-color: black;
}
*/
/*.overlay{
background-color: rgba(200, 200, 200, 0.7);
top: 0;
left: 0;
width: 100%;
height: 100%;
position: relative;
z-index: 1;
}
.css_selector {
background: linear-gradient(
rgba(20, 20, 20, 0.5),
rgba(20, 20, 20, 0.5)
);
}
foreground: linear-gradient(
rgba(20, 20, 20, 0.5),
rgba(20, 20, 20, 0.5)
);*/
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?
key=AIzaSyALt375cV7B_ZO_HCHtKM6G79sJsyI0zmU
&libraries=drawing,geometry"></script>
</head>
<body ondragstart="return false">
<label>Date: <label id="timeBox"></label>, Flight Time: <label id="flightTimeBox" style="font-weight:bold"></label> Minutes</label><br>
<label>Location: <label id="flightLocationBox" style="font-weight:bold"></label></label></label><br>
<label>Speed: <label id="flightSpeedBox" style="font-weight:bold"></label> mph</label><br>
<label>Direction: <label id="flightDirectionBox" style="font-weight:bold"></label></label></label><br>
<label>Altitude: <label id="flightAltitudeBox" style="font-weight:bold"></label> ft</label></label>
<h3>Restart Simulation:</h3>
<div id="latitudeText" class="generalInputField">Latitude<span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span>
</div>
<form id="latitudeForm" class="inputValue" onsubmit="initLocation(); return false">
<input id="latitudeField" class="inputBorder numberField" type="number" step="any" name="latitudeInput" value="37.374712"/>
</form>
<div id="longitudeText" class="generalInputField">Longitude<span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span>
</div>
<form id="longitudeForm" class="inputValue" onsubmit="initLocation(); return false">
<input id="longitudeField" class="inputBorder numberField" type="number" step="any" name="longitudeInput" value="-120.577858"/>
</form>
<br>
<button type="button" id="startButton" onclick="initLocation(); return false">Start Program</button>
<br>
<div id="black-canvas"><div id ="map-canvas"></div></div>
<input class="w3-button w3-black" type="button" value="Input Button">
<script type="text/javascript" >
// Initialize map variables
var map;
var currentTime = 0.0;
//var currentDate = new Date();
var startTime = new Date();
var marker;
// Starting position of map
var latitude = 37.374712;
var longitude = -120.577858;
// starting drone parameters
var speed = 0.0;
var altitude = 0.0;
// Current and previous position of drone
var droneLatLng = new google.maps.LatLng (latitude, longitude);
var lastDroneLatLng = droneLatLng;
var lastPositionUpdateTime = 0.0;
var direction = ""; // "NW", "NE", "SE", "SW"
// Fog of war grid
var grid = [[]];
var gridLength = 100;
var gridResolution = 0.00001;
// File reading
/*
var file = IO.getFile("data/20170327_70119.gdat");
var inStream = IO.newInputStream(file, "text");
*/
/*
var file = new FileReader();
var lines = file.readAsText("data/20170327_70119.gdat").split("/\r?\n/g");
console.log(lines);
*/
//var inStream = //IO.newInputStream(file, "text");
function initGrid()
{
var topEdge = latitude + ((gridLength / 2) * gridResolution);
var leftEdge = longitude - ((gridLength / 4) * gridResolution) + gridLength * gridResolution;
for (var i = 0; i < gridLength; i++) {
grid[i] = [];
for (var j = 0; j < gridLength; j++) {
grid [i][j] = new google.maps.Rectangle({
strokeColor: '#3F3F3F',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: '#3F3F3F',
fillOpacity: 0.80,
map: map,
bounds: {
north: topEdge - (i * gridResolution),
south: topEdge - (i * gridResolution) - gridResolution, //topEdge + ((j + gridLength / 4) * gridResolution) - gridResolution,
east: leftEdge - (j * gridResolution), //leftEdge + ((i + gridLength / 4) * gridResolution),
west: leftEdge - (j * gridResolution) - gridResolution //leftEdge + ((i + gridLength / 4) * gridResolution) - gridResolution
}
});
}
}
}
function initialize()
{
console.log('Initializing Map!');
// Add map
var mapOptions =
{
// center: new google.maps.LatLng(37.374712, -120.577858),
center: new google.maps.LatLng(latitude, longitude),
zoom: 19,
mapTypeId: google.maps.MapTypeId.SATELLITE,
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
map.setTilt(0);
var drawingManager = new google.maps.drawing.DrawingManager(
{
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: ['marker', 'circle', 'polygon', 'polyline', 'rectangle']
},
markerOptions: {icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'},
circleOptions: {
fillColor: 'rgba(0, 98, 255, 0.46)',
fillOpacity: 1,
strokeWeight: 5,
clickable: false,
editable: true,
zIndex: 1
}
});
drawingManager.setMap(map);
// Add event listener
google.maps.event.addListener(map, 'zoom_changed',
function()
{
//alert(map.getZoom());
}
);
// Add marker
marker = new google.maps.Marker(
{
position: new google.maps.LatLng(37.374712, -120.577858),
map: map,
title: "Marker A",
});
google.maps.event.addListener(marker, 'click', function()
{
map.panTo(marker.getPosition());
});
marker.setMap(map);
initGrid();
}
google.maps.event.addDomListener(window, 'load', initialize);
function updateLocation(lat,lon){
//latitude = lat;
//longitude = lon;
//map.setCenter (latitude, longitude, 0);
lastDroneLatLng = droneLatLng;
droneLatLng = new google.maps.LatLng (lat, lon);
var distance = google.maps.geometry.spherical.computeDistanceBetween(lastDroneLatLng, droneLatLng); // compute distance between previous and current location in meters
speed = (2236.94 * distance)/(Date.now() - lastPositionUpdateTime); // time is in milliseconds, so multiply by 1000 to get seconds, so speed is in meters per second. Then multiply by 2.23694 to get miles per hour
lastPositionUpdateTime = Date.now();
if (droneLatLng.lat() > lastDroneLatLng.lat()) {
direction = "N";
} else {
direction = "S";
}
if (droneLatLng.lng() > lastDroneLatLng.lng()) {
direction = direction + "E";
} else {
direction = direction + "W";
}
//marker.setPosition (latitude, longitude, 0);
marker.setPosition (droneLatLng);
console.log ("Updated location to (" + latitude + ", " + longitude + ")\n");
};
function circlePoint(time)
{
var radius = 0.0005;
var x = Math.cos(time/10000) * radius;
var y = Math.sin(time/10000) * radius;
updateLocation (latitude + x, longitude + y);
altitude = 50*Math.sin(time/10000) + 100;
//return {lat:window.lat + y, lng:window.lng + x};
};
/*
function readFileData()
{
var lineStr = inStream.readLine();
// When reaching end of file
if (!inStream.available()) {
// go back to top of file
return; // do nothing
}
var params = lineStr.split();
var fileLat = parseFloat(params[6]); // drone longitude is 7the column
var fileLon = parseFloat(params[7]); // drone latitude is 8the column
var fileAlt = parseFloat(params[8]); // drone altitude is 9the column
altitude = fileAlt;
updateLocation(fileLat, fileLon);
}
*/
function updateGrid() {
var y = (droneLatLng.lat() - latitude) / gridResolution;
var x = (droneLatLng.lng() - longitude) / gridResolution;
grid[x][y].fillColor = '#3F3F3F';
}
function updateMap () {
currentTime = Date.now() - startTime; //currentTime + 0.010;
circlePoint (currentTime);
//readFileData();
updateFlightInfoText();
// Update map grid
updateGrid();
}
function initLocation(){
latitude = Number (document.forms[0].latitudeInput.value);
longitude = Number(document.forms[1].longitudeInput.value);
initialize();
}
function updateFlightInfoText() {
//document.getElementById("latitudeField").value = 'latitude';
//document.getElementById("longitudeField").value = 'longitude';
//var TimeBox = document.getElementById("timeBox");
//TimeBox.setAttribute('value', "hi");
document.getElementById("timeBox").innerHTML = new Date().toGMTString(); //Math.round((Date.now() - startTime)/1000); //(Date.now() - startTime.get)/1000;
document.getElementById("flightTimeBox").innerHTML = Math.round((Date.now() - startTime)/60000)
document.getElementById("flightSpeedBox").innerHTML = speed;
document.getElementById("flightAltitudeBox").innerHTML = altitude;
document.getElementById("flightDirectionBox").innerHTML = direction;
document.getElementById("flightLocationBox").innerHTML = Math.abs(droneLatLng.lat()) + (droneLatLng.lat() > 0? " N" : " S") + ", " + Math.abs(droneLatLng.lng()) + (droneLatLng.lng() > 0? " E" : " W");
}
setInterval ("updateMap ()", 500);
</script>
</body>
</html>