-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
133 lines (103 loc) · 3.51 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
<!DOCTYPE html>
<html>
<head>
<title>Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
// https://www.xarg.org/2018/04/how-to-plot-a-covariance-error-ellipse/
function getErrorEllipse(mu, Sigma, p) {
p = p || 0.95;
var s = -2 * Math.log(1 - p);
var a = Sigma[0][0] + 0.0000000000001;
var b = Sigma[0][1] + 0.0000000000001;
var c = Sigma[1][0] + 0.0000000000001;
var d = Sigma[1][1] + 0.0000000000001;
var tmp = Math.sqrt((a - d) * (a - d) + 4 * b * c);
var V = [
[-(tmp - a + d) / (2 * c), (tmp + a - d) / (2 * c)],
[1, 1]
];
var sqrtD = [
Math.sqrt(s * (a + d - tmp) / 2),
Math.sqrt(s * (a + d + tmp) / 2)
];
var norm1 = Math.hypot(V[0][0], 1);
var norm2 = Math.hypot(V[0][1], 1);
V[0][0] /= norm1;
V[1][0] /= norm1;
V[0][1] /= norm2;
V[1][1] /= norm2;
var ndx = sqrtD[0] < sqrtD[1] ? 1 : 0;
var x1 = mu[0] + V[0][ndx] * sqrtD[ndx];
var y1 = mu[1] + V[1][ndx] * sqrtD[ndx];
var x2 = mu[0] + V[0][1 - ndx] * sqrtD[1 - ndx];
var y2 = mu[1] + V[1][1 - ndx] * sqrtD[1 - ndx];
var x = mu[0];
var y = mu[1];
var radiusX = Math.hypot(x1 - mu[0], y1 - mu[1]);
var radiusY = Math.hypot(x2 - mu[0], y2 - mu[1]);
var rotation = Math.atan2(y1 - mu[1], x1 - mu[0]);
var pts = [];
for (var i = 0; i <= 50; i++) {
var a = i / 50 * Math.PI * 2 + Math.random();
pts.push({
lat: x + radiusX * Math.cos(a + rotation),
lng: y + radiusY * Math.sin(a)
});
}
return pts;
}
function initMap() {
var gstate = {
lat: 0,
lng: 0
};
var map = new google.maps.Map(document.getElementById('map'), {
center: gstate,
zoom: 15
});
var marker = new google.maps.Marker({
position: gstate,
map: map,
title: 'Your Position'
});
var ellipse = new google.maps.Polygon({
paths: [],
strokeColor: 'black',
strokeOpacity: 0.9,
strokeWeight: 1,
fillColor: 'red',
fillOpacity: 0.3,
map: map
});
socket.on('position', function (state) {
gstate.lat = state.position.pos[0];
gstate.lng = state.position.pos[1];
var path = getErrorEllipse(state.position.pos, state.position.cov);
ellipse.setPaths(path);
map.setCenter(gstate);
marker.setPosition(gstate);
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyADf2Ss5DEZdZMFEJ0f8fmi1KcYRZMYLZI&callback=initMap"
async defer></script>
</body>
</html>