seisobs-webapp/www/misc.js

252 lines
9.3 KiB
JavaScript
Raw Normal View History

/**********************************************************************
* misc.js *
* script for unspecific functions and setup *
**********************************************************************/
/* License
Copyright 2014-2023 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/.
2021-10-17 16:56:58 +02:00
Version VVVVV
*/
/* calculate marker radius from magnitude
* both formulas have equal radii at mag=1.2 */
2014-05-06 13:26:47 +02:00
function mag2radius(mag) {
2020-07-15 09:59:49 +02:00
return 3*mag; // radius proportional to magnitude
2014-05-06 13:26:47 +02:00
// return 8.104*Math.pow(30,mag) // radius proportional to energy
};
/* set height of eventlist div */
2014-05-06 13:26:47 +02:00
function setInfoHeight() {
var height = $('div.map').height() - 36;
$('div.info').height(height);
};
/* get region and regionID of a location */
function getLocation(lat, lng) {
var region = false;
var regionID;
var regions = [
['Monschau', 'Schleiden', 'Bad Münstereifel', 'Rheinland-Pfalz', 'Rheinland-Pfalz', 'Rheinland-Pfalz', 'Hessen', 'Hessen', 'Hessen', 'Hessen'],
['Aachen', 'Zülpich', 'Euskirchen', 'Bonn', 'Rheinland-Pfalz', 'Rheinland-Pfalz', 'Hessen', 'Hessen', 'Hessen', 'Hessen'],
['Geilenkirchen', 'Düren', 'Köln', 'Köln-Mülheim', 'Waldbröl', 'Freudenberg', 'Siegen', 'Hessen', 'Hessen', 'Hessen'],
['Heinsberg', 'Mönchengladbach', 'Neuss', 'Solingen', 'Gummersbach', 'Olpe', 'Schmallenberg', 'Bad Berleburg', 'Hessen', 'Hessen'],
['Nettetal', 'Krefeld', 'Düsseldorf', 'Wuppertal', 'Hagen', 'Iserlohn', 'Arnsberg', 'Brilon', 'Hessen', 'Hessen'],
['Geldern', 'Moers', 'Duisburg', 'Essen', 'Dortmund', 'Unna', 'Soest', 'Büren', 'Marsberg', 'Warburg'],
['Kleve', 'Wesel', 'Dorsten', 'Recklinghausen', 'Lünen', 'Hamm/Westfalen', 'Beckum', 'Lippstadt', 'Paderborn', 'Bad Driburg'],
['Emmerich am Rhein', 'Bocholt', 'Borken', 'Coesfeld', 'Münster', 'Warendorf', 'Rheda-Wiedenbrück', 'Gütersloh', 'Detmold', 'Bad Pyrmont'],
['The Netherlands', 'The Netherlands', 'Vreden', 'Ahaus', 'Steinfurt', 'Lengerich', 'Bad Ilburg', 'Bielefeld', 'Herford', 'Niedersachsen'],
['The Netherlands', 'The Netherlands', 'The Netherlands', 'Niedersachsen', 'Rheine', 'Ibbenbüren', 'Niedersachsen', 'Lübbecke', 'Minden', 'Niedersachsen']
];
if ( lat >= 50.4 && lat < 52.4 && lng >= 6.0 && lng < 9.333333 ) {
var latIndex = Math.floor((lat-50.4)*5); // 5 tiles per degree
var lngIndex = Math.floor((lng-6.0)*3); // 3 tiles per degree
region = regions[latIndex][lngIndex];
};
if ( region != 'The Netherlands' ) {
regionID = 5500-latIndex*200+lngIndex*2+2;
};
if ( lat >= 50.9 && lat < 51.1 && lng >= 5.666666 && lng < 6.0 ) {
region = 'Selfkant';
regionID = 5000;
};
return [ region, regionID ];
};
/* window resize */
2020-07-15 13:57:51 +02:00
$( window ).on('resize', function() { setInfoHeight(); });
2014-05-06 13:26:47 +02:00
/* parseQueryString */
function parseQueryString() {
var query = (window.location.search || '?').substr(1),
map = {};
query.replace(/([^&=]+)=?([^&]*)(?:&+|$)/g, function(match, key, value) {
key.toLowerCase();
(map[key] = map[key] || []).push(value);
});
return map;
}
/* create global vars */
2021-10-17 16:56:58 +02:00
var jahr = new Date().getFullYear();
var map;
var openMarkerID;
2014-05-06 13:26:47 +02:00
var eventTable = {};
var eventDetails = {};
var stationTable = {};
var config = {
ajax: {
timeout: 20000, // 20 seconds
2020-07-14 19:31:46 +02:00
eventURL: 'https://fdsnws.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query',
dlsvURL: 'dlsv',
2020-07-14 19:31:46 +02:00
mseedURL: 'https://fdsnws.geophysik.ruhr-uni-bochum.de/fdsnws/dataselect/1/query',
stationURL: 'https://fdsnws.geophysik.ruhr-uni-bochum.de/fdsnws/station/1/query',
nominatimURL: 'https://photon.komoot.io/reverse',
timespan: 400,
},
event: {
2014-05-07 14:30:27 +02:00
evaluationBlacklist: ['automatic', 'preliminary', 'rejected'],
markerOpacity: 0.4,
markerColor: 'blue',
markerColorH: 'red',
minMag: 0.7,
minMagDelta: 0.1,
2020-07-14 19:31:46 +02:00
typeWhitelist: ['earthquake', 'induced or triggered event', 'controlled explosion'],
// typeWhitelist: ['earthquake', 'induced or triggered event', 'controlled explosion', 'nuclear explosion'],
// typeWhitelist: ['earthquake', 'induced or triggered event'],
},
map: {
zoomDefault: 9,
zoomFocus: 12,
centerDefault: [51.85, 7.0],
timespan: 180,
latlngDelta: 0.1,
baselayer: 'OpenStreetMap.DE',
},
station: {
markerColor: 'darkgreen',
markerOpacity: 1,
markerSize: {
defaultSize: 8,
GE_IBBN: 10,
GR_BUG: 10,
GR_KAST: 10,
NL_HGN: 3,
NL_OPLO: 3,
NL_VKB: 3,
NL_WIT: 3,
NL_WTSB: 3,
},
2020-07-14 19:31:46 +02:00
networkBlacklist: ['NL', 'X5', '1A', 'AM'],
stationBlacklist: ['RN_WEA2', 'RN_ACN', 'RN_BHE', 'RN_ENT', 'RN_GSH', 'RN_HES', 'RN_JCKS', 'RN_LOH',
'RN_OLF', 'RN_PLH', 'RN_RWB', 'RN_SOR', 'RN_TDN', 'RN_WBS',
'RN_HAM1', 'RN_HAM2', 'RN_HAM3', 'RN_HAM4', 'RN_HAM5', 'RN_HAM6', 'RN_HAM7', 'RN_HAM8', 'RN_HAM9',
'RN_HAM10', 'RN_HAM11', 'RN_HAM12', 'RN_HAM13', 'RN_HAM14', 'RN_HAM15', 'RN_HAM16', 'RN_HAM17'],
},
tab: {
active: 0,
disabled: [2],
max: 4,
},
};
var networkURL = {
GE: 'http://dx.doi.org/10.14470/TR560404',
GR: 'http://www.bgr.bund.de/DE/Themen/Erdbeben-Gefaehrdungsanalysen/Seismologie/Seismologie/Seismometer_Stationen/Stationsnetze/d_stationsnetz_node.html',
2020-07-14 19:31:46 +02:00
NH: 'http://www.gd.nrw.de/gg_le.htm',
NL: 'http://www.knmi.nl/seismologie/seismisch_network_knmi3.html',
2020-07-14 19:31:46 +02:00
RN: 'https://doi.org/10.7914/SN/RN',
YD: 'https://doi.org/10.7914/SN/YD_2020',
};
var networkText = {
2020-07-14 19:31:46 +02:00
GE: '<a href="'+networkURL['GE']+'" target="_blank">GEOFON Seismic Network</a> - Deutsches GeoForschungsZentrum GFZ',
GR: '<a href="'+networkURL['GR']+'" target="_blank">German Regional Seismic Network</a>, BGR Hannover',
2020-07-14 19:31:46 +02:00
NH: '<a href="'+networkURL['NH']+'" target="_blank">Geologischer Dienst NRW</a>, Krefeld',
NL: '<a href="'+networkURL['NL']+'" target="_blank">Netherlands Seismic Network</a>, The Netherlands',
2020-07-14 19:31:46 +02:00
RN: '<a href="'+networkURL['RN']+'" target="_blank">RuhrNet - Ruhr-University Bochum, Germany</a>',
YD: '<a href="'+networkURL['YD']+'" target="_blank">FloodRisk Seismic Network</a>',
};
var bochumStation = ['BUG', 'IBBN', 'KERA', 'KARP'];
2014-05-06 13:26:47 +02:00
// FIX: firefox has no console
if (typeof console == "undefined") var console = { log: function() {} };
/**********************************************************************
* document ready *
**********************************************************************/
2014-05-06 13:26:47 +02:00
$(document).ready(function() {
// parse query string
var parameters = parseQueryString();
2020-07-15 09:59:49 +02:00
if ( parameters['baselayer']) {
config['map']['baselayer'] = parameters['baselayer'][0];
};
2020-07-15 13:57:51 +02:00
if ( parameters['basemap'] ) {
2020-07-15 09:59:49 +02:00
config['map']['baselayer'] = parameters['basemap'][0];
};
if ( Number(parameters['lat']) && Number(parameters['lon']) ) {
config['map']['centerDefault'] = [Number(parameters['lat']), Number(parameters['lon'])];
};
if ( Number(parameters['minmag']) ) {
config['event']['minMag'] = Number(parameters['minmag']);
};
if ( parameters['eventcolor'] ) {
config['event']['markerColor'] = parameters['eventcolor'];
};
if ( parameters['eventcolorh'] ) {
config['event']['markerColorH'] = parameters['eventcolorh'];
};
if ( parameters['stationcolor'] ) {
config['station']['markerColor'] = parameters['stationcolor'];
};
if ( Number(parameters['timespan']) ) {
config['map']['timespan'] = Number(parameters['timespan']);
};
if ( Number(parameters['tab']) ) {
if ( Number(parameters['tab']) < config['tab']['max'] ) {
config['tab']['active'] = Number(parameters['tab']);
};
};
if ( Number(parameters['zoom']) ) {
config['map']['zoomDefault'] = Number(parameters['zoom']);
config['map']['zoomFocus'] = Number(parameters['zoom'])+3;
};
2014-05-06 13:26:47 +02:00
// AJAX setup
$.ajaxSetup({timeout: config['ajax']['timeout']});
2014-05-06 13:26:47 +02:00
// adjust height of infocontainer
setInfoHeight();
2014-05-06 13:26:47 +02:00
// create tabs
$('#tabs').tabs({
active: config['tab']['active'],
disabled: config['tab']['disabled'],
activate: function( event, ui ) { ui['newPanel'].find('table').trigger("update", [true]); },
});
// create accordions
$( '#infoaccordion' ).accordion({
active: 0,
header: 'h3.aheader',
heightStyle: 'content',
animate: 200,
});
2014-09-23 18:00:18 +02:00
// spinner
2020-07-15 13:57:51 +02:00
$(document).on("ajaxSend", function() {
2014-09-23 18:00:18 +02:00
$("#spinner").show();
2020-07-15 13:57:51 +02:00
}).on("ajaxStop", function() {
2014-09-23 18:00:18 +02:00
$("#spinner").hide();
});
// load more tab content
$.get("more_de.md", function( data ) {
var converter = new showdown.Converter();
$('.more_de').html(converter.makeHtml(data));
});
$.get("more_en.md", function( data ) {
var converter = new showdown.Converter();
$('.more_en').html(converter.makeHtml(data));
});
// load info tab content
$.get("info.inc.de", function( data ) {
$('.info_de, .info_en').html(data);
});
$.get("copyright.inc.de", function( data ) {
$('.copyright_de, .copyright_en').html(data);
});
$.get("impressum.inc.de", function( data ) {
$('.imprint_de, .imprint_en').html(data);
});
});