Fix zooming to validated features. Fixes #748

This commit is contained in:
Tom MacWright
2013-02-13 17:21:21 -05:00
parent fd423f4db7
commit 8538339b44
3 changed files with 20 additions and 16 deletions
+1 -1
View File
@@ -180,7 +180,7 @@ iD.modes.Select = function(context, selection, initial) {
if (showMenu) context.surface().call(radialMenu);
context.surface()
.on('dblclick.select', dblclick)
.on('dblclick.select', dblclick);
}, 200);
};
+16 -12
View File
@@ -308,21 +308,25 @@ iD.Map = function(context) {
return new iD.geo.Extent(projection.invert([0, dimensions[1]]),
projection.invert([dimensions[0], 0]));
} else {
var extent = iD.geo.Extent(_),
tl = projection([extent[0][0], extent[1][1]]),
br = projection([extent[1][0], extent[0][1]]);
// Calculate maximum zoom that fits extent
var hFactor = (br[0] - tl[0]) / dimensions[0],
vFactor = (br[1] - tl[1]) / dimensions[1],
hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2,
vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2,
newZoom = map.zoom() - Math.max(hZoomDiff, vZoomDiff);
map.centerZoom(extent.center(), newZoom);
map.centerZoom(extent.center(), map.extentZoom(extent));
}
};
map.extentZoom = function(_) {
var extent = iD.geo.Extent(_),
tl = projection([extent[0][0], extent[1][1]]),
br = projection([extent[1][0], extent[0][1]]);
// Calculate maximum zoom that fits extent
var hFactor = (br[0] - tl[0]) / dimensions[0],
vFactor = (br[1] - tl[1]) / dimensions[1],
hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2,
vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2,
newZoom = map.zoom() - Math.max(hZoomDiff, vZoomDiff);
return newZoom;
};
map.flush = function() {
context.connection().flush();
context.history().reset();
+3 -3
View File
@@ -11,7 +11,7 @@ iD.ui.Save = function(context) {
if (!history.hasChanges()) return;
connection.authenticate(function(err) {
var modal = iD.ui.modal(context.container());
modal = iD.ui.modal(context.container());
var changes = history.changes();
changes.connection = connection;
modal.select('.content')
@@ -67,8 +67,8 @@ iD.ui.Save = function(context) {
}
function clickFix(d) {
map.extent(d.entity.extent(context.graph()));
if (map.zoom() > 19) map.zoom(19);
var extent = d.entity.extent(context.graph());
map.centerZoom(extent.center(), Math.min(19, map.extentZoom(extent)));
context.enter(iD.modes.Select(context, [d.entity.id]));
modal.remove();
}