mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 16:19:48 +02:00
Tree intersect now works with changes
This commit is contained in:
+26
-17
@@ -25,6 +25,18 @@ iD.Difference = function (base, head) {
|
||||
}
|
||||
});
|
||||
|
||||
function addParents(parents, result) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
var parent = parents[i];
|
||||
|
||||
if (parent.id in result)
|
||||
continue;
|
||||
|
||||
result[parent.id] = parent;
|
||||
addParents(head.parentRelations(parent), result);
|
||||
}
|
||||
}
|
||||
|
||||
var difference = {};
|
||||
|
||||
difference.length = function () {
|
||||
@@ -67,21 +79,18 @@ iD.Difference = function (base, head) {
|
||||
return result;
|
||||
};
|
||||
|
||||
difference.addParents = function(entities) {
|
||||
|
||||
for (var i in entities) {
|
||||
addParents(head.parentWays(entities[i]), entities);
|
||||
addParents(head.parentRelations(entities[i]), entities);
|
||||
}
|
||||
return entities;
|
||||
},
|
||||
|
||||
difference.complete = function(extent) {
|
||||
var result = {}, id, change;
|
||||
|
||||
function addParents(parents) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
var parent = parents[i];
|
||||
|
||||
if (parent.id in result)
|
||||
continue;
|
||||
|
||||
result[parent.id] = parent;
|
||||
addParents(head.parentRelations(parent));
|
||||
}
|
||||
}
|
||||
|
||||
for (id in changes) {
|
||||
change = changes[id];
|
||||
|
||||
@@ -97,21 +106,21 @@ iD.Difference = function (base, head) {
|
||||
if (entity.type === 'way') {
|
||||
var nh = h ? h.nodes : [],
|
||||
nb = b ? b.nodes : [],
|
||||
diff;
|
||||
diff, i;
|
||||
|
||||
diff = _.difference(nh, nb);
|
||||
for (var i = 0; i < diff.length; i++) {
|
||||
for (i = 0; i < diff.length; i++) {
|
||||
result[diff[i]] = head.entity(diff[i]);
|
||||
}
|
||||
|
||||
diff = _.difference(nb, nh);
|
||||
for (var i = 0; i < diff.length; i++) {
|
||||
for (i = 0; i < diff.length; i++) {
|
||||
result[diff[i]] = head.entity(diff[i]);
|
||||
}
|
||||
}
|
||||
addParents(head.parentWays(entity), result);
|
||||
addParents(head.parentRelations(entity), result);
|
||||
|
||||
addParents(head.parentWays(entity));
|
||||
addParents(head.parentRelations(entity));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
+28
-9
@@ -40,14 +40,10 @@ iD.History = function(context) {
|
||||
|
||||
function rebaseTree(entities) {
|
||||
for (var i = 0; i < entities.length; i++) {
|
||||
insert(treeGraph.entities[entities[i]]);
|
||||
insert(stack[index].graph.entities[entities[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
function getRectangle(entity) {
|
||||
return extentRectangle(entity.extent(treeGraph));
|
||||
}
|
||||
|
||||
function extentRectangle(extent) {
|
||||
var m = 1000 * 1000 * 100,
|
||||
x = m * extent[0][0],
|
||||
@@ -58,11 +54,16 @@ iD.History = function(context) {
|
||||
}
|
||||
|
||||
function insert(entity) {
|
||||
rtree.insert(getRectangle(entity), entity.id);
|
||||
rtree.insert(extentRectangle(entity.extent(stack[index].graph)), entity.id);
|
||||
}
|
||||
|
||||
function remove(entity) {
|
||||
rtree.remove(getRectangle(entity), entity.id);
|
||||
var r= rtree.remove(extentRectangle(entity.extent(treeGraph)), entity.id);
|
||||
}
|
||||
|
||||
function reinsert(entity) {
|
||||
remove(treeGraph.entities[entity.id]);
|
||||
insert(entity);
|
||||
}
|
||||
|
||||
var history = {
|
||||
@@ -161,8 +162,26 @@ iD.History = function(context) {
|
||||
},
|
||||
|
||||
intersects: function(extent) {
|
||||
if (treeGraph !== stack[index].graph) {
|
||||
var diff = iD.Difference(treeGraph, stack[index].graph),
|
||||
modified = {};
|
||||
|
||||
diff.modified().forEach(function(d) {
|
||||
var loc = treeGraph.entities[d.id].loc;
|
||||
if (!loc || loc[0] !== d.loc[0] || loc[1] !== d.loc[1]) {
|
||||
modified[d.id] = d;
|
||||
}
|
||||
});
|
||||
|
||||
d3.values(diff.addParents(modified)).map(reinsert);
|
||||
diff.created().forEach(insert);
|
||||
diff.deleted().forEach(remove);
|
||||
|
||||
treeGraph = stack[index].graph;
|
||||
}
|
||||
|
||||
return rtree.search(extentRectangle(extent))
|
||||
.map(function(id) { return treeGraph.entity(id) });
|
||||
.map(function(id) { return treeGraph.entity(id); });
|
||||
},
|
||||
|
||||
difference: function() {
|
||||
@@ -185,7 +204,7 @@ iD.History = function(context) {
|
||||
}
|
||||
|
||||
return {
|
||||
modified: difference.modified().map(discardTags),
|
||||
modified: d3.values(difference.modified()).map(discardTags),
|
||||
created: difference.created().map(discardTags),
|
||||
deleted: difference.deleted()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user