|
| 1 | +var query = { |
| 2 | + timeframe: 'last_5_seconds', |
| 3 | + interval: 'second', |
| 4 | + dimensions: ['location.lat', 'location.lon', 'tag'], |
| 5 | + metrics: ['metric'], |
| 6 | + collection: 'geo', |
| 7 | + realtime: { |
| 8 | + enabled: true, |
| 9 | + interval: state.get('config.refresh.duration') |
| 10 | + } |
| 11 | +}; |
| 12 | +var lastQueryUUID = ''; |
1 | 13 | joola.on('ready', function () {
|
2 | 14 | console.log('Joola SDK ready, version', joola.VERSION);
|
3 |
| - var query = { |
4 |
| - timeframe: 'last_5_seconds', |
5 |
| - interval: 'second', |
6 |
| - dimensions: ['location.lat', 'location.lon', 'tag'], |
7 |
| - metrics: ['metric'], |
8 |
| - collection: 'geo', |
9 |
| - realtime: { |
10 |
| - enabled: false, |
11 |
| - interval: state.get('config.refresh.duration') |
| 15 | + |
| 16 | + joola.on('query_updated', function () { |
| 17 | + if (lastQueryUUID && lastQueryUUID.length > 0){ |
| 18 | + console.log('stopping',lastQueryUUID); |
| 19 | + joola.query.stop(lastQueryUUID); |
12 | 20 | }
|
13 |
| - }; |
14 |
| - /*new joola.viz.Table({ |
15 |
| - container: '#table', |
16 |
| - query: query, |
17 |
| - pickers: { |
18 |
| - primary: { |
19 |
| - enabled: false |
20 |
| - }, |
21 |
| - add_dimension: { |
22 |
| - enabled: true, |
23 |
| - caption: 'Add dimension...', |
24 |
| - allowRemove: false, |
25 |
| - allowSelect: false |
26 |
| - }, |
27 |
| - add_metric: { |
28 |
| - enabled: true, |
29 |
| - caption: 'Add metric...', |
30 |
| - allowRemove: false, |
31 |
| - allowSelect: false |
32 |
| - } |
33 |
| - }, |
34 |
| - enter: function (data) { |
35 |
| - var addMarker = function (point) { |
36 |
| - var marker = new google.maps.Marker({ |
37 |
| - position: new google.maps.LatLng(point.lat, point.lon), |
38 |
| - map: map |
39 |
| - }); |
40 |
| - var chHtml = "<h4>Event details</h4><div>"; |
41 |
| - Object.keys(point).forEach(function (key) { |
42 |
| - var elem = point[key]; |
43 |
| - if (typeof elem !== 'object') |
44 |
| - chHtml += '<strong>' + key + ':</strong> ' + elem + '<br/>'; |
45 |
| - }); |
46 |
| - var chInfoWindow = new google.maps.InfoWindow({ |
47 |
| - content: chHtml, |
48 |
| - maxWidth: 250 |
49 |
| - }); |
50 |
| - google.maps.event.addListener(marker, 'click', function () { |
51 |
| - chInfoWindow.open(map, marker); |
52 |
| - }); |
53 |
| - setTimeout(function () { |
54 |
| - marker.setMap(null); |
55 |
| - }, state.get('config.tail.duration')); |
56 |
| - }; |
| 21 | + |
| 22 | + joola.query.fetch(query, function (err, docs) { |
| 23 | + if (err) |
| 24 | + throw err; |
| 25 | + |
| 26 | + lastQueryUUID = docs[0].query.realtimeUID; |
57 | 27 |
|
| 28 | + var data = docs[0].documents; |
58 | 29 | data.forEach(function (point) {
|
59 |
| - point = point.raw; |
60 | 30 | point.lat = point.location_lat;
|
61 | 31 | point.lon = point.location_lon;
|
62 |
| - //addMarker(point); |
63 | 32 |
|
64 |
| - var marker = L.marker([point.lat, point.lon], { |
65 |
| - icon: L.mapbox.marker.icon({ |
66 |
| - 'marker-color': '#f86767' |
67 |
| - }) |
| 33 | + var marker = L.marker(new L.LatLng(point.lat, point.lon), { |
| 34 | + icon: L.mapbox.marker.icon({'marker-color': '#f86767', 'marker-size': 'small'}), |
| 35 | + data: point |
68 | 36 | });
|
69 |
| - //marker.addTo(map); |
| 37 | + markers.addLayer(marker); |
| 38 | + }); |
| 39 | + markers.eachLayer(function (marker) { |
| 40 | + //heat.addLatLng(marker.getLatLng()); |
70 | 41 |
|
71 | 42 | });
|
72 |
| - // L.mapbox.featureLayer(geojson).addTo(map); |
73 |
| - } |
| 43 | + }); |
74 | 44 | });
|
75 |
| -*/ |
| 45 | + setTimeout(function () { |
| 46 | + joola.emit('query_updated'); |
| 47 | + }, 500); |
| 48 | + |
| 49 | + /*new joola.viz.Table({ |
| 50 | + container: '#table', |
| 51 | + query: query, |
| 52 | + pickers: { |
| 53 | + primary: { |
| 54 | + enabled: false |
| 55 | + }, |
| 56 | + add_dimension: { |
| 57 | + enabled: true, |
| 58 | + caption: 'Add dimension...', |
| 59 | + allowRemove: false, |
| 60 | + allowSelect: false |
| 61 | + }, |
| 62 | + add_metric: { |
| 63 | + enabled: true, |
| 64 | + caption: 'Add metric...', |
| 65 | + allowRemove: false, |
| 66 | + allowSelect: false |
| 67 | + } |
| 68 | + }, |
| 69 | + enter: function (data) { |
| 70 | + var addMarker = function (point) { |
| 71 | + var marker = new google.maps.Marker({ |
| 72 | + position: new google.maps.LatLng(point.lat, point.lon), |
| 73 | + map: map |
| 74 | + }); |
| 75 | + var chHtml = "<h4>Event details</h4><div>"; |
| 76 | + Object.keys(point).forEach(function (key) { |
| 77 | + var elem = point[key]; |
| 78 | + if (typeof elem !== 'object') |
| 79 | + chHtml += '<strong>' + key + ':</strong> ' + elem + '<br/>'; |
| 80 | + }); |
| 81 | + var chInfoWindow = new google.maps.InfoWindow({ |
| 82 | + content: chHtml, |
| 83 | + maxWidth: 250 |
| 84 | + }); |
| 85 | + google.maps.event.addListener(marker, 'click', function () { |
| 86 | + chInfoWindow.open(map, marker); |
| 87 | + }); |
| 88 | + setTimeout(function () { |
| 89 | + marker.setMap(null); |
| 90 | + }, state.get('config.tail.duration')); |
| 91 | + }; |
| 92 | +
|
| 93 | + data.forEach(function (point) { |
| 94 | + point = point.raw; |
| 95 | + point.lat = point.location_lat; |
| 96 | + point.lon = point.location_lon; |
| 97 | + //addMarker(point); |
| 98 | +
|
| 99 | + var marker = L.marker([point.lat, point.lon], { |
| 100 | + icon: L.mapbox.marker.icon({ |
| 101 | + 'marker-color': '#f86767' |
| 102 | + }) |
| 103 | + }); |
| 104 | + //marker.addTo(map); |
| 105 | +
|
| 106 | + }); |
| 107 | + // L.mapbox.featureLayer(geojson).addTo(map); |
| 108 | + } |
| 109 | + }); |
| 110 | + */ |
76 | 111 | /*
|
77 | 112 | joola.on('polygon_added', function (marker) {
|
78 | 113 | var _query = joola.common.extend(query, {
|
@@ -121,7 +156,8 @@ joola.on('ready', function () {
|
121 | 156 | joola.io.socket.on('event', function (collection, data) {
|
122 | 157 | if (['geo'].indexOf(collection) === -1)
|
123 | 158 | return;
|
124 |
| - EPSData.push(data.length); |
| 159 | + EPSData.shift(); |
| 160 | + EPSData.push({timestamp: new Date(), metric: 0, total: data.length}); |
125 | 161 | data.forEach(function (point) {
|
126 | 162 | point.lat = point.location.lat;
|
127 | 163 | point.lon = point.location.lon;
|
|
0 commit comments