2015-04-17 23:54:19 +02:00
|
|
|
|
define(["map/clientlayer", "map/labelslayer",
|
2017-03-17 03:14:57 +01:00
|
|
|
|
"d3", "leaflet", "moment", "locationmarker", "rbush",
|
2016-05-22 15:40:13 +02:00
|
|
|
|
"leaflet.label", "leaflet.providers", "moment.de"],
|
2015-04-19 12:22:09 +02:00
|
|
|
|
function (ClientLayer, LabelsLayer, d3, L, moment, LocationMarker, rbush) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var options = {
|
|
|
|
|
worldCopyJump: true,
|
|
|
|
|
zoomControl: false
|
|
|
|
|
};
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
var AddLayerButton = L.Control.extend({
|
2017-03-17 03:14:57 +01:00
|
|
|
|
options: {
|
|
|
|
|
position: "bottomright"
|
|
|
|
|
},
|
2015-04-12 03:24:46 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
initialize: function (f, options) {
|
|
|
|
|
L.Util.setOptions(this, options);
|
|
|
|
|
this.f = f;
|
|
|
|
|
},
|
2015-04-12 03:24:46 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
onAdd: function () {
|
|
|
|
|
var button = L.DomUtil.create("button", "add-layer");
|
|
|
|
|
button.textContent = "\uF2C7";
|
2015-04-12 03:24:46 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
// L.DomEvent.disableClickPropagation(button)
|
|
|
|
|
// Click propagation isn't disabled as this causes problems with the
|
|
|
|
|
// location picking mode; instead propagation is stopped in onClick().
|
|
|
|
|
L.DomEvent.addListener(button, "click", this.f, this);
|
2015-04-12 03:24:46 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
this.button = button;
|
2015-04-12 03:24:46 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-04-12 03:24:46 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
var LocateButton = L.Control.extend({
|
2017-03-17 03:14:57 +01:00
|
|
|
|
options: {
|
|
|
|
|
position: "bottomright"
|
|
|
|
|
},
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
active: false,
|
|
|
|
|
button: undefined,
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
initialize: function (f, options) {
|
|
|
|
|
L.Util.setOptions(this, options);
|
|
|
|
|
this.f = f;
|
|
|
|
|
},
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
onAdd: function () {
|
|
|
|
|
var button = L.DomUtil.create("button", "locate-user");
|
|
|
|
|
button.textContent = "\uF2E9";
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
L.DomEvent.disableClickPropagation(button);
|
|
|
|
|
L.DomEvent.addListener(button, "click", this.onClick, this);
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
this.button = button;
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return button;
|
|
|
|
|
},
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
update: function () {
|
|
|
|
|
this.button.classList.toggle("active", this.active);
|
|
|
|
|
},
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
set: function (v) {
|
|
|
|
|
this.active = v;
|
|
|
|
|
this.update();
|
|
|
|
|
},
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
onClick: function () {
|
|
|
|
|
this.f(!this.active);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2015-11-09 10:01:20 +01:00
|
|
|
|
var CoordsPickerButton = L.Control.extend({
|
|
|
|
|
options: {
|
|
|
|
|
position: "bottomright"
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
active: false,
|
|
|
|
|
button: undefined,
|
|
|
|
|
|
|
|
|
|
initialize: function (f, options) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
L.Util.setOptions(this, options);
|
|
|
|
|
this.f = f;
|
2015-11-09 10:01:20 +01:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onAdd: function () {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var button = L.DomUtil.create("button", "coord-picker");
|
2016-05-22 15:26:16 +02:00
|
|
|
|
button.textContent = "\uF3A3";
|
2015-11-09 10:01:20 +01:00
|
|
|
|
|
2015-12-30 08:21:46 +01:00
|
|
|
|
// Click propagation isn't disabled as this causes problems with the
|
|
|
|
|
// location picking mode; instead propagation is stopped in onClick().
|
2017-03-17 03:14:57 +01:00
|
|
|
|
L.DomEvent.addListener(button, "click", this.onClick, this);
|
2015-11-09 10:01:20 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
this.button = button;
|
2015-11-09 10:01:20 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return button;
|
2015-11-09 10:01:20 +01:00
|
|
|
|
},
|
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
update: function () {
|
|
|
|
|
this.button.classList.toggle("active", this.active);
|
2015-11-09 10:01:20 +01:00
|
|
|
|
},
|
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
set: function (v) {
|
|
|
|
|
this.active = v;
|
|
|
|
|
this.update();
|
2015-11-09 10:01:20 +01:00
|
|
|
|
},
|
|
|
|
|
|
2015-12-30 08:21:46 +01:00
|
|
|
|
onClick: function (e) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
L.DomEvent.stopPropagation(e);
|
|
|
|
|
this.f(!this.active);
|
2015-11-09 10:01:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
});
|
2015-11-09 10:01:20 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function mkMarker(dict, iconFunc, router) {
|
|
|
|
|
return function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var m = L.circleMarker([d.nodeinfo.location.latitude, d.nodeinfo.location.longitude], iconFunc(d));
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
m.resetStyle = function () {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
m.setStyle(iconFunc(d));
|
|
|
|
|
};
|
2015-03-25 02:15:17 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
m.on("click", router.node(d));
|
|
|
|
|
m.bindLabel(d.nodeinfo.hostname);
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
dict[d.nodeinfo.node_id] = m;
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return m;
|
|
|
|
|
};
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function addLinksToMap(dict, linkScale, graph, router) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
graph = graph.filter(function (d) {
|
|
|
|
|
return "distance" in d && d.type !== "VPN";
|
|
|
|
|
});
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2016-05-22 23:32:05 +02:00
|
|
|
|
return graph.map(function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var opts = {
|
|
|
|
|
color: d.type === "Kabel" ? "#50B0F0" : linkScale(d.tq).hex(),
|
|
|
|
|
weight: 4,
|
|
|
|
|
opacity: 0.5,
|
|
|
|
|
dashArray: "none"
|
|
|
|
|
};
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var line = L.polyline(d.latlngs, opts);
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
line.resetStyle = function () {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
line.setStyle(opts);
|
|
|
|
|
};
|
2015-03-25 02:15:17 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
line.bindLabel(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>");
|
|
|
|
|
line.on("click", router.link(d));
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
dict[d.id] = line;
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return line;
|
|
|
|
|
});
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var iconOnline = {
|
|
|
|
|
color: "#1566A9",
|
|
|
|
|
fillColor: "#1566A9",
|
|
|
|
|
radius: 6,
|
|
|
|
|
fillOpacity: 0.5,
|
|
|
|
|
opacity: 0.5,
|
|
|
|
|
weight: 2,
|
|
|
|
|
className: "stroke-first"
|
|
|
|
|
};
|
|
|
|
|
var iconOffline = {
|
|
|
|
|
color: "#D43E2A",
|
|
|
|
|
fillColor: "#D43E2A",
|
|
|
|
|
radius: 3,
|
|
|
|
|
fillOpacity: 0.5,
|
|
|
|
|
opacity: 0.5,
|
|
|
|
|
weight: 1,
|
|
|
|
|
className: "stroke-first"
|
|
|
|
|
};
|
|
|
|
|
var iconLost = {
|
|
|
|
|
color: "#D43E2A",
|
|
|
|
|
fillColor: "#D43E2A",
|
2016-05-25 22:52:29 +02:00
|
|
|
|
radius: 4,
|
2017-03-17 03:14:57 +01:00
|
|
|
|
fillOpacity: 0.8,
|
|
|
|
|
opacity: 0.8,
|
|
|
|
|
weight: 1,
|
|
|
|
|
className: "stroke-first"
|
|
|
|
|
};
|
|
|
|
|
var iconAlert = {
|
|
|
|
|
color: "#D43E2A",
|
|
|
|
|
fillColor: "#D43E2A",
|
2016-05-25 22:52:29 +02:00
|
|
|
|
radius: 5,
|
2017-03-17 03:14:57 +01:00
|
|
|
|
fillOpacity: 0.8,
|
|
|
|
|
opacity: 0.8,
|
|
|
|
|
weight: 2,
|
2016-05-25 22:52:29 +02:00
|
|
|
|
className: "stroke-first"
|
2017-03-17 03:14:57 +01:00
|
|
|
|
};
|
|
|
|
|
var iconNew = {color: "#1566A9", fillColor: "#93E929", radius: 6, fillOpacity: 1.0, opacity: 0.5, weight: 2};
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2015-07-07 01:56:11 +02:00
|
|
|
|
return function (config, linkScale, sidebar, router, buttons) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var self = this;
|
|
|
|
|
var barycenter;
|
|
|
|
|
var groupOnline, groupOffline, groupNew, groupLost, groupLines;
|
|
|
|
|
var savedView;
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var map, userLocation;
|
|
|
|
|
var layerControl;
|
|
|
|
|
var customLayers = {};
|
|
|
|
|
var baseLayers = {};
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
var locateUserButton = new LocateButton(function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (d) {
|
|
|
|
|
enableTracking();
|
|
|
|
|
} else {
|
|
|
|
|
disableTracking();
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var mybuttons = [];
|
2015-07-07 01:56:11 +02:00
|
|
|
|
|
|
|
|
|
function addButton(button) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var el = button.onAdd();
|
|
|
|
|
mybuttons.push(el);
|
|
|
|
|
buttons.appendChild(el);
|
2015-07-07 01:56:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearButtons() {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
mybuttons.forEach(function (d) {
|
|
|
|
|
buttons.removeChild(d);
|
|
|
|
|
});
|
2015-07-07 01:56:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 10:01:20 +01:00
|
|
|
|
var showCoordsPickerButton = new CoordsPickerButton(function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (d) {
|
|
|
|
|
enableCoords();
|
|
|
|
|
} else {
|
|
|
|
|
disableCoords();
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-11-09 10:01:20 +01:00
|
|
|
|
|
2015-04-19 16:54:35 +02:00
|
|
|
|
function saveView() {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
savedView = {
|
|
|
|
|
center: map.getCenter(),
|
|
|
|
|
zoom: map.getZoom()
|
|
|
|
|
};
|
2015-04-19 16:54:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function enableTracking() {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.locate({
|
|
|
|
|
watch: true,
|
|
|
|
|
enableHighAccuracy: true,
|
|
|
|
|
setView: true
|
|
|
|
|
});
|
|
|
|
|
locateUserButton.set(true);
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function disableTracking() {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.stopLocate();
|
|
|
|
|
locationError();
|
|
|
|
|
locateUserButton.set(false);
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2015-11-09 10:01:20 +01:00
|
|
|
|
function enableCoords() {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.getContainer().classList.add("pick-coordinates");
|
|
|
|
|
map.on("click", showCoordinates);
|
|
|
|
|
showCoordsPickerButton.set(true);
|
2015-11-09 10:01:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function disableCoords() {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.getContainer().classList.remove("pick-coordinates");
|
|
|
|
|
map.off("click", showCoordinates);
|
|
|
|
|
showCoordsPickerButton.set(false);
|
2015-11-09 10:01:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showCoordinates(e) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
router.gotoLocation(e.latlng);
|
2016-02-25 20:05:36 +01:00
|
|
|
|
// window.prompt("Koordinaten (Lat, Lng)", e.latlng.lat.toFixed(9) + ", " + e.latlng.lng.toFixed(9))
|
2017-03-17 03:14:57 +01:00
|
|
|
|
disableCoords();
|
2015-11-09 10:01:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function locationFound(e) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (!userLocation) {
|
|
|
|
|
userLocation = new LocationMarker(e.latlng).addTo(map);
|
|
|
|
|
}
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
userLocation.setLatLng(e.latlng);
|
|
|
|
|
userLocation.setAccuracy(e.accuracy);
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function locationError() {
|
|
|
|
|
if (userLocation) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.removeLayer(userLocation);
|
|
|
|
|
userLocation = null;
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-04 19:08:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function addLayer(layerName) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (layerName in baseLayers) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-07 16:36:19 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (layerName in customLayers) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-04-15 22:25:22 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
try {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var layer = L.tileLayer.provider(layerName);
|
|
|
|
|
layerControl.addBaseLayer(layer, layerName);
|
|
|
|
|
customLayers[layerName] = layer;
|
2015-04-15 22:25:22 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (localStorageTest()) {
|
|
|
|
|
localStorage.setItem("map/customLayers", JSON.stringify(Object.keys(customLayers)));
|
|
|
|
|
}
|
2015-04-17 22:10:47 +02:00
|
|
|
|
} catch (e) {
|
2017-03-17 03:19:03 +01:00
|
|
|
|
console.error(e);
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-15 22:25:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 15:47:07 +01:00
|
|
|
|
function contextMenuGotoLocation(e) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
router.gotoLocation(e.latlng);
|
2016-02-25 15:47:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var el = document.createElement("div");
|
|
|
|
|
el.classList.add("map");
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map = L.map(el, options);
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var layers = config.mapLayers.map(function (d) {
|
2015-07-07 16:36:19 +02:00
|
|
|
|
return {
|
|
|
|
|
"name": d.name,
|
|
|
|
|
"layer": "url" in d ? L.tileLayer(d.url, d.config) : L.tileLayer.provider(d.name)
|
2017-03-17 03:14:57 +01:00
|
|
|
|
};
|
|
|
|
|
});
|
2015-07-07 16:36:19 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
layers[0].layer.addTo(map);
|
2015-07-07 16:36:19 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
layers.forEach(function (d) {
|
|
|
|
|
baseLayers[d.name] = d.layer;
|
|
|
|
|
});
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.on("locationfound", locationFound);
|
|
|
|
|
map.on("locationerror", locationError);
|
|
|
|
|
map.on("dragend", saveView);
|
|
|
|
|
map.on("contextmenu", contextMenuGotoLocation);
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
addButton(locateUserButton);
|
|
|
|
|
addButton(showCoordsPickerButton);
|
2015-04-04 19:08:28 +02:00
|
|
|
|
|
2015-07-07 01:56:11 +02:00
|
|
|
|
addButton(new AddLayerButton(function () {
|
2015-04-17 22:10:47 +02:00
|
|
|
|
/*eslint no-alert:0*/
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var layerName = prompt("Leaflet Provider:");
|
|
|
|
|
addLayer(layerName);
|
|
|
|
|
}));
|
2015-04-12 03:24:46 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
layerControl = L.control.layers(baseLayers, [], {position: "bottomright"});
|
|
|
|
|
layerControl.addTo(map);
|
2015-04-15 22:25:22 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
if (localStorageTest()) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var d = JSON.parse(localStorage.getItem("map/customLayers"));
|
2015-04-15 22:25:22 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (d) {
|
|
|
|
|
d.forEach(addLayer);
|
|
|
|
|
}
|
2016-04-21 22:32:22 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
d = JSON.parse(localStorage.getItem("map/selectedLayer"));
|
|
|
|
|
d = d && d.name in baseLayers ? baseLayers[d.name] : d && d.name in customLayers ? customLayers[d.name] : false;
|
2016-04-21 22:32:22 +02:00
|
|
|
|
|
|
|
|
|
if (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.removeLayer(layers[0].layer);
|
|
|
|
|
map.addLayer(d);
|
2016-04-21 22:32:22 +02:00
|
|
|
|
}
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-15 22:25:22 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var clientLayer = new ClientLayer({minZoom: 15});
|
|
|
|
|
clientLayer.addTo(map);
|
|
|
|
|
clientLayer.setZIndex(5);
|
2015-04-17 01:02:56 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var labelsLayer = new LabelsLayer({});
|
|
|
|
|
labelsLayer.addTo(map);
|
|
|
|
|
labelsLayer.setZIndex(6);
|
2015-04-17 23:54:19 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.on("baselayerchange", function (e) {
|
|
|
|
|
map.options.maxZoom = e.layer.options.maxZoom;
|
|
|
|
|
clientLayer.options.maxZoom = map.options.maxZoom;
|
|
|
|
|
labelsLayer.options.maxZoom = map.options.maxZoom;
|
|
|
|
|
if (map.getZoom() > map.options.maxZoom) {
|
|
|
|
|
map.setZoom(map.options.maxZoom);
|
|
|
|
|
}
|
|
|
|
|
if (localStorageTest()) {
|
|
|
|
|
localStorage.setItem("map/selectedLayer", JSON.stringify({name: e.name}));
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-05-22 12:30:31 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var nodeDict = {};
|
|
|
|
|
var linkDict = {};
|
|
|
|
|
var highlight;
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function resetMarkerStyles(nodes, links) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
Object.keys(nodes).forEach(function (d) {
|
|
|
|
|
nodes[d].resetStyle();
|
|
|
|
|
});
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
Object.keys(links).forEach(function (d) {
|
|
|
|
|
links[d].resetStyle();
|
|
|
|
|
});
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function setView(bounds) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
map.fitBounds(bounds, {paddingTopLeft: [sidebar(), 0]});
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function resetZoom() {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (barycenter) {
|
|
|
|
|
setView(barycenter.getBounds());
|
|
|
|
|
}
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function goto(m) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var bounds;
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if ("getBounds" in m) {
|
|
|
|
|
bounds = m.getBounds();
|
|
|
|
|
} else {
|
|
|
|
|
bounds = L.latLngBounds([m.getLatLng()]);
|
|
|
|
|
}
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
setView(bounds);
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return m;
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function updateView(nopanzoom) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
resetMarkerStyles(nodeDict, linkDict);
|
|
|
|
|
var m;
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (highlight !== undefined) {
|
2015-04-17 22:10:47 +02:00
|
|
|
|
if (highlight.type === "node") {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
m = nodeDict[highlight.o.nodeinfo.node_id];
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (m) {
|
|
|
|
|
m.setStyle({color: "orange", weight: 20, fillOpacity: 1, opacity: 0.7, className: "stroke-first"});
|
|
|
|
|
}
|
2015-04-17 22:10:47 +02:00
|
|
|
|
} else if (highlight.type === "link") {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
m = linkDict[highlight.o.id];
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (m) {
|
2016-05-25 22:52:29 +02:00
|
|
|
|
m.setStyle({weight: 4, opacity: 1, dashArray: "5, 10"});
|
2017-03-17 03:14:57 +01:00
|
|
|
|
}
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2017-03-17 03:14:57 +01:00
|
|
|
|
}
|
2015-04-17 22:10:47 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (!nopanzoom) {
|
|
|
|
|
if (m) {
|
|
|
|
|
goto(m);
|
|
|
|
|
} else if (savedView) {
|
|
|
|
|
map.setView(savedView.center, savedView.zoom);
|
|
|
|
|
} else {
|
|
|
|
|
resetZoom();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-06 11:58:02 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
function calcBarycenter(nodes) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
nodes = nodes.map(function (d) {
|
|
|
|
|
return d.nodeinfo.location;
|
|
|
|
|
});
|
2015-07-07 21:42:55 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (nodes.length === 0) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
2015-07-07 21:42:55 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var lats = nodes.map(function (d) {
|
|
|
|
|
return d.latitude;
|
|
|
|
|
});
|
|
|
|
|
var lngs = nodes.map(function (d) {
|
|
|
|
|
return d.longitude;
|
|
|
|
|
});
|
2015-03-25 01:16:15 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var barycenter = L.latLng(d3.median(lats), d3.median(lngs));
|
|
|
|
|
var barycenterDev = [d3.deviation(lats), d3.deviation(lngs)];
|
2015-04-06 15:54:26 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (barycenterDev[0] === undefined) {
|
|
|
|
|
barycenterDev[0] = 0;
|
|
|
|
|
}
|
2015-07-07 21:28:44 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (barycenterDev[1] === undefined) {
|
|
|
|
|
barycenterDev[1] = 0;
|
|
|
|
|
}
|
2015-07-07 21:28:44 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
var barycenterCircle = L.latLng(barycenter.lat + barycenterDev[0],
|
2017-03-17 03:14:57 +01:00
|
|
|
|
barycenter.lng + barycenterDev[1]);
|
2015-04-06 15:54:26 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var r = barycenter.distanceTo(barycenterCircle);
|
2015-04-06 15:54:26 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return L.circle(barycenter, r * config.mapSigmaScale);
|
2015-04-17 22:10:47 +02:00
|
|
|
|
}
|
2015-04-06 15:54:26 +02:00
|
|
|
|
|
2015-04-19 12:22:09 +02:00
|
|
|
|
function mapRTree(d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var o = [d.nodeinfo.location.latitude, d.nodeinfo.location.longitude,
|
|
|
|
|
d.nodeinfo.location.latitude, d.nodeinfo.location.longitude];
|
2015-04-19 12:22:09 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
o.node = d;
|
2015-04-19 12:22:09 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return o;
|
2015-04-19 12:22:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
self.setData = function (data) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
nodeDict = {};
|
|
|
|
|
linkDict = {};
|
2015-04-06 15:54:26 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (groupOffline) {
|
|
|
|
|
groupOffline.clearLayers();
|
|
|
|
|
}
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (groupOnline) {
|
|
|
|
|
groupOnline.clearLayers();
|
|
|
|
|
}
|
2015-04-03 00:02:00 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (groupNew) {
|
|
|
|
|
groupNew.clearLayers();
|
|
|
|
|
}
|
2015-04-03 00:02:00 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (groupLost) {
|
|
|
|
|
groupLost.clearLayers();
|
|
|
|
|
}
|
2015-04-03 00:02:00 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (groupLines) {
|
|
|
|
|
groupLines.clearLayers();
|
|
|
|
|
}
|
2015-04-03 00:02:00 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var lines = addLinksToMap(linkDict, linkScale, data.graph.links, router);
|
|
|
|
|
groupLines = L.featureGroup(lines).addTo(map);
|
2015-04-03 00:02:00 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (typeof config.fixedCenter === "undefined") {
|
|
|
|
|
barycenter = calcBarycenter(data.nodes.all.filter(has_location));
|
|
|
|
|
} else {
|
|
|
|
|
barycenter = L.circle(L.latLng(new L.LatLng(config.fixedCenter.lat, config.fixedCenter.lng)), config.fixedCenter.radius * 1000);
|
|
|
|
|
}
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var nodesOnline = subtract(data.nodes.all.filter(online), data.nodes.new);
|
|
|
|
|
var nodesOffline = subtract(data.nodes.all.filter(offline), data.nodes.lost);
|
2015-04-06 15:54:26 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
var markersOnline = nodesOnline.filter(has_location)
|
2017-03-17 03:14:57 +01:00
|
|
|
|
.map(mkMarker(nodeDict, function () {
|
|
|
|
|
return iconOnline;
|
|
|
|
|
}, router));
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
var markersOffline = nodesOffline.filter(has_location)
|
2017-03-17 03:14:57 +01:00
|
|
|
|
.map(mkMarker(nodeDict, function () {
|
|
|
|
|
return iconOffline;
|
|
|
|
|
}, router));
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
var markersNew = data.nodes.new.filter(has_location)
|
2017-03-17 03:14:57 +01:00
|
|
|
|
.map(mkMarker(nodeDict, function () {
|
|
|
|
|
return iconNew;
|
|
|
|
|
}, router));
|
2015-03-25 10:29:41 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
var markersLost = data.nodes.lost.filter(has_location)
|
|
|
|
|
.map(mkMarker(nodeDict, function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (d.lastseen.isAfter(moment(data.now).subtract(3, "days"))) {
|
|
|
|
|
return iconAlert;
|
|
|
|
|
}
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2016-05-25 22:52:29 +02:00
|
|
|
|
if (d.lastseen.isAfter(moment(data.now).subtract(14, "days"))) {
|
|
|
|
|
return iconLost;
|
|
|
|
|
}
|
2017-03-17 03:14:57 +01:00
|
|
|
|
}, router));
|
2015-03-26 13:51:08 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
groupOffline = L.featureGroup(markersOffline).addTo(map);
|
|
|
|
|
groupLost = L.featureGroup(markersLost).addTo(map);
|
2016-05-25 22:52:29 +02:00
|
|
|
|
groupOnline = L.featureGroup(markersOnline).addTo(map);
|
2017-03-17 03:14:57 +01:00
|
|
|
|
groupNew = L.featureGroup(markersNew).addTo(map);
|
2015-03-26 13:51:08 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
var rtreeOnlineAll = rbush(9);
|
2015-04-19 12:22:09 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
rtreeOnlineAll.load(data.nodes.all.filter(online).filter(has_location).map(mapRTree));
|
2015-04-19 12:22:09 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
clientLayer.setData(rtreeOnlineAll);
|
|
|
|
|
labelsLayer.setData({
|
|
|
|
|
online: nodesOnline.filter(has_location),
|
|
|
|
|
offline: nodesOffline.filter(has_location),
|
|
|
|
|
new: data.nodes.new.filter(has_location),
|
|
|
|
|
lost: data.nodes.lost.filter(has_location)
|
|
|
|
|
});
|
2015-03-29 16:14:10 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
updateView(true);
|
|
|
|
|
};
|
2015-04-17 01:02:56 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
self.resetView = function () {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
disableTracking();
|
|
|
|
|
highlight = undefined;
|
|
|
|
|
updateView();
|
|
|
|
|
};
|
2015-03-29 16:14:10 +02:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
self.gotoNode = function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
disableTracking();
|
|
|
|
|
highlight = {type: "node", o: d};
|
|
|
|
|
updateView();
|
|
|
|
|
};
|
2015-03-25 01:16:15 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
self.gotoLink = function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
disableTracking();
|
|
|
|
|
highlight = {type: "link", o: d};
|
|
|
|
|
updateView();
|
|
|
|
|
};
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2016-02-25 15:47:07 +01:00
|
|
|
|
self.gotoLocation = function () {
|
|
|
|
|
//ignore
|
2017-03-17 03:14:57 +01:00
|
|
|
|
};
|
2016-02-25 15:47:07 +01:00
|
|
|
|
|
2015-04-17 22:10:47 +02:00
|
|
|
|
self.destroy = function () {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
clearButtons();
|
|
|
|
|
map.remove();
|
2015-07-12 00:11:18 +02:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
if (el.parentNode) {
|
|
|
|
|
el.parentNode.removeChild(el);
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-07-12 00:11:18 +02:00
|
|
|
|
|
|
|
|
|
self.render = function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
|
d.appendChild(el);
|
|
|
|
|
map.invalidateSize();
|
|
|
|
|
};
|
2015-03-25 00:54:00 +01:00
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
|
return self;
|
|
|
|
|
};
|
|
|
|
|
});
|