-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.html
358 lines (308 loc) · 9.94 KB
/
home.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
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<!DOCTYPE html>
<html>
<head>
<title>Realtime Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBy9hZSnE48aRbGD8zQAHRrtlOsk_H27BU&sensor=false"></script>
<script>
var map;
var wsURL = "ws://91.115.91.115:80/sock";
var circleHash = {};
function initialize() {
var NY = new google.maps.LatLng(40.760837, -73.981847);
var mapOptions = {
zoom: 13,
center: NY//,
//mapTypeId: google.maps.MapTypeId.TERRAIN
}
map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
var sock = new ReconnectingWebSocket(wsURL);
}
// reference: https://github.com/joewalnes/reconnecting-websocket/
function ReconnectingWebSocket(url, protocols) {
protocols = protocols || [];
// These can be altered by calling code.
this.debug = false;
this.reconnectInterval = 1000;
this.timeoutInterval = 2000;
var self = this;
var ws;
var forcedClose = false;
var timedOut = false;
this.url = url;
this.protocols = protocols;
this.readyState = WebSocket.CONNECTING;
this.URL = url; // Public API
this.onopen = function(event) {
};
this.onclose = function(event) {
};
this.onconnecting = function(event) {
};
this.onmessage = function(event) {
receiveData(event.data);
};
this.onerror = function(event) {
};
function connect(reconnectAttempt) {
ws = new WebSocket(url, protocols);
self.onconnecting();
if (self.debug || ReconnectingWebSocket.debugAll) {
console.debug('ReconnectingWebSocket', 'attempt-connect', url);
}
var localWs = ws;
var timeout = setTimeout(function() {
if (self.debug || ReconnectingWebSocket.debugAll) {
console.debug('ReconnectingWebSocket', 'connection-timeout', url);
}
timedOut = true;
localWs.close();
timedOut = false;
}, self.timeoutInterval);
ws.onopen = function(event) {
clearTimeout(timeout);
if (self.debug || ReconnectingWebSocket.debugAll) {
console.debug('ReconnectingWebSocket', 'onopen', url);
}
self.readyState = WebSocket.OPEN;
reconnectAttempt = false;
self.onopen(event);
};
ws.onclose = function(event) {
clearTimeout(timeout);
ws = null;
if (forcedClose) {
self.readyState = WebSocket.CLOSED;
self.onclose(event);
} else {
self.readyState = WebSocket.CONNECTING;
self.onconnecting();
if (!reconnectAttempt && !timedOut) {
if (self.debug || ReconnectingWebSocket.debugAll) {
console.debug('ReconnectingWebSocket', 'onclose', url);
}
self.onclose(event);
}
setTimeout(function() {
connect(true);
}, self.reconnectInterval);
}
};
ws.onmessage = function(event) {
if (self.debug || ReconnectingWebSocket.debugAll) {
console.debug('ReconnectingWebSocket', 'onmessage', url, event.data);
}
self.onmessage(event);
};
ws.onerror = function(event) {
if (self.debug || ReconnectingWebSocket.debugAll) {
console.debug('ReconnectingWebSocket', 'onerror', url, event);
}
self.onerror(event);
};
}
connect(url);
this.send = function(data) {
if (ws) {
if (self.debug || ReconnectingWebSocket.debugAll) {
console.debug('ReconnectingWebSocket', 'send', url, data);
}
return ws.send(data);
} else {
throw 'INVALID_STATE_ERR : Pausing to reconnect websocket';
}
};
this.close = function() {
forcedClose = true;
if (ws) {
ws.close();
}
};
/**
* Additional public API method to refresh the connection if still open (close, re-open).
* For example, if the app suspects bad data / missed heart beats, it can try to refresh.
*/
this.refresh = function() {
if (ws) {
ws.close();
}
};
}
/**
* Setting this to true is the equivalent of setting all instances of ReconnectingWebSocket.debug to true.
*/
ReconnectingWebSocket.debugAll = false;
function receiveData(data) {
if(data.length > 0) {
var string_split = data.split(",");
var myLatlng = new google.maps.LatLng(parseFloat(string_split[1]), parseFloat(string_split[2]));
//drawCircle(myLatlng, string_split[3], string_split[0]);
drawCustomMarker(myLatlng, string_split[3], string_split[0])
}
}
function drawSimppleMarker(location, text) {
var infowindow = new google.maps.InfoWindow({
content: text,
maxWidth: 200
});
var marker = new google.maps.Marker({
position: location,
map: map,
title: 'Some location'
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
function drawCustomMarker(location, text, colorIndex) {
var infowindow = new google.maps.InfoWindow({
content: text,
maxWidth: 200
});
// Marker sizes are expressed as a Size of X,Y
// where the origin of the image (0,0) is located
// in the top left of the image.
// Origins, anchor positions and coordinates of the marker
// increase in the X direction to the right and in
// the Y direction down.
var image;
if (colorIndex == 0) {
image = {
url: '/images/twitter-pointer1.png',
// This marker is 20 pixels wide by 32 pixels tall.
size: new google.maps.Size(27, 32),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 32)
};
} else if(colorIndex == 1) {
image = {
url: '/images/instagram-pointer1.png',
// This marker is 20 pixels wide by 32 pixels tall.
size: new google.maps.Size(27, 32),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 32)
};
} else if(colorIndex == 2) {
image = {
url: '/images/flickr-pointer1.png',
// This marker is 20 pixels wide by 32 pixels tall.
size: new google.maps.Size(27, 32),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 32)
};
}
// Shapes define the clickable region of the icon.
// The type defines an HTML <area> element 'poly' which
// traces out a polygon as a series of X,Y points. The final
// coordinate closes the poly by connecting to the first
// coordinate.
var shape = {
coords: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
var marker = new google.maps.Marker({
position: location,
map: map,
icon: image,
shape: shape,
title: 'Some location',
zIndex: 0
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
function HandleInfoWindow(latLng, content) {
var infoWindow = new google.maps.InfoWindow({
maxWidth: 420
});
infoWindow.setContent(content);
infoWindow.setPosition(latLng);
infoWindow.open(map);
}
function drawCircle(location, text, colorIndex) {
var color = "";
if(colorIndex == 0) {
color = "#FF0000";
}
else if(colorIndex == 1) {
color = "#0000FF";
}
else if(colorIndex == 2) {
color = "#00FF00";
}
// Add a Circle overlay to the map.
var circle = new google.maps.Circle({
center: location,
radius: 40,//50,//100,
strokeColor: color,
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: color,
fillOpacity: 0.35,
map: map,
title: 'Some location'
});
var unix = new Date().getTime();
var key = location.toString() + unix;
circleHash[key] = circle;
google.maps.event.addListener(circle, 'rightclick', function() {
removeCircle(key);
});
google.maps.event.addListener(circle, 'click', function() {
HandleInfoWindow(location, text)
});
}
function makePolygon() {
polygonCoords = [
new google.maps.LatLng('40.703286','-74.017739'),
new google.maps.LatLng('40.735551','-74.010487'),
new google.maps.LatLng('40.752979','-74.007397'),
new google.maps.LatLng('40.815891', '-73.960540'),
new google.maps.LatLng('40.800966', '-73.929169'),
new google.maps.LatLng('40.783921','-73.94145'),
new google.maps.LatLng('40.776122','-73.941965'),
new google.maps.LatLng('40.739974','-73.972864'),
new google.maps.LatLng('40.729308','-73.971663'),
new google.maps.LatLng('40.711614','-73.978014'),
new google.maps.LatLng('40.706148','-74.00239'),
new google.maps.LatLng('40.702114','-74.009671'),
new google.maps.LatLng('40.701203','-74.015164')
]
var polygon = new google.maps.Polygon({
paths: polygonCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
});
polygon.setMap(map);
}
function removeCircle(location) {
console.debug('removeCircle called')
circleHash[location].setMap(null);
delete circleHash[location];
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>