From 9abe3af312554470a0d79a8f75e3f1587a08cb7d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 17 Jan 2013 14:14:31 -0800 Subject: [PATCH] Fix extent and difference rendering for multi polygons --- js/id/graph/relation.js | 10 ++++++++-- js/id/renderer/map.js | 10 ++++++++-- test/spec/graph/relation.js | 9 ++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/js/id/graph/relation.js b/js/id/graph/relation.js index 4788ad0d1..490b98ac7 100644 --- a/js/id/graph/relation.js +++ b/js/id/graph/relation.js @@ -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() { diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 59f46f0ee..a21a8a2d0 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -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; + } + } } } } diff --git a/test/spec/graph/relation.js b/test/spec/graph/relation.js index 26a1a2022..7395521c0 100644 --- a/test/spec/graph/relation.js +++ b/test/spec/graph/relation.js @@ -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 () {