Skip to content

Commit

Permalink
Merge pull request #6161 from jguthrie100/fix_closed_way_disconnect
Browse files Browse the repository at this point in the history
Leave way as closed when disconnecting
  • Loading branch information
quincylvania authored Apr 8, 2019
2 parents 8d31367 + 00c7ead commit 50a0982
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions modules/actions/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export function actionDisconnect(nodeId, newNodeId) {
} else {
way.nodes.forEach(function(waynode, index) {
if (waynode === nodeId) {
if (way.isClosed() && parentWays.length > 1 && wayIds && wayIds.indexOf(way.id) !== -1 && index === way.nodes.length-1) {
return;
}
candidates.push({ wayID: way.id, index: index });
}
});
Expand Down
13 changes: 10 additions & 3 deletions modules/operations/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import { behaviorOperation } from '../behavior/index';


export function operationDisconnect(selectedIDs, context) {
var vertices = selectedIDs.filter(function(id) {
return context.geometry(id) === 'vertex';
var vertices = [],
ways = [];

selectedIDs.forEach(function(id) {
if (context.geometry(id) === 'vertex') {
vertices.push(id);
} else {
ways.push(id);
}
});

var entityID = vertices[0];
Expand All @@ -23,7 +30,7 @@ export function operationDisconnect(selectedIDs, context) {


operation.available = function() {
return vertices.length === 1;
return vertices.length === 1 && ways.every(function(way) { return context.graph().entity(way).nodes.includes(vertices[0]); });
};


Expand Down
29 changes: 29 additions & 0 deletions test/spec/actions/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,35 @@ describe('iD.actionDisconnect', function () {
expect(graph.entity('|').nodes).to.eql(['d', 'b']);
});

it('preserves the closed way when part of a larger disconnect operation', function () {
// Situation:
// a ---- bb === c
// = ==
// = ==
// d
// Disconnect - at b (whilst == is selected).
//
// Expected result:
// a ---- b ee === c
// = ==
// = ==
// d
//
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: '-', nodes: ['a', 'b']}),
iD.osmWay({id: '=', nodes: ['b', 'c', 'd', 'b']})
]);

graph = iD.actionDisconnect('b', 'e').limitWays(['='])(graph);

expect(graph.entity('-').nodes).to.eql(['a', 'b']);
expect(graph.entity('=').nodes).to.eql(['e', 'c', 'd', 'e']);
});

it('replaces later occurrences in a self-intersecting way', function() {
// Situtation:
// a --- b
Expand Down

0 comments on commit 50a0982

Please sign in to comment.