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