source: src/django_gheat/wlheatmap/static/heatmap_extensions.js@ 9648

Last change on this file since 9648 was 9648, checked in by rick, 13 years ago

Bunch of comma fixes to make IE happy.

File size: 14.0 KB
RevLine 
[9302]1/**
2 * Uses zoomleven and mouseposition to call nodelist.py view.
3 * View returns nodes in json format, values are printed in doc element.
4 */
[9269]5function getNodeList(zoomlevel, mousepos){
[9358]6 $.getJSON("nodelist/" + zoomlevel + "," + mousepos.lat + "," + mousepos.lon,
[9269]7 function(json){
[9234]8 content = 'Wireless Leiden nodes on mouseposition:<br /><b>';
9 $.each(json, function(i,json){
[9244]10 content += json.fields.ssid + '<br />';
[9234]11 });
[9244]12 content += '</b>';
[9234]13 $("#node_list").html(content);
[9223]14 }
[9234]15 );
[9223]16}
17
[9302]18/**
19 * Right way to get url parameters?
20 * http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery/1404100#1404100
21 */
[9269]22function getURLParameter(name) {
23 return decodeURI(
24 (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
25 );
26}
27
[9235]28$(document).ready(function() {
[9267]29 var signallayer = '';
[9263]30 var userlist = new Array();
31 var nodelist = new Array();
[9237]32
[9302]33 /**
34 * Adds colourpicker for layer colour.
35 * Function set in: 'colourpicker.js'
36 */
[9267]37 $("#colour").colorPicker();
38
[9302]39 /**
40 * Adds datepicker for start & end date
41 * Function set in: 'jquery-ui-1.8.13.custom.min.js'
42 */
[9267]43 $("#start_date").datepicker({
44 dateFormat: "dd/mm/yy",
45 onSelect: function(dateValue, inst){
46 $("#end_date").datepicker("option", "minDate", dateValue);
47 }
48 });
49 $("#end_date").datepicker({
[9641]50 dateFormat: "dd/mm/yy"
[9267]51 });
[9272]52
[9302]53 /**
54 * Adds slider for signal strength layer.
55 * Function set in: 'jquery-ui-1.8.13.custom.min.js'
56 */
[9570]57 function update_slider(min,max) {
[9575]58 $("#sig_value").text("All AccessPoints Signal Strength: " + min + " - " + max);
59 $("#signallayer font").text("All AccessPoints Signal: " + min + " - " + max);
[9570]60 };
61
[9578]62 function update_sig_slider(min,max) {
63 $("#select_sig_value").text("Signal Strength: " + min + " - " + max);
64 };
65
[9267]66 $("#slider").slider({
67 range: true,
68 min: 0,
69 max: 100,
70 values: [0, 100],
71 // while sliding, it changes the text above the slider to show the values realtime
72 slide: function(event, sig){
[9570]73 update_slider(sig.values[0], sig.values[1]);
[9267]74 },
[9297]75 // on slider stop, it sets a new URL with updated values and redraws the layer
[9267]76 stop: function(event, sig){
[9275]77 signallayer = map.getLayersByName('signallayer');
[9570]78 signallayer[0].setUrl("tile/${z}/${x},${y}.png?colour=90,90,90&signaal__gte=" + sig.values[0] + "&signaal__lte=" + sig.values[1]);
[9275]79 signallayer[0].redraw();
[9648]80 }
[9267]81 });
[9578]82 $("#select_sig_slider").slider({
83 range: true,
84 min: 0,
85 max: 100,
86 values: [0,100],
87 // while sliding, it changes the text above the slider to show the values realtime
88 slide: function(event, sig){
89 update_sig_slider(sig.values[0], sig.values[1]);
[9648]90 }
[9578]91 });
[9267]92
[9570]93
94 function init_slider(min, max) {
95 $("#slider").slider( "option", "values", [min,max] );
96 signallayer = map.getLayersByName('signallayer');
97 signallayer[0].setUrl("tile/${z}/${x},${y}.png?colour=90,90,90&signaal__gte=" + min + "&signaal__lte=" + max);
98 signallayer[0].redraw();
99 update_slider(min,max);
[9578]100
101 $("#select_sig_slider").slider( "option", "values", [min,max] );
102 update_sig_slider(min,max);
[9570]103 };
104
105
106
[9302]107 /**
108 * Toggles layer visibility on checkbox use from layerswitcher.
109 */
[9297]110 $("#togglelayer").live('click', function(){
[9272]111 layername = $(this).parents('span').attr('id');
112 layer = map.getLayersByName(layername);
[9405]113 if(this.checked){
114 layer[0].setVisibility(true);
115 }
116 else{
117 layer[0].setVisibility(false);
118 }
[9272]119 });
120
[9302]121 /**
122 * Toggles layer visibility per category on checkbox use from layerswitcher.
123 */
[9297]124 $("#togglecat").live("click", function(){
125 layertype = $(this).attr('class');
126 layers = new Array();
127 layers = $('#' + layertype).children('span');
[9405]128 if(this.checked){
129 $.each(layers, function(l, layer){
130 layer = map.getLayersByName(layer.id);
131 layer[0].setVisibility(true);
132 $(this).children('input').attr('checked', true);
133 });
134 }
135 else{
136 $.each(layers, function(l, layer){
137 layer = map.getLayersByName(layer.id);
138 layer[0].setVisibility(false);
139 $(this).children('input').attr('checked', false);
140 });
141 }
[9276]142 });
143
[9302]144 /**
145 * Removes layer from map and layerswitcher.
146 */
[9272]147 $("#rmvlayer").live("click", function(){
[9274]148 layername = $(this).closest('span').attr('id');
[9273]149 layer = map.getLayersByName(layername);
[9272]150 map.removeLayer(layer[0]);
[9274]151 $(this).closest('span').remove();
[9272]152 });
153
[9302]154 /**
155 * Toggles text shown on website.
156 * 'info' shows info text.
157 * 'filter' page shows text on filters & filter options.
158 */
[9267]159 $("#menu_filter").click(function(){
160 $("#filter").slideToggle("fast");
[9272]161 $("#info").slideUp("fast");
[9267]162 });
163 $("#menu_info").click(function(){
164 $("#filter").slideUp("fast");
165 $("#info").slideToggle("fast");
166 });
[9347]167 $("#hide_parent").live("click",function(){
168 parent = $(this).parent("div");
169 $(parent).slideUp("fast");
170 });
171
[9267]172
[9347]173
[9302]174 /**
175 * Toggles layerswitcher visibility.
176 * On 'off', toggler shows a '+'.
177 * On 'on', toggler shows a '-'.
178 */
[9274]179 $("#layer_switcher_toggle").click(function(){
180 $("#layer_switcher").toggle();
181 if($(this).text() == '+'){
182 $(this).html('-');
183 }
184 else{
185 $(this).html('+');
186 }
187 });
188
[9302]189 /**
[9317]190 * Toggles category visibility.
191 * On 'visible', toggler shows a '^'.
192 * On 'invisible', toggler shows a 'v'.
[9316]193 */
194 $("#cat_hide").live("click", function(){
195 cat = $(this).parent('div').next('p').children('span')
196 cat.toggle();
197 if(cat.is(":visible")){
198 //FIXME: images are getting loaded the hard way. Replace '/static/'. '{{ STATIC_URL }}' doesn't seem to work here.
199 $(this).css('background-image', "url(/static/img/up.png)");
200 }
201 else{
202 $(this).css('background-image', "url(/static/img/down.png)");
203 }
204 });
205
206 /**
[9302]207 * Fastest?
208 * http://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery
209 */
[9358]210 $.getJSON("filters/",
[9235]211 function(json) {
212 $.each(json, function(i,json){
[9241]213 $("#select_user").append($("<option/>").attr("value",json.gebruiker).text(json.gebruiker));
[9263]214 userlist.push(json.gebruiker);
[9235]215 $.each(json.meetrondje, function(m, meetrondje){
[9577]216 $("#select_dataset").append($("<option/>").attr({"class":json.gebruiker, "value": json.gebruiker + "-" + meetrondje.naam}).text(meetrondje.naam));
[9235]217 $.each(meetrondje.nodes, function(n, nodes){
[9577]218 $("#select_node").append($("<option/>").attr({"class":json.gebruiker + "-" + meetrondje.naam, "value":nodes}).text(nodes));
[9263]219 if(jQuery.inArray(nodes, nodelist)<0){
220 nodelist.push(nodes);
221 }
[9235]222 });
223 });
224 });
[9243]225 // Initiate the chain
[9239]226 $("#select_dataset").chained("#select_user");
227 $("#select_node").chained("#select_dataset");
[9229]228 }
[9235]229 );
[9223]230
[9302]231 /**
232 * Earlier process got all users in JSON and put them in array.
233 * For each user in array, new layer is added with username as parameter.
234 * Layercolour is randomized.
235 * If button is pressed again, layers will be deleted.
236 */
[9577]237 function update_lname() {
238 $("#lname").val($("#select_user option:selected").text() + " - " + $("#select_dataset option:selected").text() + " - " + $("#select_node option:selected").text());
239 }
240 $("#select_user").change(function(){
241 update_lname();
242 });
243 $("#select_dataset").change(function(){
244 update_lname();
245 });
246 $("#select_node").change(function(){
247 update_lname();
248 });
249
[9263]250 $('#user_filter').click(function(){
[9276]251 if(this.text=='(Add all users)'){
[9264]252 $.each(userlist, function(u, user){
[9273]253 colour = Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);
[9264]254 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
255 initialize: function(name, options) {
256 var url = [
[9358]257 "tile/${z}/${x},${y}.png?&colour=" + colour + "&meetrondje__gebruiker__naam=" + user
[9264]258 ];
259 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
260 var newArguments = [name, url, options];
261 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
262 },
263 CLASS_NAME: "OpenLayers.Layer.Overlay"
264 });
[9274]265 filterlayer = new OpenLayers.Layer.OSM.Overlay(user, {isBaseLayer: false, visibility: true});
[9264]266 map.addLayer(filterlayer);
[9406]267 $("#user").append("<span id=\"" + user + "\"><div id='layer_switcher_colour' style='background-color:rgb(" + colour + ")' /><input type=checkbox id=togglelayer checked /><font>" + user + " </font><a id=rmvlayer>X</a><br /></span>");
[9263]268 });
[9276]269 $(this).text('(Del all users');
[9264]270 }
271 else{
[9276]272 $(this).text('(Add all users)');
[9317]273 $.each($('#user span'), function(s, span){
274 layer = map.getLayersByName(span.id);
[9264]275 map.removeLayer(layer[0]);
[9317]276 $(span).remove();
[9264]277 });
278 }
[9263]279 });
280
[9302]281 /**
282 * Earlier process got all nodes in JSON and put them in array.
283 * For each node in array, new layer is added with node as parameter.
284 * Layercolour is randomized.
285 * If button is pressed again, layers will be deleted.
286 */
[9263]287 $('#node_filter').click(function(){
[9276]288 if(this.text=='(Add all nodes)'){
[9264]289 $.each(nodelist, function(n, node){
[9273]290 colour = Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);
[9264]291 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
292 initialize: function(name, options) {
293 var url = [
[9358]294 "tile/${z}/${x},${y}.png?&colour=" + colour + "&accespoint__ssid=" + node
[9264]295 ];
296 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
297 var newArguments = [name, url, options];
298 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
299 },
300 CLASS_NAME: "OpenLayers.Layer.Overlay"
301 });
[9274]302 nodefilterlayer = new OpenLayers.Layer.OSM.Overlay(node, {isBaseLayer: false, visibility: true});
[9264]303 map.addLayer(nodefilterlayer);
[9406]304 $("#node").append("<span class='node' id=\"" + node + "\"><div id='layer_switcher_colour' style='background-color:rgb(" + colour + ")' /><input type=checkbox id=togglelayer checked /><font>" + node + " </font><a id=rmvlayer>X</a><br /></span>");
[9263]305 });
[9276]306 $(this).text('(Del all nodes)');
[9264]307 }
308 else{
[9276]309 $(this).text('(Add all nodes)');
310 $.each($('#node span'), function(s, span){
311 layer = map.getLayersByName(span.id);
[9264]312 map.removeLayer(layer[0]);
[9276]313 $(span).remove();
[9264]314 });
315 }
[9263]316 });
317
[9302]318 /**
319 * Adds a new layer when clicked.
320 * Filters set by user are used as layer parameters.
321 * Colour is either chosen or randomized.
322 * Blank parameters are ignored.
323 */
[9235]324 $('#add_filter').click(function(){
[9302]325 // get values from elements
[9235]326 user = $('#select_user option:selected').text();
327 dataset = $('#select_dataset option:selected').text();
328 wlnode = $('#select_node option:selected').text();
[9251]329 start_date = $('#start_date').val();
330 end_date = $('#end_date').val();
[9577]331 colour = $("#colour").val();
332 lname = $("#lname").val();
[9223]333
[9302]334 /**
335 * On HEX to RGB:
336 * http://stackoverflow.com/questions/5798868/need-some-tips-with-how-to-convert-a-hexadecimal-color-value-to-a-rgb-one/5798900#5798900
337 * Note that '#' comes out as '%23', so substr() starts at char 3
338 */
[9246]339 colour = parseInt((colour.substr(3, 2)),16) + ',' + parseInt((colour.substr(5, 2)),16) + ',' + parseInt((colour.substr(7, 2)),16);
340
[9263]341 // some checks if values are correct, and adding them to parts of the link
[9578]342 if (user == 'all') {
343 user = '';
344 } else {
345 user='&meetrondje__gebruiker__naam='+user;
346 }
347 if (dataset == 'all') {
348 dataset = '';
349 } else {
350 dataset='&meetrondje__naam='+dataset;
351 }
352 if (wlnode == 'all'){
353 wlnode='';
354 } else {
355 wlnode='&accespoint__ssid='+wlnode;
356 }
[9251]357 if (start_date && end_date){
358 sd_d=start_date.substr(0,2);
359 sd_m=start_date.substr(3,2);
360 sd_y=start_date.substr(6,4);
361
362 ed_d=end_date.substr(0,2);
363 ed_m=end_date.substr(3,2);
364 ed_y=end_date.substr(6,4);
365
366 start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
367 end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
368 }
[9253]369 if (start_date && !end_date){
370 sd_d=start_date.substr(0,2);
371 sd_m=start_date.substr(3,2);
372 sd_y=start_date.substr(6,4);
373 start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
374 end_date='';
375 }
376 if (!start_date && end_date){
377 ed_d=end_date.substr(0,2);
378 ed_m=end_date.substr(3,2);
379 ed_y=end_date.substr(6,4);
380 start_date='';
381 end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
382 }
[9578]383 if (colour != 'NaN,NaN,NaN'){
384 colour=colour;
385 } else {
386 colour = Math.floor(Math.random()*256)+','+Math.floor (Math.random()*256)+','+Math.floor(Math.random()*256);
387 }
388 if (lname == ''){
389 lname= 'Custom Filter';
390 }
[9223]391
[9578]392 var min = $("#select_sig_slider").slider("values")[0];
393 var max = $("#select_sig_slider").slider("values")[1];
394 signal = '&signaal__gte=' + min + '&signaal__lte=' + max;
395
[9263]396 // setting layer
[9235]397 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
398 initialize: function(name, options) {
399 var url = [
[9578]400 "tile/${z}/${x},${y}.png?colour=" + colour + user + dataset + wlnode + start_date + end_date + signal
[9235]401 ];
402 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
403 var newArguments = [name, url, options];
404 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
405 },
[9274]406
[9235]407 CLASS_NAME: "OpenLayers.Layer.Overlay"
408 });
[9223]409
[9263]410 // adding layer
[9235]411 filterlayer = new OpenLayers.Layer.OSM.Overlay(lname, {isBaseLayer: false, visibility: true});
412 map.addLayer(filterlayer);
[9274]413
[9406]414 $("#custom").append("<span id=\"" + lname + "\"><div id='layer_switcher_colour' style='background-color:rgb(" + colour + ")' /><input type=checkbox id=togglelayer checked /><font>" + lname + " </font><a id=rmvlayer>X</a><br /></span>");
[9223]415 });
[9570]416 init_heatmap();
417 init_slider(35,75);
[9235]418});
Note: See TracBrowser for help on using the repository browser.