Use interpolated D3 zooming for zoomIn/zoomOut

This commit is contained in:
Bryan Housel
2015-03-09 16:34:07 -04:00
parent b4cd1d67d8
commit 2485d74d5b
2 changed files with 37 additions and 10 deletions
+25 -4
View File
@@ -153,11 +153,15 @@ iD.Map = function(context) {
}
function zoomPan() {
if (Math.log(d3.event.scale / Math.LN2 - 8) < minzoom + 1) {
if (Math.log(d3.event.scale) / Math.LN2 - 8 < minzoom) {
surface.interrupt();
iD.ui.flash(context.container())
.select('.content')
.text(t('cannot_zoom'));
return setZoom(context.minEditableZoom(), true);
setZoom(context.minEditableZoom(), true);
queueRedraw();
dispatch.move(map);
return;
}
projection
@@ -253,6 +257,22 @@ iD.Map = function(context) {
return map;
};
function interpolateZoom(_) {
var k = projection.scale(),
t = projection.translate();
surface.node().__chart__ = {
x: t[0],
y: t[1],
k: k * 2 * Math.PI
};
setZoom(_);
projection.scale(k).translate(t); // undo setZoom projection changes
zoom.event(surface.transition());
}
function setZoom(_, force) {
if (_ === map.zoom() && !force)
return false;
@@ -307,8 +327,8 @@ iD.Map = function(context) {
return redraw();
};
map.zoomIn = function() { return map.zoom(~~map.zoom() + 1); };
map.zoomOut = function() { return map.zoom(~~map.zoom() - 1); };
map.zoomIn = function() { interpolateZoom(~~map.zoom() + 1); };
map.zoomOut = function() { interpolateZoom(~~map.zoom() - 1); };
map.center = function(loc) {
if (!arguments.length) {
@@ -328,6 +348,7 @@ iD.Map = function(context) {
}
if (z < minzoom) {
surface.interrupt();
iD.ui.flash(context.container())
.select('.content')
.text(t('cannot_zoom'));
+12 -6
View File
@@ -39,18 +39,24 @@ describe('iD.Map', function() {
});
describe('#zoomIn', function() {
it('increments zoom', function() {
it('increments zoom', function(done) {
expect(map.zoom(4)).to.equal(map);
expect(map.zoomIn()).to.equal(map);
expect(map.zoom()).to.equal(5);
map.zoomIn();
window.setTimeout(function() {
expect(map.zoom()).to.equal(5);
done();
}, 500);
});
});
describe('#zoomOut', function() {
it('decrements zoom', function() {
it('decrements zoom', function(done) {
expect(map.zoom(4)).to.equal(map);
expect(map.zoomOut()).to.equal(map);
expect(map.zoom()).to.equal(3);
map.zoomOut();
window.setTimeout(function() {
expect(map.zoom()).to.equal(3);
done();
}, 500);
});
});