/* do reverse geolocation lookup */ function getGeolocation(id, lat, lng) { if ( !geolocationTable[id] ) { // $.getJSON( "//nominatim.openstreetmap.org/reverse", { lat: lat, lon: lng, zoom: 10, format: "json" } ) $.getJSON( "//open.mapquestapi.com/nominatim/v1/reverse.php", { lat: lat, lon: lng, zoom: 10, format: "json" } ) .done(function( json ) { var city = json.address["city"]; var country = json.address["country"]; var countryCode = json.address["country_code"].toUpperCase(); geolocationTable[id] = city; ( country != "Deutschland" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null; if ( city ) { $("#eventstable a.toggle[eventid="+id+"]").text(geolocationTable[id]); var sort = [[0,1],[1,1],[2,1]]; $("#eventstable").trigger("update", [true]); $("#eventstable").trigger("updateCache"); $("#eventstable").trigger("sorton", [sort]); } else { console.log("Nominatim did not provide a city tag for "+lat+" / "+lng); }; }) .fail(function( jqxhr, textStatus, error ) { var err = textStatus + ", " + error; console.log( "Request Failed: " + err ); }); }; }; /* Load events using ajax */ function ajaxLoadEvents(stime, etime) { var mapBounds = map.getBounds(); var N = mapBounds.getNorth(); var E = mapBounds.getEast(); var S = mapBounds.getSouth(); var W = mapBounds.getWest(); var d = 0.1; if ( !stime ) { var stime = new Date(); stime.setDate(stime.getDate()-180); }; if ( !etime ) { var etime = new Date(); etime.setDate(etime.getDate()+1); }; var url = "https://ariadne.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query" var request_data = { starttime: sprintf("%d-%02d-%02d", stime.getFullYear(), stime.getMonth()+1, stime.getDate()), endtime: sprintf("%d-%02d-%02d", etime.getFullYear(), etime.getMonth()+1, etime.getDate()), minlat: S-d, maxlat: N+d, minlon: W-d, maxlon: E+d, minmag: minMag-0.1, }; $.ajax({ type: "GET", url: url, data: request_data, dataType: "xml", success: function (xml) { $(xml).find('event').each(function () { var id = $(this).attr('publicID').split('/')[2]; var mag = $(this).find('magnitude > mag > value').text(); var otime = $(this).find('origin > time > value').text(); var lng = $(this).find('origin > longitude > value').text(); var lat = $(this).find('origin > latitude > value').text(); var mag = $(this).find('magnitude > mag > value').text(); var evaluationMode = $(this).find('evaluationMode').text(); var evaluationStatus = $(this).find('evaluationStatus').text(); var type = $(this).find('type').last().text(); var location = getLocation(Number(lat), Number(lng))[0]; ( location ) ? null : location = $(this).find('description > text').text(); // create table row: Date, Time, Mag, Location if ( !eventTable[id] && ( type == 'earthquake' || type == 'induced or triggered event' || type == 'outside of network interest') && evaluationMode != 'automatic' && evaluationStatus != 'preliminary' && Number(mag)+0.05 >= minMag ) { var row = '
Ereignis: %s', id) + sprintf('Ort: %.4f °N, %.4f °O ', Number(lat), Number(lng)) + sprintf('Zeit: %sZ
', otime.split('.')[0], otime.split('.')[0]); marker.bindPopup(text); // try to get better location with reverse geolocation lookup (nominatim), check cache first ( geolocationTable[id] ) ? $("#eventstable a.toggle[eventid="+id+"]").text(geolocationTable[id]) : getGeolocation(id, lat, lng); }; }); }, complete: function () { initStationTable(); var sort = [[0,1],[1,1],[2,1]]; $("#eventstable").trigger("update", [true]); $("#eventstable").trigger("updateCache"); $("#eventstable").trigger("sorton", [sort]); initMapLink(); }, error: function( jqxhr, textStatus, error ) { var err = textStatus + ", " + error; console.log( "Request Failed: " + err ); } }); }; // add row to table function addEventRow(id, props) { $('#eventstable').tablesorter({ sortList: "[[0,0], [1,1]], [2,1]", resort: true, showProcessing: true, pager_size: 35 }); var html = 'ID "+id+"\n\n" + "Origin\n" + "Date "+props.date+"\n" + "Time "+props.time+"\n" + "Latitude "+props.lat+" deg +/- "+props.lat_err+" km\n" + "Longitude "+props.lon+" deg +/- "+props.lon_err+" km\n" + "Depth "+props.depth+" km +/- "+props.depth_err+" km\n" + "Residual RMS "+props.rms+" s\n" + "Azimuthal gap "+props.gap+" deg\n\n" + props.no_phases + " Phase arrivals:\n" + "sta net dist azi phase time res wt sta\n"; for ( i = 0 ; i < props.no_phases ; i++ ) { html += props.phases[i]; ( i < props.no_phases -1 ) ? html += "\n" : null ; }; html += "