From b643bf105ea8f23baabd40438e60e253803a1ad7 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 15 Mar 2016 15:45:19 -0400 Subject: [PATCH] Start lasso on left button only, refactor `lassoed()` --- js/id/behavior/lasso.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/js/id/behavior/lasso.js b/js/id/behavior/lasso.js index b9f115667..3db221a5e 100644 --- a/js/id/behavior/lasso.js +++ b/js/id/behavior/lasso.js @@ -4,7 +4,8 @@ iD.behavior.Lasso = function(context) { var lasso; function mousedown() { - if (d3.event.shiftKey === true) { + var button = 0; // left + if (d3.event.button === button && d3.event.shiftKey === true) { lasso = null; selection @@ -30,6 +31,20 @@ iD.behavior.Lasso = function(context) { [Math.max(a[0], b[0]), Math.max(a[1], b[1])]]; } + function lassoed() { + if (!lasso) return []; + + var graph = context.graph(), + bounds = lasso.extent().map(context.projection.invert), + extent = iD.geo.Extent(normalize(bounds[0], bounds[1])); + + return _.pluck(context.intersects(extent).filter(function(entity) { + return entity.type === 'node' && + iD.geo.pointInPolygon(context.projection(entity.loc), lasso.coordinates) && + !context.features().isHidden(entity, graph, entity.geometry(graph)); + }), 'id'); + } + function mouseup() { selection .on('mousemove.lasso', null) @@ -37,20 +52,11 @@ iD.behavior.Lasso = function(context) { if (!lasso) return; - var graph = context.graph(), - bounds = lasso.extent().map(context.projection.invert), - extent = iD.geo.Extent(normalize(bounds[0], bounds[1])); - + var ids = lassoed(); lasso.close(); - var selected = context.intersects(extent).filter(function(entity) { - return entity.type === 'node' && - iD.geo.pointInPolygon(context.projection(entity.loc), lasso.coordinates) && - !context.features().isHidden(entity, graph, entity.geometry(graph)); - }); - - if (selected.length) { - context.enter(iD.modes.Select(context, _.pluck(selected, 'id'))); + if (ids.length) { + context.enter(iD.modes.Select(context, ids)); } }