From bbdd4a7bcbc389bb4300e03029ddb6d1bf22eda7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 1 Dec 2012 14:36:14 -0800 Subject: [PATCH] d3 style map.extent() --- js/id/renderer/map.js | 18 +++++++----------- test/spec/Map.js | 10 +++++----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 08f07291f..3f806077f 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -103,7 +103,7 @@ iD.Map = function(elem, connection) { if (surface.style(transformProp) != 'none') return; var z = map.zoom(), all = [], ways = [], areas = [], points = [], waynodes = [], - extent = getExtent(), + extent = map.extent(), graph = map.history.graph(); if (!only) { @@ -448,10 +448,6 @@ iD.Map = function(elem, connection) { return map; } - function getExtent() { - return [projection.invert([0, 0]), projection.invert(dimensions)]; - } - function pointLocation(p) { var translate = projection.translate(), scale = projection.scale(); @@ -494,7 +490,7 @@ iD.Map = function(elem, connection) { map.zoomIn = function() { return map.zoom(Math.ceil(map.zoom() + 1)); }; map.zoomOut = function() { return map.zoom(Math.floor(map.zoom() - 1)); }; - function center(loc) { + map.center = function(loc) { if (!arguments.length) { return projection.invert(pxCenter()); } else { @@ -507,21 +503,21 @@ iD.Map = function(elem, connection) { redraw(); return map; } - } + }; + + map.extent = function() { + return [projection.invert([0, 0]), projection.invert(dimensions)]; + }; function flush() { apiTilesLoaded = {}; } map.download = download; - map.getExtent = getExtent; map.selectEntity = selectEntity; map.background = background; - map.center = center; - map.centre = center; - map.projection = projection; map.size = setSize; diff --git a/test/spec/Map.js b/test/spec/Map.js index ffb917bab..476bcb011 100644 --- a/test/spec/Map.js +++ b/test/spec/Map.js @@ -34,8 +34,8 @@ describe('Map', function() { }); }); - describe('#getCenter', function() { - it('reports center', function() { + describe('#center', function() { + it('gets and sets center', function() { expect(map.center([0, 0])).toEqual(map); expect(map.center()).toEqual([0, 0]); expect(map.center([10, 15])).toEqual(map); @@ -44,12 +44,12 @@ describe('Map', function() { }); }); - describe('#getExtent', function() { + describe('#extent', function() { it('reports extent', function() { expect(map.size([100, 100])).toEqual(map); expect(map.center([0, 0])).toEqual(map); - expect(map.getExtent()[0][0]).toBeCloseTo(-36); - expect(map.getExtent()[1][0]).toBeCloseTo(36); + expect(map.extent()[0][0]).toBeCloseTo(-36); + expect(map.extent()[1][0]).toBeCloseTo(36); }); }); });