From 0440054cd92e321c21a0ea5ea74a0ec3f29d446d Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Fri, 27 Jan 2017 13:02:27 -0500 Subject: [PATCH] Child and sibling vertices should be eligible for drag_node (closes #3799, see also #3801) --- modules/modes/drag_node.js | 21 ++++++++++++--------- modules/svg/vertices.js | 11 +++++++---- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index e0d9ca771..575df3a05 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -81,17 +81,18 @@ export function modeDragNode(context) { function start(entity) { wasMidpoint = entity.type === 'midpoint'; - var editableIDs = [ entity.id ]; - context.graph().parentWays(entity).forEach(function (parentWay) { - editableIDs.push(parentWay.id); - editableIDs = editableIDs.concat(_.map(context.graph().parentRelations(parentWay), 'id')); - }); + // vertices classed "sibling" include: (see svg/vertices.js) + // - children of selected ways or multipolygons + // - vertices sharing a way with selected vertices + var selection = d3.selectAll('g.' + entity.id), + isSibling = !selection.empty() && selection.classed('sibling'); - isCancelled = d3.event.sourceEvent.shiftKey || - !(wasMidpoint || _.some(editableIDs, function (editableID) { return selectedIDs.indexOf(editableID) !== -1; })) || + isCancelled = d3.event.sourceEvent.shiftKey || !(wasMidpoint || isSibling) || context.features().hasHiddenConnections(entity, context.graph()); - if (isCancelled) return behavior.cancel(); + if (isCancelled) { + return behavior.cancel(); + } if (wasMidpoint) { var midpoint = entity; @@ -105,10 +106,12 @@ export function modeDragNode(context) { context.perform(actionNoop()); } + // activeIDs generate no pointer events. This prevents the node or vertex + // being dragged from trying to connect to itself or its parent element. activeIDs = _.map(context.graph().parentWays(entity), 'id'); activeIDs.push(entity.id); - setActiveElements(); + context.enter(mode); } diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index d3a850768..14897d8bf 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -53,7 +53,7 @@ export function svgVertices(projection, context) { } - function draw(selection, vertices, klass, graph, zoom) { + function draw(selection, vertices, klass, graph, zoom, siblings) { function icon(entity) { if (entity.id in icons) return icons[entity.id]; @@ -105,6 +105,8 @@ export function svgVertices(projection, context) { } + siblings = siblings || {}; + var icons = {}, z = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2); @@ -141,6 +143,7 @@ export function svgVertices(projection, context) { groups .merge(enter) .attr('transform', svgPointTransform(projection)) + .classed('sibling', function(entity) { return entity.id in siblings; }) .classed('shared', function(entity) { return graph.isShared(entity); }) .classed('endpoint', function(entity) { return entity.isEndpoint(graph); }) .call(setAttributes); @@ -148,7 +151,7 @@ export function svgVertices(projection, context) { function drawVertices(selection, graph, entities, filter, extent, zoom) { - var selected = siblingAndChildVertices(context.selectedIDs(), graph, extent), + var siblings = siblingAndChildVertices(context.selectedIDs(), graph, extent), wireframe = context.surface().classed('fill-wireframe'), vertices = []; @@ -164,7 +167,7 @@ export function svgVertices(projection, context) { if (geometry !== 'vertex') continue; - if (entity.id in selected || + if (entity.id in siblings || entity.hasInterestingTags() || entity.isEndpoint(graph) || entity.isConnected(graph)) { @@ -175,7 +178,7 @@ export function svgVertices(projection, context) { var layer = selection.selectAll('.layer-hit'); layer.selectAll('g.vertex.vertex-persistent') .filter(filter) - .call(draw, vertices, 'vertex-persistent', graph, zoom); + .call(draw, vertices, 'vertex-persistent', graph, zoom, siblings); drawHover(selection, graph, extent, zoom); }