[9216] | 1 | // Base stolen from http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
|
---|
[9220] | 2 | function AjaxRequest(url, callback, filter, field) {
|
---|
[9207] | 3 |
|
---|
[9216] | 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 | }
|
---|
[9207] | 13 | }
|
---|
[9216] | 14 |
|
---|
| 15 | function processRequest () {
|
---|
| 16 | if (req.readyState == 4) {
|
---|
| 17 | if (req.status == 200) {
|
---|
[9218] | 18 | if (callback) {
|
---|
[9220] | 19 | if (filter) callback(filter, field, req.responseText);
|
---|
[9218] | 20 | else callback(req.responseText);
|
---|
| 21 | }
|
---|
[9216] | 22 | }
|
---|
| 23 | }
|
---|
[9207] | 24 | }
|
---|
| 25 |
|
---|
[9216] | 26 | this.doGet = function() {
|
---|
| 27 | req.open("GET", url, true);
|
---|
| 28 | req.send(null);
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[9218] | 32 |
|
---|
[9216] | 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 />';
|
---|
[9207] | 47 | }
|
---|
[9216] | 48 | list += '</b>';
|
---|
[9207] | 49 | }
|
---|
[9216] | 50 | else{
|
---|
| 51 | list = 'No nodes to display.';
|
---|
| 52 | }
|
---|
| 53 | document.getElementById('node_list').innerHTML=list;
|
---|
[9207] | 54 | }
|
---|
| 55 |
|
---|
| 56 |
|
---|
[9218] | 57 | function get_filters() {
|
---|
[9220] | 58 |
|
---|
| 59 | // Create form
|
---|
[9218] | 60 | var formstart = '<form method="get" action="">';
|
---|
| 61 | var formend = '<input type="button" value="Add filter" onClick="addFilter()"/></form>';
|
---|
[9219] | 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 />';
|
---|
[9222] | 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 />';
|
---|
[9218] | 69 |
|
---|
[9220] | 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']]
|
---|
[9218] | 76 | for (var i=0; i<filters.length; i++) {
|
---|
[9220] | 77 | get_json(filters[i][0], filters[i][1]);
|
---|
[9218] | 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 |
|
---|
[9220] | 82 | function get_json(filter, field) {
|
---|
[9218] | 83 | var url = "/website/filter/filter_" + filter;
|
---|
[9220] | 84 | var ajax = new AjaxRequest(url, set_filter, filter, field);
|
---|
[9217] | 85 | ajax.doGet();
|
---|
| 86 | }
|
---|
[9216] | 87 |
|
---|
[9217] | 88 |
|
---|
[9220] | 89 | function set_filter(filter, field, responseText) {
|
---|
[9217] | 90 | json=eval('(' + responseText + ')');
|
---|
[9219] | 91 | var options = '';
|
---|
[9217] | 92 | for (var i=0; i<json.length; i++){
|
---|
[9222] | 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 | }
|
---|
[9217] | 99 | }
|
---|
[9220] | 100 | document.getElementById(filter).innerHTML+=options;
|
---|
[9217] | 101 | }
|
---|
| 102 |
|
---|
| 103 |
|
---|
[9222] | 104 | function update_filters(id){
|
---|
| 105 | var filtervalue = id.options[id.selectedIndex].value;
|
---|
| 106 |
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
[9217] | 110 | function addFilter(){
|
---|
| 111 |
|
---|
[9218] | 112 | var user = encodeURIComponent(document.getElementById("user").value);
|
---|
[9220] | 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);
|
---|
[9217] | 119 |
|
---|
[9221] | 120 | if (user != ''){user='&meetrondje__gebruiker__naam='+user;}
|
---|
[9217] | 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 | }
|
---|