From 8a2300578ae59a9a9e27b35aee01934238a30f39 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 25 Mar 2015 02:50:28 +0100 Subject: [PATCH] resetView --- lib/history.js | 17 +++++++++++++++++ lib/map.js | 17 +++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/history.js b/lib/history.js index a44e2cc..9ad77a1 100644 --- a/lib/history.js +++ b/lib/history.js @@ -109,6 +109,8 @@ require(["map"], function (Map) { historyDict.links[linkId(d)] = d }) + gotoAnything.reset() + gotoHistory(gotoAnything, historyDict, window.location.hash) window.onpopstate = function (d) { @@ -280,10 +282,12 @@ require(["map"], function (Map) { } function Infobox(sidebar) { + var gotoAnything var self = this el = undefined function close() { + gotoAnything.reset() destroy() pushHistory() } @@ -314,6 +318,10 @@ require(["map"], function (Map) { return el } + self.setGoto = function (d) { + gotoAnything = d + } + return self } @@ -605,6 +613,14 @@ require(["map"], function (Map) { var targets = [] var self = this + infobox.setGoto(self) + + function resetView() { + targets.forEach( function (t) { + t.resetView() + }) + } + function gotoNode(d, showMap, push) { showMap = trueDefault(showMap) push = trueDefault(push) @@ -639,6 +655,7 @@ require(["map"], function (Map) { this.node = function (d, m, p) { return function () { return gotoNode(d, m, p) }} this.link = function (d, m, p) { return function () { return gotoLink(d, m, p) }} + this.reset = resetView this.addMarkers = function (d) { markers = d } diff --git a/lib/map.js b/lib/map.js index a7e721f..d44a639 100644 --- a/lib/map.js +++ b/lib/map.js @@ -52,6 +52,8 @@ define(function () { var iconOffline = { color: "#D43E2A", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first" } var iconNew = { color: "#558020", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first" } + var groupOnline, group + return function (sidebar) { var self = this @@ -92,8 +94,13 @@ define(function () { .map(mkMarker(nodeDict, function (d) { return iconOnline }, gotoAnything)) var groupLines = L.featureGroup(lines).addTo(map) - var groupOnline = L.featureGroup(onlinemarkers).addTo(map) - var group = L.featureGroup(markers).addTo(map) + groupOnline = L.featureGroup(onlinemarkers).addTo(map) + group = L.featureGroup(markers).addTo(map) + resetView() + } + + function resetView() { + resetMarkerStyles(nodeDict, linkDict) var bounds = group.getBounds() @@ -135,6 +142,8 @@ define(function () { return m } + self.resetView = resetView + self.gotoNode = function (d) { resetMarkerStyles(nodeDict, linkDict) @@ -142,6 +151,8 @@ define(function () { if (m) m.setStyle({ fillColor: m.options.color, color: "orange", weight: 20, fillOpacity: 1, opacity: 0.7 }) + else + resetView() } self.gotoLink = function (d) { @@ -151,6 +162,8 @@ define(function () { if (m) m.setStyle({ weight: 7, opacity: 1, dashArray: "10, 10" }) + else + resetView() } return self