-
Notifications
You must be signed in to change notification settings - Fork 4
/
console-client.js
85 lines (72 loc) · 2.12 KB
/
console-client.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
// Global state
var last_hb;
var cc = 0;
var colors = ['#ff0000', '#00ff00', '#0000ff', '#ff00ff'];
var color = function() {
return colors[cc++];
}
var plots = {};
var init = function(io) {
last_hb = new Date().getTime();
var piksiCoords = {};
var polylines = {};
var markers = {};
var positioned = false;
var handlers = {
'pos_llh': function(msg) {
var piksi = msg.piksi_id;
piksiCoords[piksi] = piksiCoords[piksi] || [];
piksiCoords[piksi].push(msg.point);
if (!positioned) {
window.map.setCenter(msg.point);
window.map.setZoom(16);
positioned = true;
}
// Set all markers
for (var piksiId in piksiCoords) {
var path = piksiCoords[piksiId];
var pathBegin = path[0];
var pathEnd = path[path.length - 1];
markers[piksiId] = markers[piksiId] || {};
markers[piksiId].begin = markers[piksiId].begin ||
new google.maps.Marker({
map: window.map,
title: "Piksi " + piksiId + " path begin"
});
markers[piksiId].begin.setPosition(pathBegin);
markers[piksiId].end = markers[piksiId].end ||
new google.maps.Marker({
map: window.map,
title: "Piksi " + piksiId + " path end"
});
markers[piksiId].end.setPosition(pathEnd);
}
// Set all polylines
for (var piksiId in piksiCoords) {
var path = piksiCoords[piksiId];
polylines[piksiId] = polylines[piksiId] ||
new google.maps.Polyline({
map: window.map,
geodesic: true,
strokeColor: colors[piksiId],
strokeOpacity: 1.0,
strokeWeight: 2
});
polylines[piksiId].setPath(path);
}
},
'heartbeat': function(msg) {
var now = new Date().getTime();
last_hb = now;
}
}
console.log('HELLO');
io.input.add(handlers);
}
// TODO animate heartbeat, other messages?
var animate = function() {
var now = new Date().getTime();
var delta = Math.pow(1/2, (now - last_hb) / 3000);
window.requestAnimationFrame(animate);
}
module.exports = init;