From 843926009de92595a0ac996927fd47aea3c549b6 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 7 Feb 2013 16:32:03 -0500 Subject: [PATCH] Normalize coordinates so that lasso can be dragged in any direction --- js/id/behavior/lasso.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/js/id/behavior/lasso.js b/js/id/behavior/lasso.js index 08dda8cd3..3986b5cf2 100644 --- a/js/id/behavior/lasso.js +++ b/js/id/behavior/lasso.js @@ -28,25 +28,32 @@ iD.behavior.Lasso = function(context) { lasso.b(d3.mouse(context.surface().node())); } + function normalize(a, b) { + return [ + [Math.min(a[0], b[0]), Math.min(a[1], b[1])], + [Math.max(a[0], b[0]), Math.max(a[1], b[1])]]; + } + function mouseup() { var extent = iD.geo.Extent( - context.projection.invert(lasso.a()), - context.projection.invert(lasso.b())); + normalize(context.projection.invert(lasso.a()), + context.projection.invert(lasso.b()))); lasso.close(); var selected = context.graph().intersects(extent); + selection + .on('mousemove.lasso', null) + .on('mouseup.lasso', null); + if (selected.length) { context.enter(iD.modes.Select(context, _.pluck(selected, 'id'))); } - - selection - .on('mousemove.lasso', null); } selection - .on('mousedown.select', mousedown); + .on('mousedown.lasso', mousedown); }; behavior.off = function(selection) {