diff --git a/lib/map.js b/lib/map.js index 8e7bcc8..66ead33 100644 --- a/lib/map.js +++ b/lib/map.js @@ -198,11 +198,6 @@ define(["map/clientlayer", "map/labelslayer", layerControl.addBaseLayer(layer, layerName) customLayers.add(layerName) - if (!layerControl.added) { - layerControl.addTo(map) - layerControl.added = true - } - if (localStorageTest()) localStorage.setItem("map/customLayers", JSON.stringify(Array.from(customLayers))) } catch (e) { @@ -242,6 +237,7 @@ define(["map/clientlayer", "map/labelslayer", })) layerControl = L.control.layers(baseLayers, [], {position: "bottomright"}) + layerControl.addTo(map) if (localStorageTest()) { var d = JSON.parse(localStorage.getItem("map/customLayers")) @@ -277,7 +273,8 @@ define(["map/clientlayer", "map/labelslayer", } function resetZoom() { - setView(barycenter.getBounds()) + if (barycenter) + setView(barycenter.getBounds()) } function goto(m) { @@ -321,6 +318,10 @@ define(["map/clientlayer", "map/labelslayer", function calcBarycenter(nodes) { nodes = nodes.map(function (d) { return d.nodeinfo.location }) + + if (nodes.length === 0) + return undefined + var lats = nodes.map(function (d) { return d.latitude }) var lngs = nodes.map(function (d) { return d.longitude })