mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-20 23:44:47 +02:00
add force option for rebase to overwrite existing entities
related: openstreetmap/iD#2467
This commit is contained in:
+3
-4
@@ -112,20 +112,19 @@ iD.Graph.prototype = {
|
||||
// is used only during the history operation that merges newly downloaded
|
||||
// data into each state. To external consumers, it should appear as if the
|
||||
// graph always contained the newly downloaded data.
|
||||
rebase: function(entities, stack) {
|
||||
rebase: function(entities, stack, force) {
|
||||
var base = this.base(),
|
||||
i, j, k, id;
|
||||
|
||||
for (i = 0; i < entities.length; i++) {
|
||||
var entity = entities[i];
|
||||
|
||||
if (base.entities[entity.id])
|
||||
if (!force && base.entities[entity.id])
|
||||
continue;
|
||||
|
||||
// Merging data into the base graph
|
||||
base.entities[entity.id] = entity;
|
||||
this._updateCalculated(undefined, entity,
|
||||
base.parentWays, base.parentRels);
|
||||
this._updateCalculated(undefined, entity, base.parentWays, base.parentRels);
|
||||
|
||||
// Restore provisionally-deleted nodes that are discovered to have an extant parent
|
||||
if (entity.type === 'way') {
|
||||
|
||||
@@ -42,8 +42,8 @@ iD.History = function(context) {
|
||||
},
|
||||
|
||||
merge: function(entities, extent) {
|
||||
stack[0].graph.rebase(entities, _.pluck(stack, 'graph'));
|
||||
tree.rebase(entities);
|
||||
stack[0].graph.rebase(entities, _.pluck(stack, 'graph'), false);
|
||||
tree.rebase(entities, false);
|
||||
|
||||
dispatch.change(undefined, extent);
|
||||
},
|
||||
@@ -237,8 +237,8 @@ iD.History = function(context) {
|
||||
var baseEntities = h.baseEntities.map(function(entity) {
|
||||
return iD.Entity(entity);
|
||||
});
|
||||
stack[0].graph.rebase(baseEntities, _.pluck(stack, 'graph'));
|
||||
tree.rebase(baseEntities);
|
||||
stack[0].graph.rebase(baseEntities, _.pluck(stack, 'graph'), true);
|
||||
tree.rebase(baseEntities, true);
|
||||
}
|
||||
|
||||
stack = h.stack.map(function(d) {
|
||||
|
||||
+2
-2
@@ -39,13 +39,13 @@ iD.Tree = function(head) {
|
||||
|
||||
var tree = {};
|
||||
|
||||
tree.rebase = function(entities) {
|
||||
tree.rebase = function(entities, force) {
|
||||
var insertions = {};
|
||||
|
||||
for (var i = 0; i < entities.length; i++) {
|
||||
var entity = entities[i];
|
||||
|
||||
if (head.entities.hasOwnProperty(entity.id) || rectangles[entity.id])
|
||||
if (!force && (head.entities.hasOwnProperty(entity.id) || rectangles[entity.id]))
|
||||
continue;
|
||||
|
||||
insertions[entity.id] = entity;
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ window.iD = function () {
|
||||
|
||||
connection.on('load.context', function loadContext(err, result) {
|
||||
if (altGraph) {
|
||||
altGraph.rebase(result.data, [altGraph]);
|
||||
altGraph.rebase(result.data, [altGraph], false);
|
||||
} else {
|
||||
history.merge(result.data, result.extent);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,16 @@ describe('iD.Graph', function() {
|
||||
expect(graph.entity('n')).to.equal(a);
|
||||
});
|
||||
|
||||
it("gives precedence to new entities when force = true", function () {
|
||||
var a = iD.Node({id: 'n'}),
|
||||
b = iD.Node({id: 'n'}),
|
||||
graph = iD.Graph([a]);
|
||||
|
||||
graph.rebase([b], [graph], true);
|
||||
|
||||
expect(graph.entity('n')).to.equal(b);
|
||||
});
|
||||
|
||||
it("inherits entities from base prototypally", function () {
|
||||
var graph = iD.Graph();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user