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

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

Datepicker works. Next, will link it to user/dataset and fix some minor things.

File size: 4.0 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// set filter values
16$(document).ready(function() {
17
18 // Fastest?: http://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery
19 $.getJSON("/website/filters/",
20 function(json) {
21 $.each(json, function(i,json){
22 $("#select_user").append($("<option/>").attr("value",json.gebruiker).text(json.gebruiker));
23 $.each(json.meetrondje, function(m, meetrondje){
24 $("#select_dataset").append($("<option/>").attr({"class":json.gebruiker, "value":meetrondje.naam}).text(meetrondje.naam));
25 $.each(meetrondje.nodes, function(n, nodes){
26 $("#select_node").append($("<option/>").attr({"class":meetrondje.naam, "value":nodes}).text(nodes));
27 });
28 });
29 });
30 // Initiate the chain
31 $("#select_dataset").chained("#select_user");
32 $("#select_node").chained("#select_dataset");
33 }
34 );
35});
36
37// add filter
38$(function(){
39 $('#add_filter').click(function(){
40
41 user = $('#select_user option:selected').text();
42 dataset = $('#select_dataset option:selected').text();
43 wlnode = $('#select_node option:selected').text();
44// enc = $('#select_enc option:selected').text();
45// date = $('#select_date option:selected').text();
46 start_date = $('#start_date').val();
47 end_date = $('#end_date').val();
48 colour = encodeURIComponent(document.getElementById("colour").value);
49 lname = encodeURIComponent(document.getElementById("lname").value);
50
51 // 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
52 // '#' comes out as '%23', so substr() starts at char 3
53 colour = parseInt((colour.substr(3, 2)),16) + ',' + parseInt((colour.substr(5, 2)),16) + ',' + parseInt((colour.substr(7, 2)),16);
54
55 if (user != ''){user='&meetrondje__gebruiker__naam='+user;}
56 if (dataset != ''){dataset='&meetrondje__naam='+dataset;}
57 if (wlnode != ''){wlnode='&accespoint__ssid='+wlnode;}
58// if (enc != ''){enc='&accespoint__encryptie='+enc;}
59// if (date != ''){date='&meetrondje__datum='+date;}
60 if (start_date && end_date){
61 sd_d=start_date.substr(0,2);
62 sd_m=start_date.substr(3,2);
63 sd_y=start_date.substr(6,4);
64
65 ed_d=end_date.substr(0,2);
66 ed_m=end_date.substr(3,2);
67 ed_y=end_date.substr(6,4);
68
69 start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
70 end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
71 }
72
73
74 if (colour != 'NaN,NaN,NaN'){colour='colour='+colour;}
75 else {colour = '&colour='+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);}
76 if (lname != ''){lname=lname;}
77 else {lname = 'Custom Filter';}
78
79 var baseurl = "/website/tile/${z}/${x},${y}.png?";
80
81 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
82 initialize: function(name, options) {
83 var url = [
84 baseurl + colour + user + dataset + wlnode + start_date + end_date /* + enc */
85 ];
86 document.getElementById('filter_text').innerHTML+="<br />Added: " + url;
87 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
88 var newArguments = [name, url, options];
89 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
90 },
91 CLASS_NAME: "OpenLayers.Layer.Overlay"
92 });
93
94 filterlayer = new OpenLayers.Layer.OSM.Overlay(lname, {isBaseLayer: false, visibility: true});
95 map.addLayer(filterlayer);
96 });
97});
Note: See TracBrowser for help on using the repository browser.