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