seisobs-webapp/www/stations.js

148 lines
6.1 KiB
JavaScript
Raw Normal View History

/**********************************************************************
* stations.js *
* script for station specific functions and setup *
**********************************************************************/
/* License
Copyright 2014 Kasper D. Fischer <kasper.fischer@rub.de>
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see http://www.gnu.org/licenses/.
$Id$
*/
/* Load the stations using ajax */
2014-05-06 13:26:47 +02:00
function loadStations(stime, etime) {
var mapBounds = map.getBounds();
var N = mapBounds.getNorth();
var E = mapBounds.getEast();
var S = mapBounds.getSouth();
var W = mapBounds.getWest();
if ( !stime ) {
var stime = new Date();
stime.setDate(stime.getDate()-config['map']['timespan']);
2014-05-06 13:26:47 +02:00
};
if ( !etime ) {
var etime = new Date();
etime.setDate(etime.getDate()+1);
};
var request_data = {
endafter: sprintf("%d-%02d-%02d", stime.getFullYear(), stime.getMonth()+1, stime.getDate()),
startbefore: sprintf("%d-%02d-%02d", etime.getFullYear(), etime.getMonth()+1, etime.getDate()),
minlat: S-config['map']['latlngDelta'],
maxlat: N+config['map']['latlngDelta'],
minlon: W-config['map']['latlngDelta'],
maxlon: E+config['map']['latlngDelta'],
2014-05-06 13:26:47 +02:00
};
$.ajax({
type: "GET",
url: config['ajax']['stationURL'],
2014-05-06 13:26:47 +02:00
dataType: "xml",
data: request_data,
success: function (xml) {
$(xml).find('Network').each(function () {
var network = $(this).attr('code');
$(this).find('Station').each(function () {
var station = $(this).attr('code'),
lat = $(this).find('Latitude').text(),
lng = $(this).find('Longitude').text(),
stationID = network+'_'+station,
stationText = network+'.'+station;
2014-05-06 13:26:47 +02:00
if ( !stationTable[stationID] ) { // && N >= lat && S <= lat && W<= lng && E >= lng
var row = sprintf('<tr><td>%s</td><td>%s</td><td class="ar">%7.4f</td><td class="ar">%7.4f</td></tr>' , network, station, Number(lat), Number(lng));
var r = $(row);
$('#stationstable tbody').append(r);
addStationMarker(stationID, Number(lat), Number(lng), stationText.toUpperCase());
2014-05-06 13:26:47 +02:00
};
});
});
},
complete: function () {
initStationTable();
var sort = [[0,0],[1,0]];
$("#stationstable").trigger("update", [true]);
$("#stationstable").trigger("updateCache");
$("#stationstable").trigger("sorton", [sort]);
$("#stationstable > tbody > tr:even").addClass("odd");
$("#stationstable > tbody > tr:odd").addClass("even");
stationLayer.bringToFront();
2014-05-06 13:26:47 +02:00
}
});
};
/* initStationTable */
2014-05-06 13:26:47 +02:00
function initStationTable() {
// tablesorter for station list
$("#stationstable").tablesorter(
{
theme : 'blue',
cssChildRow: "tablesorter-childRow", // this is the default setting
widgets: ["uitheme", "zebra", "filter", "pager"], // initialize zebra and filter widgets, "scroller"
widgetOptions: {
// output default: '{page}/{totalPages}'
// possible variables: {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows}
pager_output: '# {startRow} - {endRow} ({totalRows}) | Seite {page} ({totalPages})',
// apply disabled classname to the pager arrows when the rows at either extreme is visible
pager_updateArrows: true,
// starting page of the pager (zero based index)
pager_startPage: 0,
// Number of visible rows
pager_size: 35,
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
pager_savePages: true,
// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
// table row set to a height to compensate; default is false
pager_fixedHeight: false,
// remove rows from the table to speed up the sort of large tables.
// setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
pager_removeRows: false,
// css class names of pager arrows
pager_css: {
container : 'stations-tablesorter-pager',
errorRow : 'tablesorter-errorRow', // error information row (don't include period at beginning)
disabled : 'disabled' // class added to arrows @ extremes (i.e. prev/first arrows "disabled" on first page)
},
// jQuery pager selectors
pager_selectors: {
container : '.stationspager', // target the pager markup (wrapper)
first : '.stationsfirst', // go to first page arrow
prev : '.stationsprev', // previous page arrow
next : '.stationsnext', // next page arrow
last : '.stationslast', // go to last page arrow
goto : '.stationsgotoPage', // go to page selector - select dropdown that sets the current page
pageDisplay : '.stationspagedisplay', // location of where the "output" is displayed
pageSize : '.stationspagesize' // page size selector - select dropdown that sets the "size" option
},
filter_childRows : true,
filter_cssFilter : 'tablesorter-filter',
filter_startsWith : false,
filter_ignoreCase : true,
scroller_height: $('div.map').height() - 250,
scroller_barWidth: 10,
scroller_jumpToHeader: false,
sortList: "[[0,0], [1,0]]",
resort: true,
showProcessing: true,
}
});
};
/**********************************************************************
* document ready *
**********************************************************************/
2014-05-06 13:26:47 +02:00
$(document).ready(function() {
loadStations();
});