Patch up tests, go to simpler map api

This commit is contained in:
Tom MacWright
2012-11-29 15:36:33 -05:00
parent c9e3297f3d
commit 81a9349e82
5 changed files with 32 additions and 33 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ var iD = function(container) {
});
var hash = iD.Hash().map(map);
if (!hash.hadHash) map.setZoom(19).setCenter([-77.0198, 38.8796]);
if (!hash.hadHash) map.setZoom(19).center([-77.0198, 38.8796]);
d3.select('.user').call(iD.userpanel(connection)
.on('logout', connection.logout)
.on('login', connection.authenticate));
+4 -4
View File
@@ -20,14 +20,14 @@ iD.Hash = function() {
return true; // replace bogus hash
} else {
map.setZoom(args[0])
.setCenter([args[2], Math.min(lat, Math.max(-lat, args[1]))]);
.center([args[2], Math.min(lat, Math.max(-lat, args[1]))]);
}
};
var formatter = function(map) {
var center = map.getCenter(),
zoom = map.getZoom(),
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
var center = map.center(),
zoom = map.getZoom(),
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
return '#?map=' + zoom.toFixed(2) +
'/' + center[1].toFixed(precision) +
'/' + center[0].toFixed(precision);
+16 -17
View File
@@ -51,6 +51,7 @@ iD.Map = function(elem, connection) {
.attr('clip-path', 'url(#clip)'),
g = ['fill', 'casing', 'stroke', 'text', 'hit', 'temp'].reduce(function(mem, i) {
return (mem[i] = r.append('g').attr('class', 'layer-g')) && mem;
return mem;
}, {}),
class_stroke = iD.Style.styleClasses('stroke'),
class_fill = iD.Style.styleClasses('stroke'),
@@ -478,18 +479,19 @@ iD.Map = function(elem, connection) {
function zoomIn() { return setZoom(Math.ceil(getZoom() + 1)); }
function zoomOut() { return setZoom(Math.floor(getZoom() - 1)); }
function getCenter() { return projection.invert(pxCenter()); }
function setCenter(loc) {
// summary: Update centre and bbox to a specified lat/lon.
var t = projection.translate(),
center = pxCenter();
ll = projection(loc);
projection.translate([
t[0] - ll[0] + center[0], t[1] - ll[1] + center[1]]);
zoom.translate(projection.translate());
redraw();
return map;
function center(loc) {
if (!arguments.length) {
return projection.invert(pxCenter());
} else {
var t = projection.translate(),
c = pxCenter(),
ll = projection(loc);
projection.translate([
t[0] - ll[0] + c[0], t[1] - ll[1] + c[1]]);
zoom.translate(projection.translate());
redraw();
return map;
}
}
function flush() {
@@ -501,11 +503,8 @@ iD.Map = function(elem, connection) {
map.selectClick = selectClick;
map.setCenter = setCenter;
map.setCentre = setCenter;
map.getCentre = getCenter;
map.getCenter = getCenter;
map.center = center;
map.centre = center;
map.getZoom = getZoom;
map.setZoom = setZoom;
map.zoomIn = zoomIn;
+3 -3
View File
@@ -58,8 +58,8 @@ describe('Graph', function() {
it("filters entities by modified", function () {
var a = {modified: function () { return true; }},
b = {modified: function () { return false; }},
graph = iD.Graph([a, b]);
expect(graph.modifications()).toEqual([a]);
graph = iD.Graph({ 'a': a, 'b': b });
expect(graph.modifications()).toEqual([iD.Entity(graph.entity('a'))]);
});
});
@@ -70,5 +70,5 @@ describe('Graph', function() {
graph = iD.Graph([a, b]);
expect(graph.creations()).toEqual([a]);
});
})
});
});
+8 -8
View File
@@ -20,20 +20,20 @@ describe('Map', function() {
describe('#getCenter', function() {
it('reports center', function() {
expect(map.setCenter([0, 0])).toEqual(map);
expect(map.getCenter()).toEqual([0, 0]);
expect(map.setCenter([10, 15])).toEqual(map);
expect(map.getCenter()[0]).toBeCloseTo(10);
expect(map.getCenter()[1]).toBeCloseTo(15);
expect(map.center([0, 0])).toEqual(map);
expect(map.center()).toEqual([0, 0]);
expect(map.center([10, 15])).toEqual(map);
expect(map.center()[0]).toBeCloseTo(10);
expect(map.center()[1]).toBeCloseTo(15);
});
});
describe('#getExtent', function() {
it('reports extent', function() {
expect(map.setSize([100, 100])).toEqual(map);
expect(map.setCenter([0, 0])).toEqual(map);
expect(map.getExtent()[0][0]).toBeCloseTo(-35.156);
expect(map.getExtent()[1][0]).toBeCloseTo(35.156);
expect(map.center([0, 0])).toEqual(map);
expect(map.getExtent()[0][0]).toBeCloseTo(-36);
expect(map.getExtent()[1][0]).toBeCloseTo(36);
});
});