From f8a68c879fecdaf246b8f27ef901601eb33207c7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 9 May 2015 14:38:41 -0700 Subject: [PATCH] Adjust tree for force-rebased entities Previously, entities that already existed in the rtree prior to the rebase option would end up duplicated in the tree afterward. Fixes #2637 --- js/id/core/tree.js | 10 +++++++++- test/spec/core/tree.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/js/id/core/tree.js b/js/id/core/tree.js index 538e9894e..6bc40c33d 100644 --- a/js/id/core/tree.js +++ b/js/id/core/tree.js @@ -45,9 +45,17 @@ iD.Tree = function(head) { for (var i = 0; i < entities.length; i++) { var entity = entities[i]; - if (!entity.visible || (!force && (head.entities.hasOwnProperty(entity.id) || rectangles[entity.id]))) + if (!entity.visible) continue; + if (head.entities.hasOwnProperty(entity.id) || rectangles[entity.id]) { + if (!force) { + continue; + } else if (rectangles[entity.id]) { + rtree.remove(rectangles[entity.id]); + } + } + insertions[entity.id] = entity; updateParents(entity, insertions, {}); } diff --git a/test/spec/core/tree.js b/test/spec/core/tree.js index e7b66abfc..0fc227acc 100644 --- a/test/spec/core/tree.js +++ b/test/spec/core/tree.js @@ -56,6 +56,21 @@ describe("iD.Tree", function() { expect(tree.intersects(iD.geo.Extent([0, 0], [2, 2]), graph)).to.eql([relation]); }); + + it("adjusts entities that are force-rebased", function() { + var graph = iD.Graph(), + tree = iD.Tree(graph), + node = iD.Node({id: 'n', loc: [1, 1]}); + + graph.rebase([node], [graph]); + tree.rebase([node]); + + node = node.move([-1, -1]); + graph.rebase([node], [graph], true); + tree.rebase([node], true); + + expect(tree.intersects(iD.geo.Extent([0, 0], [2, 2]), graph)).to.eql([]); + }); }); describe("#intersects", function() {