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

Last change on this file since 9563 was 9406, checked in by dennisw, 13 years ago

Fixed layout issues with colourboxes.

File size: 12.3 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({
50 dateFormat: "dd/mm/yy",
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 */
[9267]57 $("#slider").slider({
58 range: true,
59 min: 0,
60 max: 100,
61 values: [0, 100],
62 // while sliding, it changes the text above the slider to show the values realtime
63 slide: function(event, sig){
64 $("#sig_value").text("Signal strength: " + sig.values[0] + " - " + sig.values[1]);
[9275]65 $("#signallayer font").text("Signal strength: " + sig.values[0] + " - " + sig.values[1]);
[9267]66 },
[9297]67 // on slider stop, it sets a new URL with updated values and redraws the layer
[9267]68 stop: function(event, sig){
[9275]69 signallayer = map.getLayersByName('signallayer');
[9358]70 signallayer[0].setUrl("tile/${z}/${x},${y}.png?colour=250,250,0&signaal__gte=" + sig.values[0] + "&signaal__lte=" + sig.values[1]);
[9275]71 signallayer[0].redraw();
[9267]72 },
73 });
74
[9302]75 /**
76 * Toggles layer visibility on checkbox use from layerswitcher.
77 */
[9297]78 $("#togglelayer").live('click', function(){
[9272]79 layername = $(this).parents('span').attr('id');
80 layer = map.getLayersByName(layername);
[9405]81 if(this.checked){
82 layer[0].setVisibility(true);
83 }
84 else{
85 layer[0].setVisibility(false);
86 }
[9272]87 });
88
[9302]89 /**
90 * Toggles layer visibility per category on checkbox use from layerswitcher.
91 */
[9297]92 $("#togglecat").live("click", function(){
93 layertype = $(this).attr('class');
94 layers = new Array();
95 layers = $('#' + layertype).children('span');
[9405]96 if(this.checked){
97 $.each(layers, function(l, layer){
98 layer = map.getLayersByName(layer.id);
99 layer[0].setVisibility(true);
100 $(this).children('input').attr('checked', true);
101 });
102 }
103 else{
104 $.each(layers, function(l, layer){
105 layer = map.getLayersByName(layer.id);
106 layer[0].setVisibility(false);
107 $(this).children('input').attr('checked', false);
108 });
109 }
[9276]110 });
111
[9302]112 /**
113 * Removes layer from map and layerswitcher.
114 */
[9272]115 $("#rmvlayer").live("click", function(){
[9274]116 layername = $(this).closest('span').attr('id');
[9273]117 layer = map.getLayersByName(layername);
[9272]118 map.removeLayer(layer[0]);
[9274]119 $(this).closest('span').remove();
[9272]120 });
121
[9302]122 /**
123 * Toggles text shown on website.
124 * 'info' shows info text.
125 * 'filter' page shows text on filters & filter options.
126 */
[9267]127 $("#menu_filter").click(function(){
128 $("#filter").slideToggle("fast");
[9272]129 $("#info").slideUp("fast");
[9267]130 });
131 $("#menu_info").click(function(){
132 $("#filter").slideUp("fast");
133 $("#info").slideToggle("fast");
134 });
[9347]135 $("#hide_parent").live("click",function(){
136 parent = $(this).parent("div");
137 $(parent).slideUp("fast");
138 });
139
[9267]140
[9347]141
[9302]142 /**
143 * Toggles layerswitcher visibility.
144 * On 'off', toggler shows a '+'.
145 * On 'on', toggler shows a '-'.
146 */
[9274]147 $("#layer_switcher_toggle").click(function(){
148 $("#layer_switcher").toggle();
149 if($(this).text() == '+'){
150 $(this).html('-');
151 }
152 else{
153 $(this).html('+');
154 }
155 });
156
[9302]157 /**
[9317]158 * Toggles category visibility.
159 * On 'visible', toggler shows a '^'.
160 * On 'invisible', toggler shows a 'v'.
[9316]161 */
162 $("#cat_hide").live("click", function(){
163 cat = $(this).parent('div').next('p').children('span')
164 cat.toggle();
165 if(cat.is(":visible")){
166 //FIXME: images are getting loaded the hard way. Replace '/static/'. '{{ STATIC_URL }}' doesn't seem to work here.
167 $(this).css('background-image', "url(/static/img/up.png)");
168 }
169 else{
170 $(this).css('background-image', "url(/static/img/down.png)");
171 }
172 });
173
174 /**
[9302]175 * Fastest?
176 * http://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery
177 */
[9358]178 $.getJSON("filters/",
[9235]179 function(json) {
180 $.each(json, function(i,json){
[9241]181 $("#select_user").append($("<option/>").attr("value",json.gebruiker).text(json.gebruiker));
[9263]182 userlist.push(json.gebruiker);
[9235]183 $.each(json.meetrondje, function(m, meetrondje){
[9243]184 $("#select_dataset").append($("<option/>").attr({"class":json.gebruiker, "value":meetrondje.naam}).text(meetrondje.naam));
[9235]185 $.each(meetrondje.nodes, function(n, nodes){
[9243]186 $("#select_node").append($("<option/>").attr({"class":meetrondje.naam, "value":nodes}).text(nodes));
[9263]187 if(jQuery.inArray(nodes, nodelist)<0){
188 nodelist.push(nodes);
189 }
[9235]190 });
191 });
192 });
[9243]193 // Initiate the chain
[9239]194 $("#select_dataset").chained("#select_user");
195 $("#select_node").chained("#select_dataset");
[9229]196 }
[9235]197 );
[9223]198
[9302]199 /**
200 * Earlier process got all users in JSON and put them in array.
201 * For each user in array, new layer is added with username as parameter.
202 * Layercolour is randomized.
203 * If button is pressed again, layers will be deleted.
204 */
[9263]205 $('#user_filter').click(function(){
[9276]206 if(this.text=='(Add all users)'){
[9264]207 $.each(userlist, function(u, user){
[9273]208 colour = Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);
[9264]209 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
210 initialize: function(name, options) {
211 var url = [
[9358]212 "tile/${z}/${x},${y}.png?&colour=" + colour + "&meetrondje__gebruiker__naam=" + user
[9264]213 ];
214 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
215 var newArguments = [name, url, options];
216 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
217 },
218 CLASS_NAME: "OpenLayers.Layer.Overlay"
219 });
[9274]220 filterlayer = new OpenLayers.Layer.OSM.Overlay(user, {isBaseLayer: false, visibility: true});
[9264]221 map.addLayer(filterlayer);
[9406]222 $("#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]223 });
[9276]224 $(this).text('(Del all users');
[9264]225 }
226 else{
[9276]227 $(this).text('(Add all users)');
[9317]228 $.each($('#user span'), function(s, span){
229 layer = map.getLayersByName(span.id);
[9264]230 map.removeLayer(layer[0]);
[9317]231 $(span).remove();
[9264]232 });
233 }
[9263]234 });
235
[9302]236 /**
237 * Earlier process got all nodes in JSON and put them in array.
238 * For each node in array, new layer is added with node as parameter.
239 * Layercolour is randomized.
240 * If button is pressed again, layers will be deleted.
241 */
[9263]242 $('#node_filter').click(function(){
[9276]243 if(this.text=='(Add all nodes)'){
[9264]244 $.each(nodelist, function(n, node){
[9273]245 colour = Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);
[9264]246 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
247 initialize: function(name, options) {
248 var url = [
[9358]249 "tile/${z}/${x},${y}.png?&colour=" + colour + "&accespoint__ssid=" + node
[9264]250 ];
251 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
252 var newArguments = [name, url, options];
253 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
254 },
255 CLASS_NAME: "OpenLayers.Layer.Overlay"
256 });
[9274]257 nodefilterlayer = new OpenLayers.Layer.OSM.Overlay(node, {isBaseLayer: false, visibility: true});
[9264]258 map.addLayer(nodefilterlayer);
[9406]259 $("#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]260 });
[9276]261 $(this).text('(Del all nodes)');
[9264]262 }
263 else{
[9276]264 $(this).text('(Add all nodes)');
265 $.each($('#node span'), function(s, span){
266 layer = map.getLayersByName(span.id);
[9264]267 map.removeLayer(layer[0]);
[9276]268 $(span).remove();
[9264]269 });
270 }
[9263]271 });
272
[9302]273 /**
274 * Adds a new layer when clicked.
275 * Filters set by user are used as layer parameters.
276 * Colour is either chosen or randomized.
277 * Blank parameters are ignored.
278 */
[9235]279 $('#add_filter').click(function(){
[9302]280 // get values from elements
[9235]281 user = $('#select_user option:selected').text();
282 dataset = $('#select_dataset option:selected').text();
283 wlnode = $('#select_node option:selected').text();
[9251]284 start_date = $('#start_date').val();
285 end_date = $('#end_date').val();
[9235]286 colour = encodeURIComponent(document.getElementById("colour").value);
287 lname = encodeURIComponent(document.getElementById("lname").value);
[9223]288
[9302]289 /**
290 * On HEX to RGB:
291 * http://stackoverflow.com/questions/5798868/need-some-tips-with-how-to-convert-a-hexadecimal-color-value-to-a-rgb-one/5798900#5798900
292 * Note that '#' comes out as '%23', so substr() starts at char 3
293 */
[9246]294 colour = parseInt((colour.substr(3, 2)),16) + ',' + parseInt((colour.substr(5, 2)),16) + ',' + parseInt((colour.substr(7, 2)),16);
295
[9263]296 // some checks if values are correct, and adding them to parts of the link
[9241]297 if (user != ''){user='&meetrondje__gebruiker__naam='+user;}
298 if (dataset != ''){dataset='&meetrondje__naam='+dataset;}
[9246]299 if (wlnode != ''){wlnode='&accespoint__ssid='+wlnode;}
[9251]300 if (start_date && end_date){
301 sd_d=start_date.substr(0,2);
302 sd_m=start_date.substr(3,2);
303 sd_y=start_date.substr(6,4);
304
305 ed_d=end_date.substr(0,2);
306 ed_m=end_date.substr(3,2);
307 ed_y=end_date.substr(6,4);
308
309 start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
310 end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
311 }
[9253]312 if (start_date && !end_date){
313 sd_d=start_date.substr(0,2);
314 sd_m=start_date.substr(3,2);
315 sd_y=start_date.substr(6,4);
316 start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
317 end_date='';
318 }
319 if (!start_date && end_date){
320 ed_d=end_date.substr(0,2);
321 ed_m=end_date.substr(3,2);
322 ed_y=end_date.substr(6,4);
323 start_date='';
324 end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
325 }
[9273]326 if (colour != 'NaN,NaN,NaN'){colour=colour;}
327 else {colour = Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);}
[9235]328 if (lname != ''){lname=lname;}
329 else {lname = 'Custom Filter';}
[9223]330
[9263]331 // setting layer
[9235]332 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
333 initialize: function(name, options) {
334 var url = [
[9358]335 "tile/${z}/${x},${y}.png?&colour=" + colour + user + dataset + wlnode + start_date + end_date
[9235]336 ];
337 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
338 var newArguments = [name, url, options];
339 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
340 },
[9274]341
[9235]342 CLASS_NAME: "OpenLayers.Layer.Overlay"
343 });
[9223]344
[9263]345 // adding layer
[9235]346 filterlayer = new OpenLayers.Layer.OSM.Overlay(lname, {isBaseLayer: false, visibility: true});
347 map.addLayer(filterlayer);
[9274]348
[9406]349 $("#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]350 });
[9235]351});
Note: See TracBrowser for help on using the repository browser.