2014-05-06 15:14:30 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* map.js *
|
|
|
|
* script for map specific functions and setup *
|
|
|
|
**********************************************************************/
|
2014-05-06 13:26:47 +02:00
|
|
|
|
2014-05-06 15:14:30 +02:00
|
|
|
/* License
|
2020-07-14 21:13:15 +02:00
|
|
|
Copyright 2020 Kasper D. Fischer <kasper.fischer@rub.de>
|
2014-05-06 13:26:47 +02:00
|
|
|
|
2014-05-06 15:14:30 +02:00
|
|
|
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.
|
2014-05-06 13:26:47 +02:00
|
|
|
|
2014-05-06 15:14:30 +02:00
|
|
|
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
|
2020-07-14 19:31:46 +02:00
|
|
|
with this program. If not, see https://www.gnu.org/licenses/.
|
2014-05-06 15:14:30 +02:00
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
2014-05-06 13:26:47 +02:00
|
|
|
|
|
|
|
/* add station marker */
|
2014-05-14 17:33:43 +02:00
|
|
|
function addStationMarker(id, lat, lng, station) {
|
2015-10-01 17:44:23 +02:00
|
|
|
var marker = L.triangleMarker(L.latLng(lat, lng),
|
2014-05-06 13:26:47 +02:00
|
|
|
{
|
2014-05-14 17:33:43 +02:00
|
|
|
gradient: true,
|
2014-05-14 11:48:04 +02:00
|
|
|
fillColor: config['station']['markerColor'],
|
2014-05-14 17:33:43 +02:00
|
|
|
fillOpacity: config['station']['markerOpacity'],
|
2014-05-14 11:48:04 +02:00
|
|
|
color: config['station']['markerColor'],
|
2014-05-06 13:26:47 +02:00
|
|
|
weight: 1,
|
|
|
|
opacity: 1,
|
2015-09-04 15:13:58 +02:00
|
|
|
radius: config['station']['markerSize'][id] || config['station']['markerSize']['defaultSize'],
|
2014-05-06 13:26:47 +02:00
|
|
|
className: id+' stationMarker',
|
2014-05-14 17:33:43 +02:00
|
|
|
});
|
2020-07-15 18:36:15 +02:00
|
|
|
marker.bindTooltip('Station '+station);
|
2014-05-14 17:33:43 +02:00
|
|
|
stationLayer.addLayer(marker);
|
2014-05-06 13:26:47 +02:00
|
|
|
stationTable[id] = marker;
|
2015-10-01 17:44:23 +02:00
|
|
|
};
|
2014-05-06 13:26:47 +02:00
|
|
|
|
|
|
|
/* add event marker */
|
2014-05-20 13:08:59 +02:00
|
|
|
function addEventMarker(id, lat, lng, mag, type) {
|
2014-05-19 22:08:38 +02:00
|
|
|
if ( eventTable[id] ) {
|
|
|
|
return eventTable[id];
|
|
|
|
} else {
|
|
|
|
var markerOptions = {
|
|
|
|
gradient: true,
|
|
|
|
dropShadow: false,
|
|
|
|
fillColor: config['event']['markerColor'],
|
|
|
|
fillOpacity: config['event']['markerOpacity'],
|
|
|
|
color: config['event']['markerColor'],
|
|
|
|
weight: 0,
|
|
|
|
opacity: 1,
|
|
|
|
className: id+' eventMarker',
|
|
|
|
radius: mag2radius(mag)
|
|
|
|
};
|
2014-05-20 13:08:59 +02:00
|
|
|
var marker;
|
|
|
|
switch ( type ) {
|
|
|
|
case 'earthquake':
|
|
|
|
marker = L.starMarker(L.latLng(lat, lng), markerOptions);
|
2014-09-16 13:11:51 +02:00
|
|
|
break;
|
2020-07-14 19:31:46 +02:00
|
|
|
case 'nuclear explosion':
|
|
|
|
markerOptions['numberOfSides'] = 4;
|
|
|
|
markerOptions['radius'] = 2.0*markerOptions['radius'];
|
|
|
|
markerOptions['innerRadius'] = 0.3*markerOptions['radius'];
|
|
|
|
marker = L.regularPolygonMarker(L.latLng(lat, lng), markerOptions);
|
|
|
|
break;
|
2014-09-16 13:11:51 +02:00
|
|
|
case 'explosion':
|
|
|
|
markerOptions['numberOfSides'] = 6;
|
|
|
|
markerOptions['radius'] = 2.0*markerOptions['radius'];
|
|
|
|
markerOptions['innerRadius'] = 0.3*markerOptions['radius'];
|
|
|
|
marker = L.regularPolygonMarker(L.latLng(lat, lng), markerOptions);
|
2014-05-20 13:08:59 +02:00
|
|
|
break;
|
|
|
|
case 'quarry blast':
|
2020-07-14 19:31:46 +02:00
|
|
|
case 'controlled explosion':
|
2014-05-20 13:08:59 +02:00
|
|
|
markerOptions['numberOfPoints'] = 7;
|
|
|
|
markerOptions['innerRadius'] = 0.3*markerOptions['radius'];
|
|
|
|
marker = L.starMarker(L.latLng(lat, lng), markerOptions);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
marker = L.circleMarker(L.latLng(lat, lng), markerOptions);
|
|
|
|
};
|
2014-05-19 22:08:38 +02:00
|
|
|
eventLayer.addLayer(marker);
|
|
|
|
eventTable[id] = marker;
|
|
|
|
return marker;
|
2014-05-06 13:26:47 +02:00
|
|
|
};
|
2015-10-01 17:44:23 +02:00
|
|
|
};
|
2014-05-06 13:26:47 +02:00
|
|
|
|
|
|
|
/* handle to show events on map */
|
|
|
|
function initMapLink() {
|
2014-05-19 22:08:38 +02:00
|
|
|
$("#eventstable > tbody > tr > td > a.map-link").off('click');
|
2014-05-06 13:26:47 +02:00
|
|
|
$("#eventstable > tbody > tr > td > a.map-link").on('click' , function(){
|
|
|
|
var highlightStyle = {
|
2014-05-08 11:08:48 +02:00
|
|
|
color: config['event']['markerColorH'],
|
|
|
|
fillColor: config['event']['markerColorH'],
|
2014-05-14 17:33:43 +02:00
|
|
|
fillOpacity: 1,
|
2014-05-06 13:26:47 +02:00
|
|
|
className: $(this).attr('eventid')
|
|
|
|
}
|
|
|
|
var normalStyle = {
|
2014-05-08 11:08:48 +02:00
|
|
|
fillColor: config['event']['markerColor'],
|
2014-05-14 17:33:43 +02:00
|
|
|
fillOpacity: config['event']['markerOpacity'],
|
2014-05-08 11:08:48 +02:00
|
|
|
color: config['event']['markerColor']
|
2014-05-06 13:26:47 +02:00
|
|
|
};
|
|
|
|
// mark currently selected link and remove class selected from all other links
|
|
|
|
// set everything to normal state
|
|
|
|
$(this).addClass('selected-now');
|
|
|
|
$("#eventstable > tbody > tr:not(.filtered) > td > a.map-link:not(.selected-now)").each(function(){
|
|
|
|
$(this).removeClass('selected');
|
|
|
|
$(this).text('Karte');
|
|
|
|
eventTable[$(this).attr('eventid')].setStyle(normalStyle);
|
|
|
|
});
|
|
|
|
// switch event of first row to normalStyle if it is not the selected one
|
|
|
|
( $(this).hasClass('first') ) ? null : eventTable[$("#eventstable > tbody > tr:not(.filtered)").first().find("a.map-link").attr("eventid")].setStyle(normalStyle);
|
|
|
|
$(this).each(function(){
|
|
|
|
$(this).removeClass('selected-now');
|
|
|
|
// selected -> unselected
|
|
|
|
if ( $(this).hasClass('selected') ) {
|
|
|
|
$(this).removeClass('selected');
|
|
|
|
$(this).text('Karte');
|
2014-05-06 16:18:20 +02:00
|
|
|
map.setView(config['map']['centerDefault'], config['map']['zoomDefault']);
|
2014-05-19 22:08:38 +02:00
|
|
|
eventTable[$(this).attr('eventid')].setStyle(normalStyle);
|
2014-05-06 13:26:47 +02:00
|
|
|
highlightFirstEvent();
|
|
|
|
// unselected -> selected
|
|
|
|
} else {
|
|
|
|
$(this).addClass('selected');
|
|
|
|
$(this).text('im Fokus (rot)');
|
2014-05-06 16:18:20 +02:00
|
|
|
map.setView(eventTable[$(this).attr('eventid')].getLatLng(), config['map']['zoomFocus']);
|
2014-05-19 22:08:38 +02:00
|
|
|
eventTable[$(this).attr('eventid')].setStyle(highlightStyle)
|
2014-05-06 13:26:47 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-05-06 15:14:30 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* document ready *
|
|
|
|
**********************************************************************/
|
2014-05-06 13:26:47 +02:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
|
|
// create a map in the "map" div, set the view to a given place and zoom
|
2017-12-03 12:22:37 +01:00
|
|
|
|
2014-05-14 17:33:43 +02:00
|
|
|
// create baselayer
|
|
|
|
switch ( config['map']['baselayer'] ) {
|
|
|
|
case 'esrigray': // add ESRI Grayscale World Map (neither city nor road names)
|
2017-12-03 12:22:37 +01:00
|
|
|
map = L.map('map', { zoomControl: false, worldCopyJump: true }).setView(config['map']['centerDefault'], config['map']['zoomDefault']);
|
2014-05-14 17:33:43 +02:00
|
|
|
L.tileLayer('//server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}',
|
|
|
|
{
|
|
|
|
attribution: 'Tiles © Esri — Esri, DeLorme, NAVTEQ',
|
|
|
|
maxZoom: 16
|
|
|
|
}).addTo(map);
|
|
|
|
break;
|
2014-05-19 22:08:38 +02:00
|
|
|
case 'aerial': // add ESRI WordImagery tile layer
|
2017-12-03 12:22:37 +01:00
|
|
|
map = L.map('map', { zoomControl: false, worldCopyJump: true }).setView(config['map']['centerDefault'], config['map']['zoomDefault']);
|
2020-07-14 19:31:46 +02:00
|
|
|
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
|
2014-05-19 22:08:38 +02:00
|
|
|
{
|
|
|
|
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
|
|
|
|
}).addTo(map);
|
|
|
|
break;
|
2020-07-15 18:36:15 +02:00
|
|
|
case 'osmde': // add OpenStreetMap.DE tile layer, default
|
|
|
|
null;
|
|
|
|
default:
|
2017-12-03 12:22:37 +01:00
|
|
|
map = L.map('map', { zoomControl: false, worldCopyJump: true }).setView(config['map']['centerDefault'], config['map']['zoomDefault']);
|
2020-07-15 18:36:15 +02:00
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
|
2015-10-01 13:43:37 +02:00
|
|
|
{
|
2020-07-15 18:36:15 +02:00
|
|
|
attribution: '© <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
|
2015-10-01 13:43:37 +02:00
|
|
|
}).addTo(map);
|
2014-05-14 17:33:43 +02:00
|
|
|
};
|
|
|
|
|
2017-12-03 12:22:37 +01:00
|
|
|
// add controls
|
|
|
|
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
|
|
|
new L.control.scale({position: 'bottomright', imperial: false}).addTo(map);
|
|
|
|
|
2014-05-14 07:22:21 +02:00
|
|
|
// create station and event layer
|
2014-05-14 17:33:43 +02:00
|
|
|
// stationLayer = L.geoJson().addTo(map);
|
|
|
|
stationLayer = new L.MarkerGroup().addTo(map);
|
|
|
|
eventLayer = new L.MarkerGroup().addTo(map);
|
2014-05-14 07:22:21 +02:00
|
|
|
|
|
|
|
// load events
|
2014-06-13 17:02:38 +02:00
|
|
|
ajaxLoadEvents('', '', '', 'events.xml');
|
2014-05-06 13:26:47 +02:00
|
|
|
ajaxLoadEvents();
|
2014-05-20 13:08:59 +02:00
|
|
|
specialEvents.map(function(id) {
|
|
|
|
ajaxLoadEvents('', '', id)
|
|
|
|
});
|
2014-05-06 13:26:47 +02:00
|
|
|
toggleFilteredMarkers();
|
|
|
|
|
|
|
|
// bind popupopen event
|
|
|
|
map.on('popupopen', function() {
|
|
|
|
// convert date/time to localtime
|
|
|
|
$("div.leaflet-popup span.utctime").each(function(){$(this).addClass("localtime").removeClass("utctime");$.localtime.formatObject($(this), "dd.MM.yyyy - HH:mm")});
|
2014-05-12 18:10:29 +02:00
|
|
|
openMarkerID = $("div.leaflet-popup h3").attr("eventid");
|
|
|
|
if ( openMarkerID ) {
|
2014-05-06 13:26:47 +02:00
|
|
|
// update city in popup
|
2014-05-12 18:10:29 +02:00
|
|
|
$("div.leaflet-popup h3").text(geolocationTable[openMarkerID]);
|
|
|
|
// highlight event in table and show details
|
|
|
|
// highlightEvent(eventid);
|
|
|
|
$('#eventstable > tbody > tr > td > a.toggle').each(function() {
|
|
|
|
if ( $(this).attr('eventid') == openMarkerID ) {
|
|
|
|
$(this)[0].click();
|
|
|
|
};
|
|
|
|
});
|
2014-05-06 13:26:47 +02:00
|
|
|
};
|
|
|
|
});
|
2014-05-12 18:10:29 +02:00
|
|
|
map.on('popupclose', function() {
|
|
|
|
$('#eventstable > tbody > tr > td > a.toggle').each(function() {
|
|
|
|
if ( $(this).attr('eventid') == openMarkerID ) {
|
|
|
|
$(this)[0].click();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2014-09-16 13:23:01 +02:00
|
|
|
|
|
|
|
// print icon
|
|
|
|
L.easyPrint().addTo(map);
|
2014-05-06 13:26:47 +02:00
|
|
|
});
|