From 02a03e5a611b7e43293d3f7f0d327b55422b448c Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Tue, 7 Jul 2015 21:28:44 +0200 Subject: [PATCH] map: work with no or little nodes --- lib/map.js | 6 ++++++ lib/map/labelslayer.js | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/map.js b/lib/map.js index 0371797..8e7bcc8 100644 --- a/lib/map.js +++ b/lib/map.js @@ -327,6 +327,12 @@ define(["map/clientlayer", "map/labelslayer", var barycenter = L.latLng(d3.median(lats), d3.median(lngs)) var barycenterDev = [d3.deviation(lats), d3.deviation(lngs)] + if (barycenterDev[0] === undefined) + barycenterDev[0] = 0 + + if (barycenterDev[1] === undefined) + barycenterDev[1] = 0 + var barycenterCircle = L.latLng(barycenter.lat + barycenterDev[0], barycenter.lng + barycenterDev[1]) diff --git a/lib/map/labelslayer.js b/lib/map/labelslayer.js index 9134184..7bd2cb9 100644 --- a/lib/map/labelslayer.js +++ b/lib/map/labelslayer.js @@ -155,9 +155,12 @@ define(["leaflet", "rbush"], return undefined }).filter(function (d) { return d !== undefined }) - this.margin = 16 + labels.map(function (d) { - return d.width - }).sort().reverse()[0] + this.margin = 16 + + if (labels.length > 0) + this.margin += labels.map(function (d) { + return d.width + }).sort().reverse()[0] this.labels = rbush(9) this.labels.load(labels.map(mapRTree))