From 2ca4387f741164d2b205d87b0751aef65579c210 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 6 Feb 2013 17:42:51 -0500 Subject: [PATCH] Fix snapping nodes to areas In the future it may be good to use shadow paths, but at this point there isn't really a reason to add thousands of additional paths. --- js/id/behavior/drag_node.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/js/id/behavior/drag_node.js b/js/id/behavior/drag_node.js index acba7919d..e3028953d 100644 --- a/js/id/behavior/drag_node.js +++ b/js/id/behavior/drag_node.js @@ -84,7 +84,11 @@ iD.behavior.DragNode = function(context) { if (d.type === 'node' && d.id !== entity.id) { loc = d.loc; } else if (d.type === 'way') { - loc = iD.geo.chooseIndex(d, d3.mouse(context.surface().node()), context).loc; + var point = d3.mouse(context.surface().node()), + index = iD.geo.chooseIndex(d, point, context); + if (iD.geo.dist(point, context.projection(index.loc)) < 10) { + loc = index.loc; + } } context.replace(iD.actions.MoveNode(entity.id, loc)); @@ -100,13 +104,18 @@ iD.behavior.DragNode = function(context) { var d = datum(); if (d.type === 'way') { - var choice = iD.geo.chooseIndex(d, d3.mouse(context.surface().node()), context); - context.replace( - iD.actions.MoveNode(entity.id, choice.loc), - iD.actions.AddVertex(d.id, entity.id, choice.index), - connectAnnotation(d)); + var point = d3.mouse(context.surface().node()), + choice = iD.geo.chooseIndex(d, point, context); + if (iD.geo.dist(point, context.projection(choice.loc)) < 10) { + context.replace( + iD.actions.MoveNode(entity.id, choice.loc), + iD.actions.AddVertex(d.id, entity.id, choice.index), + connectAnnotation(d)); + return; + } + } - } else if (d.type === 'node' && d.id !== entity.id) { + if (d.type === 'node' && d.id !== entity.id) { context.replace( iD.actions.Connect([entity.id, d.id]), connectAnnotation(d));