Update url hash as user adjusts imagery offset

This commit is contained in:
Bryan Housel
2016-05-03 10:59:33 -04:00
parent 90fd1e3f8d
commit 12dabca249

View File

@@ -41,6 +41,10 @@ iD.Background = function(context) {
background.updateImagery = function() {
var b = background.baseLayerSource(),
o = overlayLayers.map(function (d) { return d.source().id; }).join(','),
meters = iD.geo.offsetToMeters(b.offset()),
epsilon = 0.01,
x = +meters[0].toFixed(2),
y = +meters[1].toFixed(2),
q = iD.util.stringQs(location.hash.substring(1));
var id = b.id;
@@ -60,6 +64,12 @@ iD.Background = function(context) {
delete q.overlays;
}
if (Math.abs(x) > epsilon || Math.abs(y) > epsilon) {
q.offset = x + ',' + y;
} else {
delete q.offset;
}
location.replace('#' + iD.util.qsString(q, true));
var imageryUsed = [b.imageryUsed()];
@@ -95,11 +105,9 @@ iD.Background = function(context) {
background.baseLayerSource = function(d) {
if (!arguments.length) return baseLayer.source();
baseLayer.source(d);
dispatch.change();
background.updateImagery();
return background;
};
@@ -143,6 +151,7 @@ iD.Background = function(context) {
background.nudge = function(d, zoom) {
baseLayer.source().nudge(d, zoom);
dispatch.change();
background.updateImagery();
return background;
};
@@ -150,6 +159,7 @@ iD.Background = function(context) {
if (!arguments.length) return baseLayer.source().offset();
baseLayer.source().offset(d);
dispatch.change();
background.updateImagery();
return background;
};