Fix extent and difference rendering for multi polygons

This commit is contained in:
John Firebaugh
2013-01-17 14:14:31 -08:00
parent 5a2444b551
commit 9abe3af312
3 changed files with 24 additions and 5 deletions
+8 -2
View File
@@ -2,8 +2,14 @@ iD.Relation = iD.Entity.extend({
type: "relation",
members: [],
extent: function() {
return [[NaN, NaN], [NaN, NaN]];
extent: function(resolver) {
return resolver.transient(this, 'extent', function() {
var extent = iD.geo.Extent();
for (var i = 0, l = this.members.length; i < l; i++) {
extent = extent.extend(resolver.entity(this.members[i].id).extent(resolver));
}
return extent;
});
},
geometry: function() {
+8 -2
View File
@@ -69,8 +69,7 @@ iD.Map = function() {
all = graph.intersects(extent);
filter = d3.functor(true);
} else {
var only = {},
filterOnly = {};
var only = {};
for (var j = 0; j < difference.length; j++) {
var id = difference[j],
entity = graph.fetch(id);
@@ -86,6 +85,13 @@ iD.Map = function() {
only[parents[k].id] = graph.fetch(parents[k].id);
}
}
parents = graph.parentRelations(only[id]);
for (k = 0; k < parents.length; k++) {
// Don't re-fetch parents
if (only[parents[k].id] === undefined) {
only[parents[k].id] = parents[k].id;
}
}
}
}
}
+8 -1
View File
@@ -36,7 +36,14 @@ describe('iD.Relation', function () {
});
describe("#extent", function () {
it("returns the minimal extent containing the extents of all members");
it("returns the minimal extent containing the extents of all members", function () {
var a = iD.Node({loc: [0, 0]}),
b = iD.Node({loc: [5, 10]}),
r = iD.Relation({members: [{id: a.id}, {id: b.id}]}),
graph = iD.Graph([a, b, r]);
expect(r.extent(graph)).to.eql([[0, 0], [5, 10]])
});
});
describe("#multipolygon", function () {