Non-overwriting hash, add hash in select mode. Needs code for dealing

with hash.
This commit is contained in:
Tom MacWright
2013-01-22 09:41:29 -05:00
parent b3765a4467
commit 7cf234365e
3 changed files with 19 additions and 7 deletions
+8
View File
@@ -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);
+8 -5
View File
@@ -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
}
}
+3 -2
View File
@@ -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('&');
};