diff --git a/js/id/id.js b/js/id/id.js index 571e3a8da..2257c03d2 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -145,7 +145,12 @@ var iD = function(container) { }); var hash = iD.Hash().map(map); - if (!hash.hadHash) map.setZoom(20).center([-77.02405, 38.87952]); + + if (!hash.hadHash) { + map.zoom(20) + .center([-77.02405, 38.87952]); + } + d3.select('.user').call(iD.userpanel(connection) .on('logout', connection.logout) .on('login', connection.authenticate)); diff --git a/js/id/renderer/hash.js b/js/id/renderer/hash.js index 748ae5af0..67138539e 100644 --- a/js/id/renderer/hash.js +++ b/js/id/renderer/hash.js @@ -19,14 +19,14 @@ iD.Hash = function() { if (args.length < 3 || args.some(isNaN)) { return true; // replace bogus hash } else { - map.setZoom(args[0]) + map.zoom(args[0]) .center([args[2], Math.min(lat, Math.max(-lat, args[1]))]); } }; var formatter = function(map) { var center = map.center(), - zoom = map.getZoom(), + zoom = map.zoom(), precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); return '#?map=' + zoom.toFixed(2) + '/' + center[1].toFixed(precision) + diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 337d1b693..08f07291f 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -101,7 +101,7 @@ iD.Map = function(elem, connection) { function drawVector(only) { if (surface.style(transformProp) != 'none') return; - var z = getZoom(), + var z = map.zoom(), all = [], ways = [], areas = [], points = [], waynodes = [], extent = getExtent(), graph = map.history.graph(); @@ -419,7 +419,7 @@ iD.Map = function(elem, connection) { dispatch.move(map); tilegroup.call(background); } - if (getZoom() > 16) { + if (map.zoom() > 16) { download(); drawVector(only); } else { @@ -464,15 +464,15 @@ iD.Map = function(elem, connection) { return [l[0] * scale + translate[0], l[1] * scale + translate[1]]; } - function getZoom(zoom) { - return Math.max(Math.log(projection.scale()) / Math.log(2) - 7, 0); - } - function pxCenter() { return [dimensions[0] / 2, dimensions[0] / 2]; } - function setZoom(z) { + map.zoom = function(z) { + if (!arguments.length) { + return Math.max(Math.log(projection.scale()) / Math.log(2) - 7, 0); + } + // summary: Redraw the map at a new zoom level. var scale = 256 * Math.pow(2, z - 1); var center = pxCenter(); @@ -489,10 +489,11 @@ iD.Map = function(elem, connection) { redraw(); return map; - } + }; + + map.zoomIn = function() { return map.zoom(Math.ceil(map.zoom() + 1)); }; + map.zoomOut = function() { return map.zoom(Math.floor(map.zoom() - 1)); }; - function zoomIn() { return setZoom(Math.ceil(getZoom() + 1)); } - function zoomOut() { return setZoom(Math.floor(getZoom() - 1)); } function center(loc) { if (!arguments.length) { return projection.invert(pxCenter()); @@ -520,10 +521,6 @@ iD.Map = function(elem, connection) { map.background = background; map.center = center; map.centre = center; - map.getZoom = getZoom; - map.setZoom = setZoom; - map.zoomIn = zoomIn; - map.zoomOut = zoomOut; map.projection = projection; map.size = setSize; @@ -541,7 +538,6 @@ iD.Map = function(elem, connection) { setSize(parent.size()); hideInspector(); - redraw(); return d3.rebind(map, dispatch, 'on', 'move', 'update'); }; diff --git a/test/spec/Map.js b/test/spec/Map.js index 0b91b43d2..ffb917bab 100644 --- a/test/spec/Map.js +++ b/test/spec/Map.js @@ -1,5 +1,5 @@ describe('Map', function() { - var node, foo; + var map, foo; beforeEach(function() { foo = document.body.appendChild(document.createElement('div')); @@ -11,10 +11,26 @@ describe('Map', function() { foo.parentNode.removeChild(foo); }); - describe('#getZoom', function() { - it('reports zoom level', function() { - expect(map.setZoom(4)).toEqual(map); - expect(map.getZoom()).toEqual(4); + describe('#zoom', function() { + it('gets and sets zoom level', function() { + expect(map.zoom(4)).toEqual(map); + expect(map.zoom()).toEqual(4); + }); + }); + + describe('#zoomIn', function() { + it('increments zoom', function() { + expect(map.zoom(4)).toEqual(map); + expect(map.zoomIn()).toEqual(map); + expect(map.zoom()).toEqual(5); + }); + }); + + describe('#zoomOut', function() { + it('decrements zoom', function() { + expect(map.zoom(4)).toEqual(map); + expect(map.zoomOut()).toEqual(map); + expect(map.zoom()).toEqual(3); }); }); @@ -36,15 +52,4 @@ describe('Map', function() { expect(map.getExtent()[1][0]).toBeCloseTo(36); }); }); - - describe('#zoomIn', function() { - it('changes reported zoom level', function() { - expect(map.setZoom(4)).toEqual(map); - expect(map.getZoom()).toEqual(4); - expect(map.zoomOut()).toEqual(map); - expect(map.getZoom()).toEqual(3); - expect(map.zoomIn()).toEqual(map); - expect(map.getZoom()).toEqual(4); - }); - }); });