From b18457f60bffaa3da877247867e28159772d63fd Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 14 Jan 2013 15:54:12 -0500 Subject: [PATCH] Fix leaking globals and add test case --- js/id/renderer/map.js | 16 ++++++++-------- test/spec/renderer/map.js | 8 +++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index da1a38fe9..3f64886b6 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -252,17 +252,17 @@ iD.Map = function() { BR = projection(br); // Calculate maximum zoom that fits extent - 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; - zoomDiff = map.zoom() - Math.max(hZoomDiff, vZoomDiff); + 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); // Calculate center of projected extent - midPoint = [(TL[0] + BR[0]) / 2, (TL[1] + BR[1]) / 2]; - midLoc = projection.invert(midPoint); + var midPoint = [(TL[0] + BR[0]) / 2, (TL[1] + BR[1]) / 2], + midLoc = projection.invert(midPoint); - map.zoom(zoomDiff).center(midLoc); + map.zoom(newZoom).center(midLoc); } }; diff --git a/test/spec/renderer/map.js b/test/spec/renderer/map.js index bfd4d90a0..4cec560e9 100644 --- a/test/spec/renderer/map.js +++ b/test/spec/renderer/map.js @@ -53,11 +53,17 @@ describe('Map', function() { }); describe('#extent', function() { - it('reports extent', function() { + it('gets and sets extent', function() { expect(map.size([100, 100])).to.equal(map); expect(map.center([0, 0])).to.equal(map); expect(map.extent()[0][0]).to.be.closeTo(-17.5, 0.5); expect(map.extent()[1][0]).to.be.closeTo(17.5, 0.5); + expect(map.extent([10, 1], [30, 1])); + expect(map.extent()[0][0]).to.be.closeTo(10, 0.1); + expect(map.extent()[1][0]).to.be.closeTo(30, 0.1); + expect(map.extent([-1, -20], [1, -40])); + expect(map.extent()[0][1]).to.be.closeTo(-20, 0.1); + expect(map.extent()[1][1]).to.be.closeTo(-40, 0.1); }); });