/** * Uses zoomleven and mouseposition to call nodelist.py view. * View returns nodes in json format, values are printed in doc element. */ function getNodeList(zoomlevel, mousepos){ $.getJSON("/website/nodelist/" + zoomlevel + "," + mousepos.lat + "," + mousepos.lon, function(json){ content = 'Wireless Leiden nodes on mouseposition:
'; $.each(json, function(i,json){ content += json.fields.ssid + '
'; }); content += '
'; $("#node_list").html(content); } ); } /** * Right way to get url parameters? * http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery/1404100#1404100 */ function getURLParameter(name) { return decodeURI( (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] ); } $(document).ready(function() { var signallayer = ''; var userlist = new Array(); var nodelist = new Array(); /** * Adds colourpicker for layer colour. * Function set in: 'colourpicker.js' */ $("#colour").colorPicker(); /** * Adds datepicker for start & end date * Function set in: 'jquery-ui-1.8.13.custom.min.js' */ $("#start_date").datepicker({ dateFormat: "dd/mm/yy", onSelect: function(dateValue, inst){ $("#end_date").datepicker("option", "minDate", dateValue); } }); $("#end_date").datepicker({ dateFormat: "dd/mm/yy", }); /** * Adds slider for signal strength layer. * Function set in: 'jquery-ui-1.8.13.custom.min.js' */ $("#slider").slider({ range: true, min: 0, max: 100, values: [0, 100], // while sliding, it changes the text above the slider to show the values realtime slide: function(event, sig){ $("#sig_value").text("Signal strength: " + sig.values[0] + " - " + sig.values[1]); $("#signallayer font").text("Signal strength: " + sig.values[0] + " - " + sig.values[1]); }, // on slider stop, it sets a new URL with updated values and redraws the layer stop: function(event, sig){ signallayer = map.getLayersByName('signallayer'); signallayer[0].setUrl("/website/tile/${z}/${x},${y}.png?colour=250,250,0&signaal__gte=" + sig.values[0] + "&signaal__lte=" + sig.values[1]); signallayer[0].redraw(); }, }); /** * Toggles layer visibility on checkbox use from layerswitcher. */ $("#togglelayer").live('click', function(){ status = $(this).attr("checked"); layername = $(this).parents('span').attr('id'); layer = map.getLayersByName(layername); layer[0].setVisibility(status); }); /** * Toggles layer visibility per category on checkbox use from layerswitcher. */ $("#togglecat").live("click", function(){ if($(this).attr("checked")){ status = true; } else{ status = false; } layertype = $(this).attr('class'); layers = new Array(); layers = $('#' + layertype).children('span'); $.each(layers, function(l, layer){ layer = map.getLayersByName(layer.id); layer[0].setVisibility(status); $(this).children('input').attr('checked', status); }); }); /** * Removes layer from map and layerswitcher. */ $("#rmvlayer").live("click", function(){ layername = $(this).closest('span').attr('id'); layer = map.getLayersByName(layername); map.removeLayer(layer[0]); $(this).closest('span').remove(); }); /** * Toggles text shown on website. * 'info' shows info text. * 'filter' page shows text on filters & filter options. */ $("#menu_filter").click(function(){ $("#filter").slideToggle("fast"); $("#info").slideUp("fast"); }); $("#menu_info").click(function(){ $("#filter").slideUp("fast"); $("#info").slideToggle("fast"); }); /** * Toggles layerswitcher visibility. * On 'off', toggler shows a '+'. * On 'on', toggler shows a '-'. */ $("#layer_switcher_toggle").click(function(){ $("#layer_switcher").toggle(); if($(this).text() == '+'){ $(this).html('-'); } else{ $(this).html('+'); } }); /** * Toggles category visibility. * On 'visible', toggler shows a '^'. * On 'invisible', toggler shows a 'v'. */ $("#cat_hide").live("click", function(){ cat = $(this).parent('div').next('p').children('span') cat.toggle(); if(cat.is(":visible")){ //FIXME: images are getting loaded the hard way. Replace '/static/'. '{{ STATIC_URL }}' doesn't seem to work here. $(this).css('background-image', "url(/static/img/up.png)"); } else{ $(this).css('background-image', "url(/static/img/down.png)"); } }); /** * Fastest? * http://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery */ $.getJSON("/website/filters/", function(json) { $.each(json, function(i,json){ $("#select_user").append($("