source: src/django_gheat/website/static/heatmap_extensions.js@ 9263

Last change on this file since 9263 was 9263, checked in by dennisw, 14 years ago

Changed 'Wireless Leiden Only' to red.
Changed 'All accespoints' to grey.
Added a mass-add button for users and Wireless Leiden nodes. These will create a new layer per item with random colour.
Added the permalink control. URLs aren't working yet though.

File size: 6.7 KB
Line 
1// Uses zoomlevel and mouseposition to call the nodelist.py view. View returns nodes in json format which is read and printed in document element.
2function getNodeList(zoomlevel, mousepos) {
3 $.getJSON("/website/nodelist/" + zoomlevel + "," + mousepos.lat + "," + mousepos.lon,
4 function(json) {
5 content = 'Wireless Leiden nodes on mouseposition:<br /><b>';
6 $.each(json, function(i,json){
7 content += json.fields.ssid + '<br />';
8 });
9 content += '</b>';
10 $("#node_list").html(content);
11 }
12 );
13}
14
15$(document).ready(function() {
16 var userlist = new Array();
17 var nodelist = new Array();
18
19 // Fastest?: http://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery
20 $.getJSON("/website/filters/",
21 function(json) {
22 $.each(json, function(i,json){
23 $("#select_user").append($("<option/>").attr("value",json.gebruiker).text(json.gebruiker));
24 userlist.push(json.gebruiker);
25 document.getElementById('filter_text').innerHTML+=("<br />User added to array: " + json.gebruiker);
26 $.each(json.meetrondje, function(m, meetrondje){
27 $("#select_dataset").append($("<option/>").attr({"class":json.gebruiker, "value":meetrondje.naam}).text(meetrondje.naam));
28 $.each(meetrondje.nodes, function(n, nodes){
29 $("#select_node").append($("<option/>").attr({"class":meetrondje.naam, "value":nodes}).text(nodes));
30 if(jQuery.inArray(nodes, nodelist)<0){
31 document.getElementById('filter_text').innerHTML+=("<br />Node added to array: " + nodes);
32 nodelist.push(nodes);
33 }
34 });
35 });
36 });
37 // Initiate the chain
38 $("#select_dataset").chained("#select_user");
39 $("#select_node").chained("#select_dataset");
40 }
41 );
42
43 // add filter per user
44 $('#user_filter').click(function(){
45 $.each(userlist, function(u, user){
46 colour = '&colour='+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);
47 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
48 initialize: function(name, options) {
49 var url = [
50 "/website/tile/${z}/${x},${y}.png?" + colour + "&meetrondje__gebruiker__naam=" + user
51 ];
52 document.getElementById('filter_text').innerHTML+="<br />Added: " + url;
53 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
54 var newArguments = [name, url, options];
55 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
56 },
57 CLASS_NAME: "OpenLayers.Layer.Overlay"
58 });
59 filterlayer = new OpenLayers.Layer.OSM.Overlay("User: "+ user, {isBaseLayer: false, visibility: true});
60 map.addLayer(filterlayer);
61 });
62 });
63
64 // add filter per node
65 $('#node_filter').click(function(){
66 $.each(nodelist, function(n, node){
67 colour = '&colour='+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);
68 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
69 initialize: function(name, options) {
70 var url = [
71 "/website/tile/${z}/${x},${y}.png?" + colour + "&accespoint__ssid=" + node
72 ];
73 document.getElementById('filter_text').innerHTML+="<br />Added: " + url;
74 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
75 var newArguments = [name, url, options];
76 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
77 },
78 CLASS_NAME: "OpenLayers.Layer.Overlay"
79 });
80 filterlayer = new OpenLayers.Layer.OSM.Overlay("Node: "+ node, {isBaseLayer: false, visibility: true});
81 map.addLayer(filterlayer);
82 });
83 });
84
85 // add custom filter
86 $('#add_filter').click(function(){
87 //get values from elements
88 user = $('#select_user option:selected').text();
89 dataset = $('#select_dataset option:selected').text();
90 wlnode = $('#select_node option:selected').text();
91 start_date = $('#start_date').val();
92 end_date = $('#end_date').val();
93 colour = encodeURIComponent(document.getElementById("colour").value);
94 lname = encodeURIComponent(document.getElementById("lname").value);
95
96 // HEX to RGB: http://stackoverflow.com/questions/5798868/need-some-tips-with-how-to-convert-a-hexadecimal-color-value-to-a-rgb-one/5798900#5798900
97 // '#' comes out as '%23', so substr() starts at char 3
98 colour = parseInt((colour.substr(3, 2)),16) + ',' + parseInt((colour.substr(5, 2)),16) + ',' + parseInt((colour.substr(7, 2)),16);
99
100 // some checks if values are correct, and adding them to parts of the link
101 if (user != ''){user='&meetrondje__gebruiker__naam='+user;}
102 if (dataset != ''){dataset='&meetrondje__naam='+dataset;}
103 if (wlnode != ''){wlnode='&accespoint__ssid='+wlnode;}
104 if (start_date && end_date){
105 sd_d=start_date.substr(0,2);
106 sd_m=start_date.substr(3,2);
107 sd_y=start_date.substr(6,4);
108
109 ed_d=end_date.substr(0,2);
110 ed_m=end_date.substr(3,2);
111 ed_y=end_date.substr(6,4);
112
113 start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
114 end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
115 }
116 if (start_date && !end_date){
117 sd_d=start_date.substr(0,2);
118 sd_m=start_date.substr(3,2);
119 sd_y=start_date.substr(6,4);
120 start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
121 end_date='';
122 }
123 if (!start_date && end_date){
124 ed_d=end_date.substr(0,2);
125 ed_m=end_date.substr(3,2);
126 ed_y=end_date.substr(6,4);
127 start_date='';
128 end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
129 }
130 if (colour != 'NaN,NaN,NaN'){colour='colour='+colour;}
131 else {colour = '&colour='+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);}
132 if (lname != ''){lname=lname;}
133 else {lname = 'Custom Filter';}
134
135 // setting layer
136 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
137 initialize: function(name, options) {
138 var url = [
139 "/website/tile/${z}/${x},${y}.png?" + colour + user + dataset + wlnode + start_date + end_date
140 ];
141 document.getElementById('filter_text').innerHTML+="<br />Added: " + url;
142 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
143 var newArguments = [name, url, options];
144 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
145 },
146 CLASS_NAME: "OpenLayers.Layer.Overlay"
147 });
148
149 // adding layer
150 filterlayer = new OpenLayers.Layer.OSM.Overlay(lname, {isBaseLayer: false, visibility: true});
151 map.addLayer(filterlayer);
152 });
153});
Note: See TracBrowser for help on using the repository browser.