From 476e929eecd7fad0dd026dfc1388effcb40a6676 Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Tue, 29 Sep 2020 15:49:42 -0400 Subject: [PATCH] Support splitting areas at nodes connected to lines if the lines can't be split (close #6047) --- modules/actions/split.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/modules/actions/split.js b/modules/actions/split.js index 46cbafab9..4baea8648 100644 --- a/modules/actions/split.js +++ b/modules/actions/split.js @@ -248,30 +248,36 @@ export function actionSplit(nodeIds, newWayIds) { action.waysForNode = function(nodeId, graph) { var node = graph.entity(nodeId); - var parents = graph.parentWays(node); - var hasLines = parents.some(function(parent) { - return parent.geometry(graph) === 'line'; - }); + var splittableParents = graph.parentWays(node).filter(isSplittable); - return parents.filter(function(parent) { - if (_wayIDs && _wayIDs.indexOf(parent.id) === -1) - return false; + if (!_wayIDs) { + // If the ways to split aren't specified, only split the lines. + // If there are no lines to split, split the areas. - if (!_wayIDs && hasLines && parent.geometry(graph) !== 'line') - return false; - - if (parent.isClosed()) { - return true; + var hasLine = splittableParents.some(function(parent) { + return parent.geometry(graph) === 'line'; + }); + if (hasLine) { + return splittableParents.filter(function(parent) { + return parent.geometry(graph) === 'line'; + }); } + } + return splittableParents; + function isSplittable(parent) { + // If the ways to split are specified, ignore everything else. + if (_wayIDs && _wayIDs.indexOf(parent.id) === -1) return false; + + // We can fake splitting closed ways at their endpoints... + if (parent.isClosed()) return true; + + // otherwise, we can't split nodes at their endpoints. for (var i = 1; i < parent.nodes.length - 1; i++) { - if (parent.nodes[i] === nodeId) { - return true; - } + if (parent.nodes[i] === nodeId) return true; } - return false; - }); + } }; action.ways = function(graph) {