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