Avoid delete/reinsert on the coreTree when not needed

(re: #6140)
This commit is contained in:
Bryan Housel
2019-04-04 10:02:15 -04:00
parent 68ed6da159
commit d5e427289f
+10 -1
View File
@@ -66,27 +66,36 @@ export function coreTree(head) {
tree.intersects = function(extent, graph) { tree.intersects = function(extent, graph) {
if (graph !== head) { if (graph !== head) {
var diff = coreDifference(head, graph); var diff = coreDifference(head, graph);
var insertions = {}; var changed = diff.didChange;
if (changed.addition || changed.deletion || changed.geometry) {
var insertions = {};
head = graph; head = graph;
if (changed.deletion) {
diff.deleted().forEach(function(entity) { diff.deleted().forEach(function(entity) {
rtree.remove(bboxes[entity.id]); rtree.remove(bboxes[entity.id]);
delete bboxes[entity.id]; delete bboxes[entity.id];
}); });
}
if (changed.geometry) {
diff.modified().forEach(function(entity) { diff.modified().forEach(function(entity) {
rtree.remove(bboxes[entity.id]); rtree.remove(bboxes[entity.id]);
insertions[entity.id] = entity; insertions[entity.id] = entity;
updateParents(entity, insertions, {}); updateParents(entity, insertions, {});
}); });
}
if (changed.addition) {
diff.created().forEach(function(entity) { diff.created().forEach(function(entity) {
insertions[entity.id] = entity; insertions[entity.id] = entity;
}); });
}
rtree.load(Object.values(insertions).map(entityBBox)); rtree.load(Object.values(insertions).map(entityBBox));
} }
}
return rtree.search(extent.bbox()) return rtree.search(extent.bbox())
.map(function(bbox) { return head.entity(bbox.id); }); .map(function(bbox) { return head.entity(bbox.id); });