|
16 | 16 | $.event.trigger(myevent);
|
17 | 17 | });
|
18 | 18 |
|
19 |
| - //var timer = setInterval(function(){$.event.trigger(myevent);}, 2000); |
| 19 | + var timer = setInterval(function(){$.event.trigger(myevent);}, 100); |
20 | 20 |
|
21 | 21 | $( document ).on('myevent', function (e) {
|
22 |
| - console.log(socketparseddata); |
| 22 | + |
23 | 23 | $.each($("#tree").jstree("get_checked",true),function(){
|
24 | 24 |
|
25 | 25 | // Get the node data
|
26 |
| - var mydata = this.data, action = null; |
| 26 | + var mydata = this.data, action = null, style = null; |
| 27 | + |
27 | 28 | // Get node action
|
28 | 29 | for (var i in mydata) {
|
29 | 30 |
|
|
43 | 44 | }
|
44 | 45 | }
|
45 | 46 | }
|
| 47 | + |
| 48 | + // Get node style |
| 49 | + for (var i in mydata) { |
| 50 | + |
| 51 | + // Just in case some other code touched my collection object, check hasOwnProperty! |
| 52 | + if (mydata.hasOwnProperty(i)) { |
| 53 | + if (mydata[i]['key'] === "styles") { |
| 54 | + var styles = mydata[i]['value']; |
| 55 | + for (var j in styles) { |
| 56 | + if (styles.hasOwnProperty(j)) { |
| 57 | + if (1 === styles[j]['isdefault']) { |
| 58 | + style = styles[j]; |
| 59 | + break; |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + break; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
46 | 67 |
|
47 | 68 | if (action) {
|
48 |
| - // Call S().parsedata |
| 69 | + |
| 70 | + // Parse the data. |
49 | 71 | S().parsedata(action, mydata, socketdata, templates, socketparseddata);
|
| 72 | + |
| 73 | + switch (action.text) { |
| 74 | + |
| 75 | + case "map_mapbox_using_leaflet" : |
| 76 | + |
| 77 | + // Style and render |
| 78 | + if (style) { |
| 79 | + |
| 80 | + var styleobj = {}; |
| 81 | + S().getstyle(style,styleobj); |
| 82 | + |
| 83 | + // Render |
| 84 | + if (markers[style.id]){ |
| 85 | + map.removeLayer(markers[style.id]); |
| 86 | + markers[style.id].update(markers[style.id]); |
| 87 | + |
| 88 | + } |
| 89 | + markers[style.id] = L.marker([socketparseddata["0f307d6a-e251-4e98-b29e-49ad4bacc514"].lat, socketparseddata["0f307d6a-e251-4e98-b29e-49ad4bacc514"].lon], {icon: styleobj[style.id]}).addTo(map); |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + break; |
| 94 | + |
| 95 | + default: |
| 96 | + |
| 97 | + throw new Error("Unknown action"); |
| 98 | + |
| 99 | + } |
50 | 100 | }
|
51 | 101 |
|
52 | 102 | });
|
|
94 | 144 |
|
95 | 145 | // Just in case some other code touched my collection object, check hasOwnProperty!
|
96 | 146 | if (mydata.hasOwnProperty(i)) {
|
97 |
| - |
98 | 147 | if (mydata[i]['key'] === "actions") {
|
99 |
| - |
100 | 148 | var actions = mydata[i]['value'];
|
101 |
| - |
102 | 149 | for (var j in actions) {
|
103 |
| - |
104 | 150 | if (actions.hasOwnProperty(j)) {
|
105 |
| - |
106 | 151 | if (1 === actions[j]['isdefault']) {
|
107 |
| - |
108 | 152 | action = actions[j];
|
109 |
| - |
110 | 153 | break;
|
111 | 154 | }
|
112 | 155 | }
|
|
117 | 160 | }
|
118 | 161 |
|
119 | 162 | if (action) {
|
120 |
| - |
121 |
| - switch (action.text) { |
122 |
| - |
123 |
| - case "map_mapbox_using_leaflet" : |
124 |
| - |
125 |
| - /** |
126 |
| - * |
127 |
| - * S().gettemplate will get the template(s) and place them in templates. |
128 |
| - * S().getdata will open the sockets for the actions and place them in sockets. |
129 |
| - * S().getdata will also place the last raw incoming message into socketdata. |
130 |
| - * |
131 |
| - */ |
132 |
| - S().gettemplate(action, mydata, templates) |
133 |
| - .getdata(action, mydata, sockets, socketdata); |
134 |
| - |
135 |
| - |
136 |
| - // Now that socketdata contains the last message for the socket, what do we want to do with it? |
137 |
| - // Say, GPS feed is coming in with time, lat, lon, alt, and socketdata contains the last such data record |
138 |
| - // Say, messages have been requested for 12:00:00 - 13:00:00 and are coming in |
139 |
| - // I just want to act on these incoming messages every 5 seconds. |
140 |
| - // |
141 |
| - |
142 |
| - break; |
143 |
| - |
144 |
| - default: |
145 |
| - |
146 |
| - throw new Error("Unknown action"); |
147 |
| - |
148 |
| - } |
| 163 | + /** |
| 164 | + * |
| 165 | + * S().gettemplate will get the template(s) and place them in templates. |
| 166 | + * S().getdata will open the sockets for the actions and place them in sockets. |
| 167 | + * S().getdata will also place the last raw incoming message into socketdata. |
| 168 | + * |
| 169 | + */ |
| 170 | + S().gettemplate(action, mydata, templates) |
| 171 | + .getdata(action, mydata, sockets, socketdata); |
149 | 172 |
|
150 | 173 | }
|
151 | 174 |
|
|
0 commit comments