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

Last change on this file since 9231 was 9222, checked in by dennisw, 13 years ago

Added ID's to options to make chain select possibly easier.

File size: 5.2 KB
Line 
1// Base stolen from http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
2function AjaxRequest(url, callback, filter, field) {
3
4 var req = init();
5 req.onreadystatechange = processRequest;
6
7 function init() {
8 if (window.XMLHttpRequest) {
9 return new XMLHttpRequest();
10 } else if (window.ActiveXObject) {
11 return new ActiveXObject("Microsoft.XMLHTTP");
12 }
13 }
14
15 function processRequest () {
16 if (req.readyState == 4) {
17 if (req.status == 200) {
18 if (callback) {
19 if (filter) callback(filter, field, req.responseText);
20 else callback(req.responseText);
21 }
22 }
23 }
24 }
25
26 this.doGet = function() {
27 req.open("GET", url, true);
28 req.send(null);
29 }
30}
31
32
33// Uses zoomlevel en mouseposition to call the nodelist.py view. View returns nodes in json format which is read and printed in document element.
34function getNodeList(zoomlevel, mousepos) {
35 var url = "/website/nodelist/" + zoomlevel + "," + mousepos.lat + "," + mousepos.lon;
36 var ajax = new AjaxRequest(url, setNodeList);
37 ajax.doGet();
38}
39
40
41function setNodeList(responseText) {
42 json=eval('(' + responseText + ')');
43 if (json.length>0){
44 list = 'Wireless Leiden nodes on mouseposition:<br /><b>';
45 for (var i=0; i<json.length; i++){
46 list += json[i].fields.ssid + '<br />';
47 }
48 list += '</b>';
49 }
50 else{
51 list = 'No nodes to display.';
52 }
53 document.getElementById('node_list').innerHTML=list;
54}
55
56
57function get_filters() {
58
59 // Create form
60 var formstart = '<form method="get" action="">';
61 var formend = '<input type="button" value="Add filter" onClick="addFilter()"/></form>';
62 var layername = '<input type="text" id="lname" name="lname" size="10"/> Layername<br />';
63 var colour = '<input type="text" id="colour" name="colour" size="10"/> Colour<br />';
64 var user = '<select id="user" style="width:104px" onblur="update_filters(this)"><option></option></select> User<br />';
65 var dataset = '<select id="dataset" style="width:104px" onblur="update_filters(this)"><option></option></select> Dataset<br />';
66 var node = '<select id="node" style="width:104px" onblur="update_filters(this)"><option></option></select> Node<br />';
67 var enc = '<select id="enc" style="width:104px" onblur="update_filters(this)"><option></option></select> Encryption<br />';
68 var date = '<select id="date" style="width:104px" onblur="update_filters(this)"><option></option></select> Date<br />';
69
70 // Write form to document
71 document.getElementById('filter_list').innerHTML+=(formstart + user + dataset + node + enc + date + colour + layername + formend);
72
73 // Get values for select boxes
74 // filters[] first value is what to get, second value is which field values will be shown in select box
75 var filters = [['user','naam'],['dataset','naam'],['node','ssid']]
76 for (var i=0; i<filters.length; i++) {
77 get_json(filters[i][0], filters[i][1]);
78 }
79}
80
81
82function get_json(filter, field) {
83 var url = "/website/filter/filter_" + filter;
84 var ajax = new AjaxRequest(url, set_filter, filter, field);
85 ajax.doGet();
86}
87
88
89function set_filter(filter, field, responseText) {
90 json=eval('(' + responseText + ')');
91 var options = '';
92 for (var i=0; i<json.length; i++){
93 if (filter=='dataset'){
94 options += '<option value="' + json[i].fields.gebruiker + '">' + json[i].fields[field] + '</option>';
95 }
96 else{
97 options += '<option value="' + json[i].pk + '">' + json[i].fields[field] + '</option>';
98 }
99 }
100 document.getElementById(filter).innerHTML+=options;
101}
102
103
104function update_filters(id){
105 var filtervalue = id.options[id.selectedIndex].value;
106
107}
108
109
110function addFilter(){
111
112 var user = encodeURIComponent(document.getElementById("user").value);
113 var dataset = encodeURIComponent(document.getElementById("dataset").value);
114 var wlnode = encodeURIComponent(document.getElementById("node").value);
115 var enc = encodeURIComponent(document.getElementById("enc").value);
116 var date = encodeURIComponent(document.getElementById("date").value);
117 var colour = encodeURIComponent(document.getElementById("colour").value);
118 var lname = encodeURIComponent(document.getElementById("lname").value);
119
120 if (user != ''){user='&meetrondje__gebruiker__naam='+user;}
121 if (dataset != ''){dataset='&meetrondje__naam='+dataset;}
122 if (wlnode != ''){wlnode='&accespoint__ssid='+wlnode;}
123 if (enc != ''){enc='&accespoint__encryptie='+enc;}
124 if (date != ''){date='&meetrondje__datum='+date;}
125 if (colour != ''){colour='colour='+colour;}
126 else {colour = '&colour='+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);}
127 if (lname != ''){lname=lname;}
128 else {lname = 'Custom Filter';}
129
130 var baseurl = "/website/tile/${z}/${x},${y}.png?";
131
132 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
133 initialize: function(name, options) {
134 var url = [
135 baseurl + colour + user + dataset + wlnode + enc + date
136 ];
137 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
138 var newArguments = [name, url, options];
139 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
140 },
141 CLASS_NAME: "OpenLayers.Layer.Overlay"
142 });
143
144 filterlayer = new OpenLayers.Layer.OSM.Overlay(lname, {isBaseLayer: false, visibility: true});
145 map.addLayer(filterlayer);
146}
Note: See TracBrowser for help on using the repository browser.