1 | // Base stolen from http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
|
---|
2 | function 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.
|
---|
34 | function 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 |
|
---|
41 | function 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 |
|
---|
57 | function 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"><option></option></select> User<br />';
|
---|
65 | var dataset = '<select id="dataset" style="width:104px"><option></option></select> Dataset<br />';
|
---|
66 | var node = '<select id="node" style="width:104px"><option></option></select> Node<br />';
|
---|
67 | var enc = '<select id="enc" style="width:104px"><option></option></select> Encryption<br />';
|
---|
68 | var date = '<select id="date" style="width:104px"><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 |
|
---|
82 | function 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 |
|
---|
89 | function set_filter(filter, field, responseText) {
|
---|
90 | json=eval('(' + responseText + ')');
|
---|
91 | var options = '';
|
---|
92 | for (var i=0; i<json.length; i++){
|
---|
93 | options += '<option>' + json[i].fields[field] + '</option>';
|
---|
94 | }
|
---|
95 | document.getElementById(filter).innerHTML+=options;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | function addFilter(){
|
---|
100 |
|
---|
101 | var user = encodeURIComponent(document.getElementById("user").value);
|
---|
102 | var dataset = encodeURIComponent(document.getElementById("dataset").value);
|
---|
103 | var wlnode = encodeURIComponent(document.getElementById("node").value);
|
---|
104 | var enc = encodeURIComponent(document.getElementById("enc").value);
|
---|
105 | var date = encodeURIComponent(document.getElementById("date").value);
|
---|
106 | var colour = encodeURIComponent(document.getElementById("colour").value);
|
---|
107 | var lname = encodeURIComponent(document.getElementById("lname").value);
|
---|
108 |
|
---|
109 | if (user != ''){user='&gebruiker__naam='+user;}
|
---|
110 | if (dataset != ''){dataset='&meetrondje__naam='+dataset;}
|
---|
111 | if (wlnode != ''){wlnode='&accespoint__ssid='+wlnode;}
|
---|
112 | if (enc != ''){enc='&accespoint__encryptie='+enc;}
|
---|
113 | if (date != ''){date='&meetrondje__datum='+date;}
|
---|
114 | if (colour != ''){colour='colour='+colour;}
|
---|
115 | else {colour = '&colour='+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);}
|
---|
116 | if (lname != ''){lname=lname;}
|
---|
117 | else {lname = 'Custom Filter';}
|
---|
118 |
|
---|
119 | var baseurl = "/website/tile/${z}/${x},${y}.png?";
|
---|
120 |
|
---|
121 | OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
|
---|
122 | initialize: function(name, options) {
|
---|
123 | var url = [
|
---|
124 | baseurl + colour + user + dataset + wlnode + enc + date
|
---|
125 | ];
|
---|
126 | options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
|
---|
127 | var newArguments = [name, url, options];
|
---|
128 | OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
|
---|
129 | },
|
---|
130 | CLASS_NAME: "OpenLayers.Layer.Overlay"
|
---|
131 | });
|
---|
132 |
|
---|
133 | filterlayer = new OpenLayers.Layer.OSM.Overlay(lname, {isBaseLayer: false, visibility: true});
|
---|
134 | map.addLayer(filterlayer);
|
---|
135 | }
|
---|