diff --git a/js/id/modes/select.js b/js/id/modes/select.js index 1de8ab0f7..505aff07a 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -47,6 +47,11 @@ iD.modes.Select = function (entity) { behavior(surface); }); + var q = iD.util.stringQs(location.hash.substring(1)); + location.hash = '#' + iD.util.qsString(_.assign(q, { + id: entity.id + }), true); + d3.select('.inspector-wrap') .style('display', 'block') .style('opacity', 1) @@ -149,6 +154,9 @@ iD.modes.Select = function (entity) { behavior.off(surface); }); + var q = iD.util.stringQs(location.hash.substring(1)); + location.hash = '#' + iD.util.qsString(_.omit(q, 'id'), true); + surface.on("click.select", null); mode.map.keybinding().on('⌫.select', null); mode.history.on('change.entity-undone', null); diff --git a/js/id/renderer/hash.js b/js/id/renderer/hash.js index bb454811b..652e64f20 100644 --- a/js/id/renderer/hash.js +++ b/js/id/renderer/hash.js @@ -1,6 +1,6 @@ iD.Hash = function() { var hash = { hadHash: false }, - s0, // cached location.hash + s0 = null, // cached location.hash lat = 90 - 1e-8, // allowable latitude range map; @@ -20,9 +20,12 @@ iD.Hash = function() { var center = map.center(), zoom = map.zoom(), precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); - return '#?map=' + zoom.toFixed(2) + - '/' + center[1].toFixed(precision) + - '/' + center[0].toFixed(precision); + var q = iD.util.stringQs(location.hash.substring(1)); + return '#' + iD.util.qsString(_.assign(q, { + map: zoom.toFixed(2) + + '/' + center[1].toFixed(precision) + + '/' + center[0].toFixed(precision) + }), true); }; var move = _.throttle(function() { @@ -32,7 +35,7 @@ iD.Hash = function() { function hashchange() { if (location.hash === s0) return; // ignore spurious hashchange events - if (parser(map, (s0 = location.hash).substring(2))) { + if (parser(map, (s0 = location.hash).substring(1))) { move(); // replace bogus hash } } diff --git a/js/id/util.js b/js/id/util.js index 79b65c524..b3ae537ec 100644 --- a/js/id/util.js +++ b/js/id/util.js @@ -30,9 +30,10 @@ iD.util.stringQs = function(str) { }, {}); }; -iD.util.qsString = function(obj) { +iD.util.qsString = function(obj, noencode) { return Object.keys(obj).sort().map(function(key) { - return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]); + return encodeURIComponent(key) + '=' + ( + noencode ? obj[key] : encodeURIComponent(obj[key])); }).join('&'); };