mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Now that updateNode preserves circularity, provide close/unclose functions
This lets us break closed ways at their connecting node in the few situations where we actually want that behavior (disconnect action for circular non-area ways)
This commit is contained in:
@@ -31,6 +31,9 @@ export function actionDisconnect(nodeId, newNodeId) {
|
||||
if (connection.index === 0 && way.isArea()) {
|
||||
// replace shared node with shared node..
|
||||
graph = graph.replace(way.replaceNode(way.nodes[0], newNode.id));
|
||||
} else if (way.isClosed() && connection.index === way.nodes.length - 1) {
|
||||
// replace closing node with new new node..
|
||||
graph = graph.replace(way.unclose().addNode(newNode.id));
|
||||
} else {
|
||||
// replace shared node with multiple new nodes..
|
||||
graph = graph.replace(way.updateNode(newNode.id, connection.index));
|
||||
@@ -52,11 +55,11 @@ export function actionDisconnect(nodeId, newNodeId) {
|
||||
return;
|
||||
}
|
||||
if (way.isArea() && (way.nodes[0] === nodeId)) {
|
||||
candidates.push({wayID: way.id, index: 0});
|
||||
candidates.push({ wayID: way.id, index: 0 });
|
||||
} else {
|
||||
way.nodes.forEach(function(waynode, index) {
|
||||
if (waynode === nodeId) {
|
||||
candidates.push({wayID: way.id, index: index});
|
||||
candidates.push({ wayID: way.id, index: index });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -188,6 +188,36 @@ _.extend(osmWay.prototype, {
|
||||
},
|
||||
|
||||
|
||||
// If this way is not closed, append the beginning node to the end of the nodelist to close it.
|
||||
close: function() {
|
||||
if (this.isClosed() || !this.nodes.length) return this;
|
||||
|
||||
var nodes = this.nodes.slice();
|
||||
nodes.push(nodes[0]);
|
||||
nodes = nodes.filter(noRepeatNodes);
|
||||
return this.update({ nodes: nodes });
|
||||
},
|
||||
|
||||
|
||||
// If this way is closed, remove any connector nodes from the end of the nodelist to unclose it.
|
||||
unclose: function() {
|
||||
if (!this.isClosed()) return this;
|
||||
|
||||
var nodes = this.nodes.slice(),
|
||||
connector = this.first(),
|
||||
i = nodes.length - 1;
|
||||
|
||||
// remove trailing connectors..
|
||||
while (i > 0 && nodes.length > 1 && nodes[i] === connector) {
|
||||
nodes.splice(i, 1);
|
||||
i = nodes.length - 1;
|
||||
}
|
||||
|
||||
nodes = nodes.filter(noRepeatNodes);
|
||||
return this.update({ nodes: nodes });
|
||||
},
|
||||
|
||||
|
||||
// Adds a node (id) in front of the node which is currently at position index.
|
||||
// If index is undefined, the node will be added to the end of the way for linear ways,
|
||||
// or just before the final connecting node for circular ways.
|
||||
@@ -207,7 +237,7 @@ _.extend(osmWay.prototype, {
|
||||
}
|
||||
|
||||
// If this is a closed way, remove all connector nodes except the first one
|
||||
// (there may be duplicates)
|
||||
// (there may be duplicates) and adjust index if necessary..
|
||||
if (isClosed) {
|
||||
var connector = this.first();
|
||||
|
||||
@@ -252,7 +282,7 @@ _.extend(osmWay.prototype, {
|
||||
}
|
||||
|
||||
// If this is a closed way, remove all connector nodes except the first one
|
||||
// (there may be duplicates)
|
||||
// (there may be duplicates) and adjust index if necessary..
|
||||
if (isClosed) {
|
||||
var connector = this.first();
|
||||
|
||||
@@ -316,7 +346,7 @@ _.extend(osmWay.prototype, {
|
||||
isClosed = this.isClosed();
|
||||
|
||||
nodes = nodes
|
||||
.filter(function(node, i, arr) { return node !== id })
|
||||
.filter(function(node) { return node !== id; })
|
||||
.filter(noRepeatNodes);
|
||||
|
||||
// If the way was closed before, append a connector node to keep it closed..
|
||||
|
||||
Reference in New Issue
Block a user