Skip to content

Commit 8387890

Browse files
committed
sQueryGetStyle - Initial Commit
1 parent dedfd36 commit 8387890

File tree

3 files changed

+106
-40
lines changed

3 files changed

+106
-40
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
*
5+
* Software distributed under the License is distributed on an "AS IS" basis,
6+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7+
* for the specific language governing rights and limitations under the License.
8+
*
9+
* The Initial Developer is Terravolv, Inc. Portions created by the Initial
10+
* Developer are Copyright (C) 2014-2015 the Initial Developer. All Rights Reserved.
11+
*/
12+
13+
/**
14+
* @param {string} xmllocationdescriptor - The location template XML
15+
* @returns {Object} objLocationDetails - Returns the location data record format
16+
* @public
17+
*/
18+
S.fn.getstyle = function (styledef, styleobject){
19+
20+
switch (styledef.text) {
21+
22+
case "leaflet_marker_icon_image" :
23+
24+
// create the leaflet marker icon object and save it into styleobject
25+
styleobject[styledef.id] = L.icon({
26+
iconUrl : styledef.iconurl,
27+
iconSize : [styledef.iconsize]
28+
});
29+
30+
break;
31+
32+
default:
33+
34+
throw new Error("Unknown style defintion");
35+
36+
}
37+
38+
return this;
39+
40+
}; // getstyle

sensorhubdemoclientnew/js/dataitems.js

+63-40
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
$.event.trigger(myevent);
1717
});
1818

19-
//var timer = setInterval(function(){$.event.trigger(myevent);}, 2000);
19+
var timer = setInterval(function(){$.event.trigger(myevent);}, 100);
2020

2121
$( document ).on('myevent', function (e) {
22-
console.log(socketparseddata);
22+
2323
$.each($("#tree").jstree("get_checked",true),function(){
2424

2525
// Get the node data
26-
var mydata = this.data, action = null;
26+
var mydata = this.data, action = null, style = null;
27+
2728
// Get node action
2829
for (var i in mydata) {
2930

@@ -43,10 +44,59 @@
4344
}
4445
}
4546
}
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+
}
4667

4768
if (action) {
48-
// Call S().parsedata
69+
70+
// Parse the data.
4971
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+
}
50100
}
51101

52102
});
@@ -94,19 +144,12 @@
94144

95145
// Just in case some other code touched my collection object, check hasOwnProperty!
96146
if (mydata.hasOwnProperty(i)) {
97-
98147
if (mydata[i]['key'] === "actions") {
99-
100148
var actions = mydata[i]['value'];
101-
102149
for (var j in actions) {
103-
104150
if (actions.hasOwnProperty(j)) {
105-
106151
if (1 === actions[j]['isdefault']) {
107-
108152
action = actions[j];
109-
110153
break;
111154
}
112155
}
@@ -117,35 +160,15 @@
117160
}
118161

119162
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);
149172

150173
}
151174

sensorhubdemoclientnew/js/variable_dictionary.js

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ var sockets = {};
2424
var socketdata = {};
2525
var templates = {};
2626
var socketparseddata = {};
27+
var styles = {};
28+
var markers = {};
29+
2730

2831
var weatherDetails = null,
2932
gpsDetails = null,

0 commit comments

Comments
 (0)