From d9b581653032a9d775a1b23c0bb03c8e26449965 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Sat, 9 Feb 2013 17:34:44 -0500 Subject: [PATCH] Store background setting in hash. Fixes #632 --- js/id/id.js | 17 +++++++++++++---- js/id/renderer/background.js | 13 +++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/js/id/id.js b/js/id/id.js index 5e39e6b0e..544c66a12 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -92,10 +92,19 @@ window.iD = function () { return context; }; - context.background() - .source(_.find(iD.layers, function(l) { - return l.data.name === 'Bing aerial imagery'; - })); + var q = iD.util.stringQs(location.hash.substring(1)); + if (q.layer) { + context.background() + .source(_.find(iD.layers, function(l) { + return l.data.sourcetag === q.layer; + })); + } + if (!context.background()) { + context.background() + .source(_.find(iD.layers, function(l) { + return l.data.name === 'Bing aerial imagery'; + })); + } return d3.rebind(context, dispatch, 'on'); }; diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index be4cc1927..8a14dc0f3 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -152,9 +152,22 @@ iD.Background = function() { return background; }; + function setPermalink(source) { + var tag = source.data.sourcetag; + var q = iD.util.stringQs(location.hash.substring(1)); + if (tag) { + location.replace('#' + iD.util.qsString(_.assign(q, { + layer: tag + }), true)); + } else { + location.replace('#' + iD.util.qsString(_.omit(q, 'layer'), true)); + } + } + background.source = function(_) { if (!arguments.length) return source; source = _; + setPermalink(source); return background; };