2017-01-29 23:51:08 +00:00
|
|
|
|
define(['map/clientlayer', 'map/labelslayer', 'leaflet', 'moment/moment', 'locationmarker', 'rbush', 'helper', 'leaflet.label', 'moment/locale/de'],
|
2016-05-26 16:39:26 +00:00
|
|
|
|
function (ClientLayer, LabelsLayer, L, moment, LocationMarker, rbush, helper) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
var options = {
|
|
|
|
|
worldCopyJump: true,
|
|
|
|
|
zoomControl: false
|
|
|
|
|
};
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
var LocateButton = L.Control.extend({
|
2016-05-22 12:51:30 +00:00
|
|
|
|
options: {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
position: 'bottomright'
|
2016-05-22 12:51:30 +00:00
|
|
|
|
},
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
active: false,
|
|
|
|
|
button: undefined,
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
initialize: function (f, o) {
|
|
|
|
|
L.Util.setOptions(this, o);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
this.f = f;
|
|
|
|
|
},
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
onAdd: function () {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
var button = L.DomUtil.create('button', 'ion-android-locate shadow');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
L.DomEvent.disableClickPropagation(button);
|
2017-01-29 23:51:08 +00:00
|
|
|
|
L.DomEvent.addListener(button, 'click', this.onClick, this);
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
this.button = button;
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
return button;
|
|
|
|
|
},
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
update: function () {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
this.button.classList.toggle('active', this.active);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
},
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
set: function (v) {
|
|
|
|
|
this.active = v;
|
|
|
|
|
this.update();
|
|
|
|
|
},
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
onClick: function () {
|
|
|
|
|
this.f(!this.active);
|
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
});
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2015-11-09 09:01:20 +00:00
|
|
|
|
var CoordsPickerButton = L.Control.extend({
|
|
|
|
|
options: {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
position: 'bottomright'
|
2015-11-09 09:01:20 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
active: false,
|
|
|
|
|
button: undefined,
|
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
initialize: function (f, o) {
|
|
|
|
|
L.Util.setOptions(this, o);
|
2016-05-22 11:23:43 +00:00
|
|
|
|
this.f = f;
|
2015-11-09 09:01:20 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onAdd: function () {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
var button = L.DomUtil.create('button', 'ion-pin shadow');
|
2015-11-09 09:01:20 +00:00
|
|
|
|
|
2015-12-30 07:21:46 +00:00
|
|
|
|
// Click propagation isn't disabled as this causes problems with the
|
|
|
|
|
// location picking mode; instead propagation is stopped in onClick().
|
2017-01-29 23:51:08 +00:00
|
|
|
|
L.DomEvent.addListener(button, 'click', this.onClick, this);
|
2015-11-09 09:01:20 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
this.button = button;
|
2015-11-09 09:01:20 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
return button;
|
2015-11-09 09:01:20 +00:00
|
|
|
|
},
|
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
update: function () {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
this.button.classList.toggle('active', this.active);
|
2015-11-09 09:01:20 +00:00
|
|
|
|
},
|
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
set: function (v) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
this.active = v;
|
|
|
|
|
this.update();
|
2015-11-09 09:01:20 +00:00
|
|
|
|
},
|
|
|
|
|
|
2015-12-30 07:21:46 +00:00
|
|
|
|
onClick: function (e) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
L.DomEvent.stopPropagation(e);
|
|
|
|
|
this.f(!this.active);
|
2015-11-09 09:01:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
});
|
2015-11-09 09:01:20 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function mkMarker(dict, iconFunc, router) {
|
|
|
|
|
return function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var m = L.circleMarker([d.nodeinfo.location.latitude, d.nodeinfo.location.longitude], iconFunc(d));
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
m.resetStyle = function resetStyle() {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
m.setStyle(iconFunc(d));
|
|
|
|
|
};
|
2015-03-25 01:15:17 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
m.on('click', router.node(d));
|
2016-05-22 11:23:43 +00:00
|
|
|
|
m.bindLabel(d.nodeinfo.hostname);
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
dict[d.nodeinfo.node_id] = m;
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
return m;
|
|
|
|
|
};
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function addLinksToMap(dict, linkScale, graph, router) {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
graph = graph.filter(function (d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
return 'distance' in d && d.type !== 'VPN';
|
2016-05-22 11:23:43 +00:00
|
|
|
|
});
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 21:32:05 +00:00
|
|
|
|
return graph.map(function (d) {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
var opts = {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
color: d.type === 'Kabel' ? '#50B0F0' : linkScale(d.tq).hex(),
|
2016-05-22 12:51:30 +00:00
|
|
|
|
weight: 4,
|
|
|
|
|
opacity: 0.5,
|
2017-01-29 23:51:08 +00:00
|
|
|
|
dashArray: 'none'
|
2016-05-22 12:51:30 +00:00
|
|
|
|
};
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var line = L.polyline(d.latlngs, opts);
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
line.resetStyle = function resetStyle() {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
line.setStyle(opts);
|
|
|
|
|
};
|
2015-03-25 01:15:17 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
line.bindLabel(d.source.node.nodeinfo.hostname + ' – ' + d.target.node.nodeinfo.hostname + '<br><strong>' + helper.showDistance(d) + ' / ' + helper.showTq(d) + '</strong>');
|
|
|
|
|
line.on('click', router.link(d));
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
dict[d.id] = line;
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
return line;
|
|
|
|
|
});
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-09-17 17:59:18 +00:00
|
|
|
|
var iconOnline = {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
color: '#1566A9',
|
|
|
|
|
fillColor: '#1566A9',
|
2016-09-17 17:59:18 +00:00
|
|
|
|
radius: 6,
|
|
|
|
|
fillOpacity: 0.5,
|
|
|
|
|
opacity: 0.5,
|
|
|
|
|
weight: 2,
|
2017-01-29 23:51:08 +00:00
|
|
|
|
className: 'stroke-first'
|
2016-09-17 17:59:18 +00:00
|
|
|
|
};
|
|
|
|
|
var iconOffline = {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
color: '#D43E2A',
|
|
|
|
|
fillColor: '#D43E2A',
|
2016-09-17 17:59:18 +00:00
|
|
|
|
radius: 3,
|
|
|
|
|
fillOpacity: 0.5,
|
|
|
|
|
opacity: 0.5,
|
|
|
|
|
weight: 1,
|
2017-01-29 23:51:08 +00:00
|
|
|
|
className: 'stroke-first'
|
2016-09-17 17:59:18 +00:00
|
|
|
|
};
|
|
|
|
|
var iconLost = {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
color: '#D43E2A',
|
|
|
|
|
fillColor: '#D43E2A',
|
2016-09-17 17:59:18 +00:00
|
|
|
|
radius: 4,
|
|
|
|
|
fillOpacity: 0.8,
|
|
|
|
|
opacity: 0.8,
|
|
|
|
|
weight: 1,
|
2017-01-29 23:51:08 +00:00
|
|
|
|
className: 'stroke-first'
|
2016-09-17 17:59:18 +00:00
|
|
|
|
};
|
|
|
|
|
var iconAlert = {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
color: '#D43E2A',
|
|
|
|
|
fillColor: '#D43E2A',
|
2016-09-17 17:59:18 +00:00
|
|
|
|
radius: 5,
|
|
|
|
|
fillOpacity: 0.8,
|
|
|
|
|
opacity: 0.8,
|
|
|
|
|
weight: 2,
|
2017-01-29 23:51:08 +00:00
|
|
|
|
className: 'stroke-first'
|
2016-09-17 17:59:18 +00:00
|
|
|
|
};
|
2017-01-29 23:51:08 +00:00
|
|
|
|
var iconNew = { color: '#1566A9', fillColor: '#93E929', radius: 6, fillOpacity: 1.0, opacity: 0.5, weight: 2 };
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2015-07-06 23:56:11 +00:00
|
|
|
|
return function (config, linkScale, sidebar, router, buttons) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var self = this;
|
|
|
|
|
var barycenter;
|
2017-01-29 23:51:08 +00:00
|
|
|
|
var groupOnline;
|
|
|
|
|
var groupOffline;
|
|
|
|
|
var groupNew;
|
|
|
|
|
var groupLost;
|
|
|
|
|
var groupLines;
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var savedView;
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
var map;
|
|
|
|
|
var userLocation;
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var layerControl;
|
|
|
|
|
var baseLayers = {};
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
var locateUserButton = new LocateButton(function (d) {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
enableTracking();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
} else {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
disableTracking();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
});
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var mybuttons = [];
|
2015-07-06 23:56:11 +00:00
|
|
|
|
|
|
|
|
|
function addButton(button) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var el = button.onAdd();
|
|
|
|
|
mybuttons.push(el);
|
|
|
|
|
buttons.appendChild(el);
|
2015-07-06 23:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearButtons() {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
mybuttons.forEach(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
buttons.removeChild(d);
|
|
|
|
|
});
|
2015-07-06 23:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 09:01:20 +00:00
|
|
|
|
var showCoordsPickerButton = new CoordsPickerButton(function (d) {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
enableCoords();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
} else {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
disableCoords();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
});
|
2015-11-09 09:01:20 +00:00
|
|
|
|
|
2015-04-19 14:54:35 +00:00
|
|
|
|
function saveView() {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
savedView = {
|
|
|
|
|
center: map.getCenter(),
|
|
|
|
|
zoom: map.getZoom()
|
|
|
|
|
};
|
2015-04-19 14:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function enableTracking() {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
map.locate({
|
|
|
|
|
watch: true,
|
|
|
|
|
enableHighAccuracy: true,
|
|
|
|
|
setView: true
|
|
|
|
|
});
|
2016-05-22 11:23:43 +00:00
|
|
|
|
locateUserButton.set(true);
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function disableTracking() {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
map.stopLocate();
|
|
|
|
|
locationError();
|
|
|
|
|
locateUserButton.set(false);
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2015-11-09 09:01:20 +00:00
|
|
|
|
function enableCoords() {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
map.getContainer().classList.add('pick-coordinates');
|
|
|
|
|
map.on('click', showCoordinates);
|
2016-05-22 11:23:43 +00:00
|
|
|
|
showCoordsPickerButton.set(true);
|
2015-11-09 09:01:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function disableCoords() {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
map.getContainer().classList.remove('pick-coordinates');
|
|
|
|
|
map.off('click', showCoordinates);
|
2016-05-22 11:23:43 +00:00
|
|
|
|
showCoordsPickerButton.set(false);
|
2015-11-09 09:01:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showCoordinates(e) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
router.gotoLocation(e.latlng);
|
|
|
|
|
disableCoords();
|
2015-11-09 09:01:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function locationFound(e) {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (!userLocation) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
userLocation = new LocationMarker(e.latlng).addTo(map);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
userLocation.setLatLng(e.latlng);
|
|
|
|
|
userLocation.setAccuracy(e.accuracy);
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function locationError() {
|
|
|
|
|
if (userLocation) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
map.removeLayer(userLocation);
|
|
|
|
|
userLocation = null;
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-04 17:08:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-22 14:36:14 +00:00
|
|
|
|
function contextMenuOpenLayerMenu() {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
document.querySelector('.leaflet-control-layers').classList.add('leaflet-control-layers-expanded');
|
2016-02-25 14:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
var el = document.createElement('div');
|
|
|
|
|
el.classList.add('map');
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
map = L.map(el, options);
|
2016-09-17 17:59:18 +00:00
|
|
|
|
var now = new Date();
|
|
|
|
|
config.mapLayers.forEach(function (item, i) {
|
2017-01-07 02:09:14 +00:00
|
|
|
|
if ((typeof item.config.start === 'number' && item.config.start <= now.getHours()) || (typeof item.config.end === 'number' && item.config.end > now.getHours())) {
|
2016-09-17 17:59:18 +00:00
|
|
|
|
item.config.order = item.config.start * -1;
|
|
|
|
|
} else {
|
|
|
|
|
item.config.order = i;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
config.mapLayers = config.mapLayers.sort(function (a, b) {
|
|
|
|
|
return a.config.order - b.config.order;
|
|
|
|
|
});
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
var layers = config.mapLayers.map(function (d) {
|
2015-07-07 14:36:19 +00:00
|
|
|
|
return {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
'name': d.name,
|
|
|
|
|
'layer': 'url' in d ? L.tileLayer(d.url.replace('{retina}', L.Browser.retina ? '@2x' : ''), d.config) : console.warn('Missing map url')
|
2016-05-22 11:23:43 +00:00
|
|
|
|
};
|
|
|
|
|
});
|
2015-07-07 14:36:19 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
layers[0].layer.addTo(map);
|
2015-07-07 14:36:19 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
layers.forEach(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
baseLayers[d.name] = d.layer;
|
|
|
|
|
});
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
map.on('locationfound', locationFound);
|
|
|
|
|
map.on('locationerror', locationError);
|
|
|
|
|
map.on('dragend', saveView);
|
|
|
|
|
map.on('contextmenu', contextMenuOpenLayerMenu);
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
addButton(locateUserButton);
|
|
|
|
|
addButton(showCoordsPickerButton);
|
2015-04-04 17:08:28 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
layerControl = L.control.layers(baseLayers, [], { position: 'bottomright' });
|
2016-05-22 11:23:43 +00:00
|
|
|
|
layerControl.addTo(map);
|
2015-04-15 20:25:22 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
var clientLayer = new ClientLayer({ minZoom: 15 });
|
2016-05-22 11:23:43 +00:00
|
|
|
|
clientLayer.addTo(map);
|
|
|
|
|
clientLayer.setZIndex(5);
|
2015-04-16 23:02:56 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var labelsLayer = new LabelsLayer({});
|
|
|
|
|
labelsLayer.addTo(map);
|
|
|
|
|
labelsLayer.setZIndex(6);
|
2015-04-17 21:54:19 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
map.on('baselayerchange', function (e) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
map.options.maxZoom = e.layer.options.maxZoom;
|
|
|
|
|
clientLayer.options.maxZoom = map.options.maxZoom;
|
|
|
|
|
labelsLayer.options.maxZoom = map.options.maxZoom;
|
2016-05-25 20:52:29 +00:00
|
|
|
|
if (map.getZoom() > map.options.maxZoom) {
|
|
|
|
|
map.setZoom(map.options.maxZoom);
|
|
|
|
|
}
|
2016-05-26 16:37:24 +00:00
|
|
|
|
if (helper.localStorageTest()) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
localStorage.setItem('map/selectedLayer', JSON.stringify({ name: e.name }));
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2016-07-23 12:52:19 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
var cssMode = document.querySelector('.css-mode');
|
2016-07-23 12:52:19 +00:00
|
|
|
|
if (cssMode) {
|
|
|
|
|
cssMode.parentNode.removeChild(cssMode);
|
2017-01-29 23:51:08 +00:00
|
|
|
|
document.querySelector('html').className = '';
|
2017-01-20 14:06:06 +00:00
|
|
|
|
labelsLayer.updateLayer();
|
2016-07-23 12:52:19 +00:00
|
|
|
|
}
|
|
|
|
|
if (e.layer.options.mode) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
document.querySelector('head').innerHTML += "<link rel='stylesheet' class='css-mode' href='" + e.layer.options.mode + ".css'>";
|
|
|
|
|
document.querySelector('html').classList.add(e.layer.options.mode);
|
2016-09-17 17:59:18 +00:00
|
|
|
|
var cssInterval = setInterval(function () {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
if (typeof document.querySelector('.css-mode').sheet.cssRules !== 'undefined') {
|
2017-01-20 14:06:06 +00:00
|
|
|
|
labelsLayer.updateLayer();
|
2016-07-23 12:52:19 +00:00
|
|
|
|
clearInterval(cssInterval);
|
|
|
|
|
}
|
|
|
|
|
}, 10);
|
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
});
|
2016-05-22 10:30:31 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var nodeDict = {};
|
|
|
|
|
var linkDict = {};
|
|
|
|
|
var highlight;
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function resetMarkerStyles(nodes, links) {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
Object.keys(nodes).forEach(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
nodes[d].resetStyle();
|
|
|
|
|
});
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
Object.keys(links).forEach(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
links[d].resetStyle();
|
|
|
|
|
});
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function setView(bounds) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
map.fitBounds(bounds, { paddingTopLeft: [sidebar(), 0], maxZoom: config.nodeZoom });
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function resetZoom() {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (barycenter) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
setView(barycenter.getBounds());
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function goto(m) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var bounds;
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
if ('getBounds' in m) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
bounds = m.getBounds();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
} else {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
bounds = L.latLngBounds([m.getLatLng()]);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
setView(bounds);
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
return m;
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2015-04-17 20:10:47 +00:00
|
|
|
|
function updateView(nopanzoom) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
resetMarkerStyles(nodeDict, linkDict);
|
|
|
|
|
var m;
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (highlight !== undefined) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
if (highlight.type === 'node') {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
m = nodeDict[highlight.o.nodeinfo.node_id];
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (m) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
m.setStyle({ color: 'orange', weight: 20, fillOpacity: 1, opacity: 0.7, className: 'stroke-first' });
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2017-01-29 23:51:08 +00:00
|
|
|
|
} else if (highlight.type === 'link') {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
m = linkDict[highlight.o.id];
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (m) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
m.setStyle({ weight: 4, opacity: 1, dashArray: '5, 10' });
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-17 20:10:47 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (!nopanzoom) {
|
|
|
|
|
if (m) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
goto(m);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
} else if (savedView) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
map.setView(savedView.center, savedView.zoom);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
} else {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
resetZoom();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-17 20:10:47 +00:00
|
|
|
|
}
|
2015-04-06 09:58:02 +00:00
|
|
|
|
|
2015-04-19 10:22:09 +00:00
|
|
|
|
function mapRTree(d) {
|
2016-05-22 12:51:30 +00:00
|
|
|
|
var o = [d.nodeinfo.location.latitude, d.nodeinfo.location.longitude,
|
|
|
|
|
d.nodeinfo.location.latitude, d.nodeinfo.location.longitude];
|
2015-04-19 10:22:09 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
o.node = d;
|
2015-04-19 10:22:09 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
return o;
|
2015-04-19 10:22:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
self.setData = function setData(data) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
nodeDict = {};
|
|
|
|
|
linkDict = {};
|
2015-04-06 13:54:26 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (groupOffline) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
groupOffline.clearLayers();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (groupOnline) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
groupOnline.clearLayers();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-02 22:02:00 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (groupNew) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
groupNew.clearLayers();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-02 22:02:00 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (groupLost) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
groupLost.clearLayers();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-02 22:02:00 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (groupLines) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
groupLines.clearLayers();
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-04-02 22:02:00 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var lines = addLinksToMap(linkDict, linkScale, data.graph.links, router);
|
|
|
|
|
groupLines = L.featureGroup(lines).addTo(map);
|
2015-04-02 22:02:00 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
if (typeof config.fixedCenter === 'undefined') {
|
2016-05-26 16:39:26 +00:00
|
|
|
|
console.error('FixedCenter is required');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
} else {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
barycenter = L.circle(L.latLng(new L.LatLng(config.fixedCenter.lat, config.fixedCenter.lng)), config.fixedCenter.radius * 1000);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
|
var nodesOnline = helper.subtract(data.nodes.all.filter(helper.online), data.nodes.new);
|
|
|
|
|
var nodesOffline = helper.subtract(data.nodes.all.filter(helper.offline), data.nodes.lost);
|
2015-04-06 13:54:26 +00:00
|
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
|
var markersOnline = nodesOnline.filter(helper.hasLocation)
|
2016-05-22 12:51:30 +00:00
|
|
|
|
.map(mkMarker(nodeDict, function () {
|
|
|
|
|
return iconOnline;
|
|
|
|
|
}, router));
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
|
var markersOffline = nodesOffline.filter(helper.hasLocation)
|
2016-05-22 12:51:30 +00:00
|
|
|
|
.map(mkMarker(nodeDict, function () {
|
|
|
|
|
return iconOffline;
|
|
|
|
|
}, router));
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
|
var markersNew = data.nodes.new.filter(helper.hasLocation)
|
2016-05-22 12:51:30 +00:00
|
|
|
|
.map(mkMarker(nodeDict, function () {
|
|
|
|
|
return iconNew;
|
|
|
|
|
}, router));
|
2015-03-25 09:29:41 +00:00
|
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
|
var markersLost = data.nodes.lost.filter(helper.hasLocation)
|
2015-04-17 20:10:47 +00:00
|
|
|
|
.map(mkMarker(nodeDict, function (d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
if (d.lastseen.isAfter(moment(data.now).subtract(3, 'days'))) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
return iconAlert;
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
if (d.lastseen.isAfter(moment(data.now).subtract(14, 'days'))) {
|
2016-05-25 20:52:29 +00:00
|
|
|
|
return iconLost;
|
|
|
|
|
}
|
2017-01-29 23:51:08 +00:00
|
|
|
|
return null;
|
2016-05-22 11:23:43 +00:00
|
|
|
|
}, router));
|
2015-03-26 12:51:08 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
groupOffline = L.featureGroup(markersOffline).addTo(map);
|
|
|
|
|
groupLost = L.featureGroup(markersLost).addTo(map);
|
2016-05-25 20:52:29 +00:00
|
|
|
|
groupOnline = L.featureGroup(markersOnline).addTo(map);
|
2016-05-22 11:23:43 +00:00
|
|
|
|
groupNew = L.featureGroup(markersNew).addTo(map);
|
2015-03-26 12:51:08 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var rtreeOnlineAll = rbush(9);
|
2015-04-19 10:22:09 +00:00
|
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
|
rtreeOnlineAll.load(data.nodes.all.filter(helper.online).filter(helper.hasLocation).map(mapRTree));
|
2015-04-19 10:22:09 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
clientLayer.setData(rtreeOnlineAll);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
labelsLayer.setData({
|
2016-05-26 16:37:24 +00:00
|
|
|
|
online: nodesOnline.filter(helper.hasLocation),
|
|
|
|
|
offline: nodesOffline.filter(helper.hasLocation),
|
|
|
|
|
new: data.nodes.new.filter(helper.hasLocation),
|
|
|
|
|
lost: data.nodes.lost.filter(helper.hasLocation)
|
2016-05-22 12:51:30 +00:00
|
|
|
|
});
|
2015-03-29 14:14:10 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
updateView(true);
|
|
|
|
|
};
|
2015-04-16 23:02:56 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
self.resetView = function resetView() {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
disableTracking();
|
|
|
|
|
highlight = undefined;
|
|
|
|
|
updateView();
|
|
|
|
|
};
|
2015-03-29 14:14:10 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
self.gotoNode = function gotoNode(d, update) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
disableTracking();
|
2017-01-29 23:51:08 +00:00
|
|
|
|
highlight = { type: 'node', o: d };
|
2016-06-22 01:15:53 +00:00
|
|
|
|
updateView(update);
|
2016-05-22 11:23:43 +00:00
|
|
|
|
};
|
2015-03-25 00:16:15 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
self.gotoLink = function gotoLink(d, update) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
disableTracking();
|
2017-01-29 23:51:08 +00:00
|
|
|
|
highlight = { type: 'link', o: d };
|
2016-06-22 01:15:53 +00:00
|
|
|
|
updateView(update);
|
2016-05-22 11:23:43 +00:00
|
|
|
|
};
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
self.gotoLocation = function gotoLocation() {
|
|
|
|
|
// ignore
|
2016-05-22 11:23:43 +00:00
|
|
|
|
};
|
2016-02-25 14:47:07 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
self.destroy = function destroy() {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
clearButtons();
|
|
|
|
|
map.remove();
|
2015-07-11 22:11:18 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
if (el.parentNode) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
el.parentNode.removeChild(el);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
};
|
2015-07-11 22:11:18 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
self.render = function render(d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
d.appendChild(el);
|
|
|
|
|
map.invalidateSize();
|
|
|
|
|
};
|
2015-03-24 23:54:00 +00:00
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
|
return self;
|
|
|
|
|
};
|
2016-05-22 12:51:30 +00:00
|
|
|
|
});
|